RaspberryPi Door Opener

Hello everyone :slight_smile:

Im totaly new to FreePBX and since im trying to solve my problem i have allready read a few post about that but non of them really helped me out and that is why I decided to write a new post. Please if this has been answered somewhere else already, feel free to delete the post an please link me to the solution.

So my goal is to open my doors with two RaspberryPi’s, where one acts as a internal unit where the FreePBX is installed (acts as Host and Client at the same time) and the other one as outdoor unit where Linphone client is installed and registered to the internal Host. The whole Process of registration and calling is finished, meaning Im able to press the button on the outside unit and make a call to the indoor unit.

My problem begins here.
What would be the best solution to open the door. I have a Python Script on the outdoor unit that opens the door so I was thinking to use the System() application function with ssh command on the indoor unit during the call with the DTMF option. But I have no idea where to start how to configure that. There are also Feature Codes and Dynamic Features but I have no clue how does all these work.

Can anyone help please? Your help would be appreciated.

Thanks in Advance.

The best way would be to open the door after entering a sequence of numbers. I guess the most complex part would be done on the door phone side. From the point of view of the Asterisk side, you are just sending digits during the call. On the door phone you would need to be waiting for digits and when the right sequence is entered, the opener should be triggered.

In fact there is an example on the FreePBX wiki. Have you taken a look there?


1 Like

I personally would use mqtt to signal the open door event.

1 Like

There are very tried and true solutions designed for this purpose. Why are you trying to build your own solution? What are you going to do to let people in when something isn’t working?

1 Like

IoT…very interesting. I newer tough about it…but certainly Ill give it a try, perhaps a hint on how do I make Asterisk publish to topic? And then again wouldn’t it be easier and faster if I could just make custom dial plan and use the system() function to send a ssh command to the other RPi? I just don’t know how to accomplish that…


depending on your abilities, easiest would be to install mosquitto (for your broker) and mosquitto-clients on the Pi’s, use

TrySystem(. . .) from the dial plan

using ‘mosquitto_pub’ on the inside device and have ‘mosquitto_sub’ hitting the relay on the outside. pi, you an.

An older technology that still works, if it all fails,

Listen for a knock on the door (it is interrupt driven and it can be password protected), go answer it if you want to :wink:

1 Like

How do I accomplish the TrySystem(…) thing? I mean how does it work? can I start it with DTMF or do i need an extension for it or macro or anything, do I use some custom feature code and when how do I do all that? the point is I want to make it happen during the call, so if I talk to someone and afterwards want to open the door I want to press a number on a keypad and start an action of door opener, I mean I could eventually forward a phone call to an extension that’s has that TrySystem(ssh command) option build in but then again no clue where to start in this direction…

I would add an in-call feature and mapping



command to try thhe system with

`TrySystem(/usr/bin/mosquitto_pub -h -t "doorlock "-m “opensesame”)

mapping gpio to mqtt with

and add a

You could of course use ssh instead but that is a very round-about way of going from a human pressing a dtmf button to powering a door latch somewhere else on the internet (use ssl if you go that route, mqtt is really quite secure if done properly) , . Use an open access mqtt broker and you can let the cleaning lady in while your at the pub. And it cost you 2x$5 for the pi zeros and another 5 for the relay, add in a few hours of R&D and you “learned to fish a bit”.

Then learn how to do it with thge AGI library straight to mqtt and there is no messing with the dialplan
or ssh or bash or routing or . . . needed as you can intercept the DTMF in there as needed.

1 Like

I have tryed the mqtt part without a problem, it works fine. But Im stuck at the Dynamic_Features, I have done the following:

in globals_custom.conf added following:

in features_applicationmap_custom.conf added following:

in features_featuremap_custom.conf added following:

and in the extensions_custom.conf
exten => s,1,TrySystem(/usr/bin/mosquitto_pub -h test.mosquitto.org -t doorlock -m opensesame)

so the /usr/bin/mosquitto_pub -h test.mosquitto.org -t doorlock -m opensesame works when I run it from cli, but during the conversation if I press *3 I just see on the following output:

Receiving tone * from sip:[email protected]
Receiving tone 3 from sip:[email protected]

Somehow I cant get it to work, I dont know what am I doing wrong…

Confirm your edits are good with:

[[email protected] asterisk]# asterisk -x "dialplan show globals" | grep DYNAMIC_FEATURES


[[email protected] asterisk]# asterisk -x "features show"

Dynamic Feature           Default Current
---------------           ------- -------
apprecord                 no def  *1
open                      no def  *3
1 Like

Check your usage in current asterisk of the difference between caller,peer,callee. You probably dont want the ‘caller’ to unilaterally let herself in :wink:

Also make sure that the asteriskuser has permission to run that command (it should) , you are testing it as root.

Interesting…this is my output:

[email protected]:~# asterisk -x “dialplan show globals” | grep DYNAMIC_FEATURES

[email protected]:~# asterisk -x “features show”
Builtin Feature Default Current

Pickup *8 *8
Blind Transfer # #
Attended Transfer
One Touch Monitor
Disconnect Call * *
Park Call
One Touch MixMonitor

Dynamic Feature Default Current


Feature Groups:


So I don’t have the Dynamic Feature…

Asterisk User has the rights to publish:

[email protected]:~# su asterisk
$ /usr/bin/mosquitto_pub -h test.mosquitto.org -t opendoor -m opensesame

[email protected]:/# mosquitto_sub -h test.mosquitto.org -v -t opendoor
opendoor opensesame

Does that mean when I change it to the callee then only the callee can run that feature?

Here’s one FM to R :wink:



Is where you add globals in asterisk but outside FreePBX, (maybe that is now changed.)

I have successfully achieved my Goal :slight_smile:

So a BIG thank you goes to Dicko and the lgaetz

that link helped me: https://wiki.asterisk.org/wiki/display/AST/Custom+Dynamic+Features but frankly I have already saw that one before but was to scared to alter the feature.conf and extension.conf and extension.conf files because of early media in the past, and a lot, lot, lot of other stuff…and because of the warning on the top “DO NOT ALTER”…and so on…

The fun Part:

config as above with these two new things that came along:

in the features.con file under applicationmap:
include features_applicationmap_additional.conf
include features_applicationmap_custom.conf
open => *3,callee,TrySystem(/usr/bin/mosquitto_pub -h “test.mosquitto.org” -t “opendoor” -m “opensesame”)

the callee option is not working, meaning both can open door with *3, but Ill check that later…

in the extension.conf file added at the end of the file:

So next Goal is to create mqtt-python-gpio connectionfor door to open , and after that forward my calls from Asterisk to the internet, so meaning I can answer to the door even from outside…and the rest of the would be the same, only the mqtt broker would be in that case on the inside…so I cut down some security issues.

So my next question is how I do it? What is the best practice when it comes to that? I know i can get a free sip account make a trunk and then Im publicly available but if I want to make it free off charge for me I would need a second sip account and register that one on my phone and then these two speak free of charge…but if I want the third one…and so on…so what would be alternatives to that?

1 Like

Any edits you make to files that have a warning in the header will be lost on reload.

Even on server restart?

I have restarted the Server and run dialplan reload and core reload and it is still there…nothing has been deleted.

The two files you edited are symlinked to their counterparts in the FreePBX module webroot:

[[email protected] etc]# ll /etc/asterisk/ | grep "features.conf\|extensions.conf"
lrwxrwxrwx. 1 asterisk asterisk     52 Dec 19  2017 extensions.conf -> /var/www/html/admin/modules/core/etc/extensions.conf
lrwxrwxrwx. 1 asterisk asterisk     50 Dec 19  2017 features.conf -> /var/www/html/admin/modules/core/etc/features.conf

you’ve altered FreePBX module files, which will probably trigger dashboard warnings of altered files, but more importantly will be overwritten when you update the core module. The only supported way to adding features is what you were doing first, as described in this post: