myhomeiot asked me to share my FreePBX setup here for the Dahua.
I have a setup where the VTO Dials a ring group, which calls all my devices. When the first device answers, the others will stop ringing. I can press # open the lock (in my case this opens a drive in gate). This allows me to use any SIP client, so I can answer the door from my PC. You could also potentially use this to call over the standard PSTN network - but I have never tried that.
First off, FreePBX does not work in docker so don’t waste your time trying like I did.
I used libvirt/kvm to install the FreePBX operating system. I used macvtap to give it a dedicated IP address on my LAN.
Once you’ve installed, head to the FreePBX admin panel and go to applications > extensions and create an extension with number 8001. Note the “Secret”, this is the password to use in SIP clients.
Create another extension with number 1001. Again note the secret. Set up a SIP client (I used linphone) and connect to [email protected]. Make sure that’s working and the light goes green.
Next head to applications > ring groups and add a ring group. Give it number 9901. In extension list enter 1001. Don’t need to change anything else.
On the Dahua VTO, my SIP settings are:
SIP Server Enable: Unchecked.
Server Type: ThirdParty
IP address: IP of FreePBX Server
Port: 5060
Username: 8001, Enable unchecked
Password: Extension password
At this point things should work, if you want # to open the lock support, read on.
Create /etc/asterisk/extensions_custom.conf and change the two instances of CHANGEME (The first is the password you’d when visiting the Dahuas web panel)
[macro-gateopen]
exten => s,1,System(curl --digest -v -u admin:CHANGEME "http://CHANGEME/cgi-bin/accessControl.cgi?action=openDoor&UserID=101&Type=Remote&channel=1")
;end [macro-gateopen]
Create /etc/asterisk/features_applicationmap_custom.conf
opengate => #,caller,macro,gateopen
Create /etc/asterisk/globals_custom.conf
DYNAMIC_FEATURES = opengate
After restarting FreePBX you should be good to go. Note that this is a slightly hacky solution, since # will work on any call made through FreePBX, and either side of a call will be able to open the gate. So it’s only a good solution if you use FreePBX for your Dahua and nothing else, which in my case, I do.
I’m on home assistant discord if anyone has any questions about it