1. Home Automation with Asterisk
Alberto Sagredo Castro
www.voipnovatos.es
10/14/2015
2. Who i am
• Alberto Sagredo Castro
• a.k.a @albersag on twitter
• Working in VoIP since ten years ago
• Working with Asterisk for about 10
years
• Several large projects with Asterisk
and many Asterisk compiled thru
Spain and Europe
• Working for Avanzada 7 and USA
VOIP
• Other Stuff : Mikrotik, Ubiquiti, Ham
Radio and all that contains bits on it
2
3. Why home automation
• It makes life easier
• Its not expensive
• It helps disabled people
• Internet of Things (IOT) is here
• Its not complex
• Eco friendly and save money
• Just play !
3
4. Home automation vs Asterisk
4
• Asterisk natively does not support home automation
protocols
• We need something to interact with ha (home
automation)
• What could we use? PHPARI, AGI, .call files, asterisk
dialplan, SQL …
• Any programmer here? What about chan_zwave :)
5. Which protocol to use
5
• home automation is plenty of protocols, open, proprietary, half open half proprietary :)
all flavours.
• smarthings
• z-wave
• knx
• insteon
• x10
• zigbee
• opensprinkler
• MQTT
6. Z-Wave
6
• Its a “propietary” protocol owned by Sigma Designs
• Its widely supported by enterprise and really good compatibility
• Its cheap (50 $/device)
• USA & EU frecuencies
• Feedback from device status
• Low energy
• Zwave alliance (+ 400 manufacturers)
• Mesh network between devices. Good for homes
8. Do not reinvent the wheel
8
• Ok. Asterisk does not support (yet) home automation but
i want to use Asterisk in my home automation system….
What could i do?
• I will use Asterisk to generate
calls when events happens
on my HA system and to
interact with them by phone.
• Phone is easier than using
apps and works on any
platform :)
9. OpenHab
9
• Its the swedish knife (a.k.a Olle :) for home automation.
• Lots of binding, plenty of protocols supported and many more
• REST API
• Items
• Sitemaps
• Scripts / Rules (Xtend scripting language)
• Transforms
• Interface to admin Habmin and App for design (Openhab Designer)
10. OpenHab
10
• Its Java .
• Runs on BananaPi or Raspberry Pi without any issues.
• Easy to install.
• Easy as Asterisk to configure.
• Scripting language so you would feel confortable with it
12. How to start
12
• We would need an USB Zwave Dongle (Aeon Labs,
Zwave.me,…)
• A Raspberry Pi or Banana Pi
• Zwave devices
• Asterisk of course
• Internet for notifications and persistent data to the cloud
18. Integration. Lets fun!
18
• Lets focus in how to integrate this cool “weapons” together.
• We could use:
• ARI
• REST API
• CLI
• .call files
• AstDB
• MySQL
• etc…..
19. Dangerous Demo 1
19
• IVR to interact with Lights and if everything goes fine, open
my garden sprinklers in spain remotely (dont be nasty)
• WIFI SSID -> “VOIPNOVATOS”
• Asterisk -> “10.0.2.x”
• User Extension “20x”
• Password : “astricon” of course
• Call 666 and don't be evil!
21. Dangerous Demo 2
21
• For some people it could be great to interact using voice
while in its home. Being at home or not, Asterisk could
turn on lights, turn off alarm and make emergency calls
• Use Google ASR, Its free and it works well! (Use latest agi
version as oldest has issues)
• You need internet connection! Hope astricon one would
work well!
22. Dangerous Demo 2
22
• Google ASR
• Asterisk Speech Recognition http://zaf.github.io/asterisk-
speech-recog/
24. Dangerous Demo 3
24
• Smart followme
• You can use Wifi to detect you are at home or presence
detectors.
• If you are outside home, divert your calls to cell phone.
Just ring on Kitchens phone if you are cooking (Advise:
this will not work if you have kids moving around)
• Here we could use AGI to get motion status from
Openhab.
29. Dangerous Demo 3
29
• Wifi Detector
#!/bin/sh
macalberto="f0:27:2d:00:44:12"
athome=0
macs=$(iw dev wlan0 station dump | grep Station | cut -f 2 -s -d" ")
for mac in $macs; do
case $mac in
"$macalberto") athome=1;;
esac
done
if [ $athome -eq 1 ]; then
curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/Home_Presence/
else
curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/Home_Presence/
fi
• curlon.sh
#!/bin/bash
curl -v -u asterisk:asterisk -X POST "http://10.0.2.19:8088/ari/asterisk/variable?variable=PRESENCEvalue=ON&api_key=asterisk:asterisk"
30. Dangerous Demo 4
30
• Create your own Alarm System controlled by phone
• We could arm alarm system by phone
• No monthly fees
• If armed and motion is detected call police or call you
before police that would be better :)
• If fired, open sprinklers at garden..
• Used ARI to gen calls on Asterisk
33. Dangerous Demo 4
33
• Openhab rules
rule "Alarm"
when
Item Fibaro_Door changed from OFF to ON
then
if(Fibaro_Door.state == ON && Alarm_Switch.state == ON )
{
logInfo("Rules", "Alarm Alarm Alarm")
executeCommandLine("/etc/openhab/configurations/rules/alarmon.sh")
pushover("Alarm on Astricon")
}
end
rule "Water"
when
Item Fibaro_Flood changed
then
if(Fibaro_Flood.state == 255 && Alarm_Switch.state == ON )
{
logInfo("Rules", "Alarm Alarm Alarm")
executeCommandLine("/etc/openhab/configurations/rules/alarmon.sh")
pushover("Alarm on Astricon")
}
end
34. Bonus Demo
34
• Asterisk Ringing Status and Called/Calling Number
• We have an openhab binding but it does not work with
new AMI
• Using JSON answer from Asterisk ARI and jq , json
parser will try to get this working.
39. Thanks
39
• To my wife and kids they are always with me and also
here (Disney off course :)
• All friends wishing luck these days
• To Fibaro
• To Digium for inviting me. It has been a pleasure and an
amazing christmas gift!
• To all of you for attending!