SlideShare ist ein Scribd-Unternehmen logo
1 von 39
Downloaden Sie, um offline zu lesen
Home Automation with Asterisk
Alberto Sagredo Castro
www.voipnovatos.es
10/14/2015
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
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
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 :)
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
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
7
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 :)
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)
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
OpenHab
11
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
How to start
13
Installing OpenHab
14
• If you use Debian install repos
curl 'https://bintray.com/user/downloadSubjectPublicKey?
username=openhab' | sudo apt-key add -
echo "deb http://dl.bintray.com/openhab/apt-repo stable main" | sudo
tee /etc/apt/sources.list.d/openhab.list
sudo apt-get update
sudo apt-get install openhab-runtime
update-rc.d openhab defaults
service openhab start
Install Java & esential bindings
15
sudo tar zxvf jdk-8-ea-b36e-linux-arm-hflt-*.tar.gz -C /opt
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/
jdk1.8.0/bin/java" 1
sudo update-alternatives for other commands if needed (e.g. javac).
java -version
Install Java & esential bindings
16
sudo apt-get install openhab-addon-binding-samsungtv
sudo apt-get install openhab-addon-binding-zwave
sudo apt-get install openhab-addon-io-myopenhab
sudo apt-get install openhab-addon-persistence-exec openhab-addon-
persistence-logging
sudo apt-get install openhab-addon-binding-opensprinkler
sudo apt-get install openhab-addon-binding-http openhab-addon-binding-ntp
sudo apt-get install openhab-addon-action-pushover
sudo apt-get install openhab-addon-binding-asterisk
Asterisk
17
Install Asterisk
Enable manager (AMI) , http and ARI
and Lets see how to integrate!
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…..
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!
Dangerous Demo 1
20
• Asterisk Dialplan
[astricon-ivr]
exten => s,1,Noop
exten => s,n,Background(welcomeivr)
exten => s,n,WaitExten(10)
exten => s,n,Hangup
exten => 1,1,Noop(Turn on light)
exten => 1,n,GotoIf($[${DB(light/astricon)} = "ON"]?lighton:lightoff)
exten => 1,n(lighton),Set(${DB(light/astricon)="OFF"})
exten => 1,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.2:8080/rest/items/Z_Socket1/)
exten => 1,n,Playback(lightoff)
exten => 1,n,Hangup
exten => 1,n(lightoff),Set(${DB(light/astricon)="ON"})
exten => 1,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.2:8080/rest/items/Z_Socket1/)
exten => 1,n,Playback(lighton)
exten => 1,n,Hangup
exten => 2,1,Noop(Fire Alarm)
exten => 2,n,GotoIf($[${DB(alarm/astricon)} = "ON"]?fired:notfired)
exten => 2,n(fired),Set(${DB(alarm/astricon)="OFF"})
exten => 2,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.2:8080/rest/items/FortrezZ_Siren)
exten => 2,n,Playback(thieves)
exten => 2,n,Hangup
exten => 2,n(notfired),Set(${DB(alarm/astricon)="ON"})
exten => 2,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.2:8080/rest/items/FortrezZ_Siren)
exten => 2,n,Playback(nothieves)
exten => 2,n,Hangup
exten => 3,1,Noop(Sprinkler)
exten => 3,n,GotoIf($[${DB(sprinkler/astricon)} = "ON"]?on:off)
exten => 3,n(on),Set(${DB(sprinkler/astricon)="OFF"})
exten => 3,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.2:8080/rest/items/Sprinklers_Zone4)
exten => 3,n,Playback(closedsprinklers)
exten => 3,n,Hangup
exten => 3,n(off),Set(${DB(sprinkler/astricon)="ON"})
exten => 3,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.2:8080/rest/items/Sprinklers_Zone4)
exten => 3,n,Playback(opensprinklers)
exten => 3,n,Hangup
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!
Dangerous Demo 2
22
• Google ASR
• Asterisk Speech Recognition http://zaf.github.io/asterisk-
speech-recog/
Dangerous Demo 2
23
• Asterisk Dialplan
[astricon-asr]
exten => s,1,Noop
exten => s,n,Background(welcomeivr)
exten => s,n,agi(speech-recog-tiny.agi,en-US)
exten => s,n,Verbose(1,The text you just said is: ${utterance})
exten => s,n,Verbose(1,The probability to be right is: ${confidence})
exten => s,n,GotoIf($["${uterance}" = "fire alarm"]?firealarm)
exten => s,n,GotoIf($["${uterance}" = "turn on"]?turnonlight:out)
exten => s,n(firealarm),Goto(firealarm,1)
exten => s,n,Hangup
exten => s,n(turnonlight),Goto(turnonlight,1)
exten => s,n(out),Hangup
exten => turnonlight,1,Noop(Turn on light)
exten => turnonlight,n,GotoIf($[${DB(light/astricon)} = "ON"]?lighton:lightoff)
exten => turnonlight,n(lighton),Set(DB(light/astricon)="OFF")
exten => turnonlight,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/Z_Socket1/)
exten => turnonlight,n,Playback(lightoff)
exten => turnonlight,n,Hangup
exten => turnonlight,n(lightoff),Set(DB(light/astricon)="ON")
exten => turnonlight,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/Z_Socket1/)
exten => turnonlight,n,Playback(lighton)
exten => turnonlight,n,Hangup
exten => firealarm,1,Noop(Fire Alarm)
exten => firealarm,n,GotoIf($[${DB(alarm/astricon)} = "ON"]?fired:notfired)
exten => firealarm,n(fired),Set(DB(alarm/astricon)="OFF")
exten => firealarm,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/FortrezZ_Siren)
exten => firealarm,n,Playback(nothieves)
exten => firealarm,n,Hangup
exten => firealarm,n(notfired),Set(DB(alarm/astricon)="ON")
exten => firealarm,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/FortrezZ_Siren)
exten => firealarm,n,Playback(thieves)
exten => firealarm,n,Hangup
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.
Dangerous Demo 3
25
• Asterisk Dialplan
[astricon-presence]
exten => s,1,Answer()
exten => s,n,AGI(openhab.agi, "asterisk", "password", "Fibaro_Motion_1_Motion", "atHomeMotion")
exten => s,n,AGI(openhab.agi, "asterisk", "password", "Home_Presence", "atHomeWifi")
exten => s,n,GotoIf($["${atHomeMotion}" == "ON"]?athome)
exten => s,n,GotoIf($["${atHomeWifi}" == "ON"]?athome:away)
exten => s,n,Goto(bye)
exten => s,n(athome),Playback(movementdetected)
exten => s,n,Hangup()
exten => s,n(away),Playback(movementnotdetected)
exten => s,n(bye),Hangup()
[astricon-presence2]
exten => s,1,Answer()
exten => s,n,GotoIf($["${PRESENCE}" == "ON"]?athome:away)
exten => s,n(athome),Playback(movementdetected)
exten => s,n,Hangup()
exten => s,n(away),Playback(movementnotdetected)
exten => s,n,Hangup()
Dangerous Demo 3
26
• Openhab.agi
#!/usr/bin/python
import sys,os,datetime
import httplib
import base64
def send(data):
sys.stdout.write("%s n"%data)
sys.stdout.flush()
AGIENV={}
env = ""
while(env != "n"):
env = sys.stdin.readline()
envdata = env.split(":")
if len(envdata)==2:
AGIENV[envdata[0].strip()]=envdata[1].strip()
username = AGIENV['agi_arg_1']
password = AGIENV['agi_arg_2']
item = AGIENV['agi_arg_3']
varname = AGIENV['agi_arg_4']
auth = base64.encodestring('%s:%s' % (username, password)).replace('n', '')
headers = {"Authorization" : "Basic %s" % auth}
conn = httplib.HTTPConnection("localhost", 8080)
conn.request('GET', "/rest/items/%s/state"%item, "", headers)
response = conn.getresponse()
item_state = response.read()
send("SET VARIABLE %s %s"%(varname, item_state))
sys.stdin.readline()
Dangerous Demo 3
27
• Openhab rules
rule "MotionOn"
when
Item Fibaro_Motion_1_Motion changed from OFF to ON
then
counter = counter + 1
logInfo("Rules", "Motion Rule ON")
executeCommandLine("/usr/src/openhab/configurations/rules/curlon.sh")
pushover("Motion Detected on Astricon")
end
rule "MotionOff"
when
Time cron "0 */2 * * * ?"
then
if(lastCheck == counter) {
counter = 0
lastCheck = -1;
logInfo("Rules", "Motion Rule OFF")
executeCommandLine("/usr/src/openhab/configurations/rules/curloff.sh")
} else {
lastCheck = counter
}
end
Dangerous Demo 3
28
• Openhab rules
var Timer timer = null
rule "MotionOn2"
when
Item Fibaro_Door changed
then
if(Fibaro_Door.state==ON) {
executeCommandLine("/etc/openhab/configurations/rules/curlondoor.sh")
if(timer==null) {
timer = createTimer(now.plusSeconds(10)) [|
executeCommandLine("/etc/openhab/configurations/rules/curloffdoor.sh")
]
} else {
timer.reschedule(now.plusSeconds(10))
}
} else if(Fibaro_Door.state==OFF) {
if(timer!=null) {
timer.cancel
timer = null
}
}
end
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"
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
Dangerous Demo 4
31
• ari.conf
[general]
enabled = yes
allowed_origins=http://ari.asterisk.org
[asterisk]
type = user
read_only = no
password = asterisk
• http.conf
[general]
enabled = yes
bindaddr=0.0.0.0
• manager.conf[general]
enabled = yes
;webenabled = yes
port = 5038
bindaddr = 127.0.0.1
[asterisk]
secret = asterisk
read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan
write = system,call,agent,user,config,command,reporting,originate,message
Dangerous Demo 4
32
• extensions.conf
[extensiones]
exten => _2XX,1,Dial(SIP/${EXTEN},20,TtrR)
exten => _2XX,n,hangup
exten => 900,1,Answer
exten => 900,n,Playback(policecall)
exten => 900,n,Ringing()
exten => 900,n,Wait(10)
exten => 900,n,Hangup
• alarmon.sh
#!/bin/bash
curl -v -u asterisk:asterisk -X POST "http://10.0.2.19:8088/ari/asterisk/variable?variable=ALARM&value=ON&api_key=asterisk:asterisk"
curl -v -u asterisk:asterisk -X POST "http://10.0.2.19:8088/ari/channels?endpoint=SIP
%2F201&extension=900&context=extensiones&priority=1&callerId=ALARM%20DETECTED%20ASTRICON&timeout=30&api_key=asterisk:asterisk"
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
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.
Bonus Demo
35
• extensions.conf
[extensiones]
exten => 999,1,Set(${CALLERID(num)}=778811)
exten => 999,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/Asterisk_Ring)
exten => 999,n,Ringing()
exten => 999,n,Wait(10)
exten => 999,n,Answer()
exten => 999,n,Echo()
exten => 999,n,Hangup
exten => h,1,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/Asterisk_Ring)
• call.sh
#!/bin/bash
json_clause=$(curl http://10.0.2.19:8088/ari/channels?api_key=asterisk:asterisk)
state=$(echo $json_clause | jq '.[0].state')
name=$(echo $json_clause | jq '.[0].name')
numbercalling=$(echo $json_clause | jq '.[0].caller.number')
numbercalled=$(echo $json_clause | jq '.[0].dialplan.exten')
numbercalled2=$(echo $json_clause | jq '.[0].connected.number')
curl --header 'Content-Type: text/plain' --request PUT --data "$numbercalling" http://localhost:8080/rest/items/Active_Calling/state/
curl --header 'Content-Type: text/plain' --request PUT --data "$numbercalled" http://localhost:8080/rest/items/Active_Called/state/
Bonus Demo
36
• Openhab rules
rule "Call"
when
Item Asterisk_Ring changed
then
if(Asterisk_Ring.state == ON)
{
executeCommandLine("bash /etc/openhab/configurations/rules/call.sh")
}
if(Asterisk_Ring.state == OFF)
{
executeCommandLine(" bash /etc/openhab/configurations/rules/calloff.sh")
}
end
Questions?
37
Resources
38
• www.openhab.org
• https://github.com/openhab/openhab/wiki/Samples-Rules
• https://github.com/openhab/openhab/wiki/Explanation-of-items
• https://github.com/openhab/openhab/wiki/Linux---OS-X
• http://raspberrypi.stackexchange.com/questions/4683/how-to-install-the-java-
jdk-on-raspberry-pi
• http://zaf.github.io/asterisk-speech-recog/
• http://tinsley.io/2015/03/openhab-presence-detection-with-dd-wrt/
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!

Weitere ähnliche Inhalte

Was ist angesagt?

IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
David Fowler
 
Arduino i rremote 1112
Arduino i rremote 1112Arduino i rremote 1112
Arduino i rremote 1112
馬 萬圳
 
Fosdem 2010 - An Introduction to Enna Media Center
Fosdem 2010 - An Introduction to Enna Media CenterFosdem 2010 - An Introduction to Enna Media Center
Fosdem 2010 - An Introduction to Enna Media Center
Benjamin Zores
 
Web Presentation Week11
Web Presentation Week11Web Presentation Week11
Web Presentation Week11
guest8732a6
 

Was ist angesagt? (20)

lwM2M OTA for ESP8266
lwM2M OTA for ESP8266lwM2M OTA for ESP8266
lwM2M OTA for ESP8266
 
Costruiamo un Rover in 60 minuti
Costruiamo un Rover in 60 minutiCostruiamo un Rover in 60 minuti
Costruiamo un Rover in 60 minuti
 
Adafruit Huzzah Esp8266 WiFi Board
Adafruit Huzzah Esp8266 WiFi BoardAdafruit Huzzah Esp8266 WiFi Board
Adafruit Huzzah Esp8266 WiFi Board
 
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
IoT simple with the ESP8266 - presented at the July 2015 Austin IoT Hardware ...
 
Arduino i rremote 1112
Arduino i rremote 1112Arduino i rremote 1112
Arduino i rremote 1112
 
Fosdem 2010 - An Introduction to Enna Media Center
Fosdem 2010 - An Introduction to Enna Media CenterFosdem 2010 - An Introduction to Enna Media Center
Fosdem 2010 - An Introduction to Enna Media Center
 
Arduino Meetup with Sonar and 433Mhz Radios
Arduino Meetup with Sonar and 433Mhz RadiosArduino Meetup with Sonar and 433Mhz Radios
Arduino Meetup with Sonar and 433Mhz Radios
 
Internet Of Things: Hands on: YOW! night
Internet Of Things: Hands on: YOW! nightInternet Of Things: Hands on: YOW! night
Internet Of Things: Hands on: YOW! night
 
Web Presentation Week11
Web Presentation Week11Web Presentation Week11
Web Presentation Week11
 
Making wearables with NodeMCU - FOSDEM 2017
Making wearables with NodeMCU - FOSDEM 2017Making wearables with NodeMCU - FOSDEM 2017
Making wearables with NodeMCU - FOSDEM 2017
 
P&O Session 2
P&O Session 2P&O Session 2
P&O Session 2
 
Esp8266 hack sonoma county 4/8/2015
Esp8266 hack sonoma county 4/8/2015Esp8266 hack sonoma county 4/8/2015
Esp8266 hack sonoma county 4/8/2015
 
Esp8266 NodeMCU
Esp8266 NodeMCUEsp8266 NodeMCU
Esp8266 NodeMCU
 
Interacting with Intel Edison
Interacting with Intel EdisonInteracting with Intel Edison
Interacting with Intel Edison
 
NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1NodeMCU ESP8266 workshop 1
NodeMCU ESP8266 workshop 1
 
Esp8266 basics
Esp8266 basicsEsp8266 basics
Esp8266 basics
 
Nodemcu - introduction
Nodemcu - introductionNodemcu - introduction
Nodemcu - introduction
 
Build WiFi gadgets using esp8266
Build WiFi gadgets using esp8266Build WiFi gadgets using esp8266
Build WiFi gadgets using esp8266
 
IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019IoT Hands-On-Lab, KINGS, 2019
IoT Hands-On-Lab, KINGS, 2019
 
Esp8266 - Intro for dummies
Esp8266 - Intro for dummiesEsp8266 - Intro for dummies
Esp8266 - Intro for dummies
 

Andere mochten auch

Hacking Z-Wave Home Automation Systems
Hacking Z-Wave Home Automation SystemsHacking Z-Wave Home Automation Systems
Hacking Z-Wave Home Automation Systems
SensePost
 
Home Automation Products and Suppliers in UAE
Home Automation Products and Suppliers in UAEHome Automation Products and Suppliers in UAE
Home Automation Products and Suppliers in UAE
Beatriz john
 
Home automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhaneHome automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhane
Kamal Lamichhane
 
Jonny_Martin-Asterisk
Jonny_Martin-AsteriskJonny_Martin-Asterisk
Jonny_Martin-Asterisk
tutorialsruby
 
VOIP Practica 1 - Marzo
VOIP Practica 1 - MarzoVOIP Practica 1 - Marzo
VOIP Practica 1 - Marzo
Jose Cordova
 
Practica 3 Modified
Practica 3 ModifiedPractica 3 Modified
Practica 3 Modified
Jose Cordova
 
Practica 1 - VOIP II
Practica 1 - VOIP IIPractica 1 - VOIP II
Practica 1 - VOIP II
Jose Cordova
 

Andere mochten auch (20)

RadioVozIP
RadioVozIPRadioVozIP
RadioVozIP
 
Hacking Z-Wave Home Automation Systems
Hacking Z-Wave Home Automation SystemsHacking Z-Wave Home Automation Systems
Hacking Z-Wave Home Automation Systems
 
Home Automation Products and Suppliers in UAE
Home Automation Products and Suppliers in UAEHome Automation Products and Suppliers in UAE
Home Automation Products and Suppliers in UAE
 
Presentation on home automation
Presentation on home automationPresentation on home automation
Presentation on home automation
 
Home automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhaneHome automation ppt-kamal lamichhane
Home automation ppt-kamal lamichhane
 
Presentation Smart Home With Home Automation
Presentation Smart Home With Home AutomationPresentation Smart Home With Home Automation
Presentation Smart Home With Home Automation
 
Asterisk-Java Framework Presentation
Asterisk-Java Framework PresentationAsterisk-Java Framework Presentation
Asterisk-Java Framework Presentation
 
Jonny_Martin-Asterisk
Jonny_Martin-AsteriskJonny_Martin-Asterisk
Jonny_Martin-Asterisk
 
Convegencia de Infraestructuras existentes hacia voip con Asterisk
Convegencia de Infraestructuras existentes hacia voip con AsteriskConvegencia de Infraestructuras existentes hacia voip con Asterisk
Convegencia de Infraestructuras existentes hacia voip con Asterisk
 
Home automation for humans
Home automation for humansHome automation for humans
Home automation for humans
 
02 asterisk - the future of telecommunications
02   asterisk - the future of telecommunications02   asterisk - the future of telecommunications
02 asterisk - the future of telecommunications
 
Telephony Service Development on Asterisk Platform
Telephony Service Development on Asterisk PlatformTelephony Service Development on Asterisk Platform
Telephony Service Development on Asterisk Platform
 
Voz ip desde dispositivos móviles
Voz ip desde dispositivos móvilesVoz ip desde dispositivos móviles
Voz ip desde dispositivos móviles
 
Vektor
VektorVektor
Vektor
 
Implementation Lessons using WebRTC in Asterisk
Implementation Lessons using WebRTC in AsteriskImplementation Lessons using WebRTC in Asterisk
Implementation Lessons using WebRTC in Asterisk
 
A Brief History of Home Automation
A Brief History of Home AutomationA Brief History of Home Automation
A Brief History of Home Automation
 
VOIP Practica 1 - Marzo
VOIP Practica 1 - MarzoVOIP Practica 1 - Marzo
VOIP Practica 1 - Marzo
 
Practica 3 Modified
Practica 3 ModifiedPractica 3 Modified
Practica 3 Modified
 
Practica 1 - VOIP II
Practica 1 - VOIP IIPractica 1 - VOIP II
Practica 1 - VOIP II
 
Cohon Gene
Cohon GeneCohon Gene
Cohon Gene
 

Ähnlich wie Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro

Intro to the raspberry pi board
Intro to the raspberry pi boardIntro to the raspberry pi board
Intro to the raspberry pi board
Thierry Gayet
 
[JAM 1.2] Design & Multitasking (Andrew Solovey)
[JAM 1.2] Design & Multitasking (Andrew Solovey)[JAM 1.2] Design & Multitasking (Andrew Solovey)
[JAM 1.2] Design & Multitasking (Andrew Solovey)
Evgeny Kaziak
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
Serge Stinckwich
 

Ähnlich wie Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro (20)

Exploring the Internet of Things Using Ruby
Exploring the Internet of Things Using RubyExploring the Internet of Things Using Ruby
Exploring the Internet of Things Using Ruby
 
Introduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIOIntroduction to Raspberry Pi and GPIO
Introduction to Raspberry Pi and GPIO
 
Nodebot: Arte de controlar arduino com javascript
Nodebot: Arte de controlar arduino com javascriptNodebot: Arte de controlar arduino com javascript
Nodebot: Arte de controlar arduino com javascript
 
Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010Python于Web 2.0网站的应用 - QCon Beijing 2010
Python于Web 2.0网站的应用 - QCon Beijing 2010
 
Getting Started with iBeacons (Designers of Things 2014)
Getting Started with iBeacons (Designers of Things 2014)Getting Started with iBeacons (Designers of Things 2014)
Getting Started with iBeacons (Designers of Things 2014)
 
playaround workshop 2010 - internet of the real things
playaround workshop 2010 - internet of the real thingsplayaround workshop 2010 - internet of the real things
playaround workshop 2010 - internet of the real things
 
CI/CD on Windows-Based Environments - Noam Shochat, eToro - DevOpsDays Tel Av...
CI/CD on Windows-Based Environments - Noam Shochat, eToro - DevOpsDays Tel Av...CI/CD on Windows-Based Environments - Noam Shochat, eToro - DevOpsDays Tel Av...
CI/CD on Windows-Based Environments - Noam Shochat, eToro - DevOpsDays Tel Av...
 
Arduino delphi 2014_7_bonn
Arduino delphi 2014_7_bonnArduino delphi 2014_7_bonn
Arduino delphi 2014_7_bonn
 
"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos"Elixir of Life" - Dev In Santos
"Elixir of Life" - Dev In Santos
 
2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge2015 bioinformatics python_io_wim_vancriekinge
2015 bioinformatics python_io_wim_vancriekinge
 
Pwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and AsteriskPwning Your Phone with Adhearsion and Asterisk
Pwning Your Phone with Adhearsion and Asterisk
 
Intro to the raspberry pi board
Intro to the raspberry pi boardIntro to the raspberry pi board
Intro to the raspberry pi board
 
Elasticsearch sur Azure : Make sense of your (BIG) data !
Elasticsearch sur Azure : Make sense of your (BIG) data !Elasticsearch sur Azure : Make sense of your (BIG) data !
Elasticsearch sur Azure : Make sense of your (BIG) data !
 
[JAM 1.2] Design & Multitasking (Andrew Solovey)
[JAM 1.2] Design & Multitasking (Andrew Solovey)[JAM 1.2] Design & Multitasking (Andrew Solovey)
[JAM 1.2] Design & Multitasking (Andrew Solovey)
 
JavaScript in 2015
JavaScript in 2015JavaScript in 2015
JavaScript in 2015
 
A.I. Exercise.
A.I. Exercise.A.I. Exercise.
A.I. Exercise.
 
An introduction to Ruby
An introduction to RubyAn introduction to Ruby
An introduction to Ruby
 
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
EclipseCon Europe 2013 - Turning Eclipse into an Arduino programming platform...
 
Network programming
Network programmingNetwork programming
Network programming
 
Using Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systemsUsing Smalltalk for controlling robotics systems
Using Smalltalk for controlling robotics systems
 

Kürzlich hochgeladen

CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Kürzlich hochgeladen (20)

08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Home Automation with Asterisk - Astricon 2015 - Alberto Sagredo Castro

  • 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
  • 7. 7
  • 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
  • 14. Installing OpenHab 14 • If you use Debian install repos curl 'https://bintray.com/user/downloadSubjectPublicKey? username=openhab' | sudo apt-key add - echo "deb http://dl.bintray.com/openhab/apt-repo stable main" | sudo tee /etc/apt/sources.list.d/openhab.list sudo apt-get update sudo apt-get install openhab-runtime update-rc.d openhab defaults service openhab start
  • 15. Install Java & esential bindings 15 sudo tar zxvf jdk-8-ea-b36e-linux-arm-hflt-*.tar.gz -C /opt sudo update-alternatives --install "/usr/bin/java" "java" "/opt/ jdk1.8.0/bin/java" 1 sudo update-alternatives for other commands if needed (e.g. javac). java -version
  • 16. Install Java & esential bindings 16 sudo apt-get install openhab-addon-binding-samsungtv sudo apt-get install openhab-addon-binding-zwave sudo apt-get install openhab-addon-io-myopenhab sudo apt-get install openhab-addon-persistence-exec openhab-addon- persistence-logging sudo apt-get install openhab-addon-binding-opensprinkler sudo apt-get install openhab-addon-binding-http openhab-addon-binding-ntp sudo apt-get install openhab-addon-action-pushover sudo apt-get install openhab-addon-binding-asterisk
  • 17. Asterisk 17 Install Asterisk Enable manager (AMI) , http and ARI and Lets see how to integrate!
  • 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!
  • 20. Dangerous Demo 1 20 • Asterisk Dialplan [astricon-ivr] exten => s,1,Noop exten => s,n,Background(welcomeivr) exten => s,n,WaitExten(10) exten => s,n,Hangup exten => 1,1,Noop(Turn on light) exten => 1,n,GotoIf($[${DB(light/astricon)} = "ON"]?lighton:lightoff) exten => 1,n(lighton),Set(${DB(light/astricon)="OFF"}) exten => 1,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.2:8080/rest/items/Z_Socket1/) exten => 1,n,Playback(lightoff) exten => 1,n,Hangup exten => 1,n(lightoff),Set(${DB(light/astricon)="ON"}) exten => 1,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.2:8080/rest/items/Z_Socket1/) exten => 1,n,Playback(lighton) exten => 1,n,Hangup exten => 2,1,Noop(Fire Alarm) exten => 2,n,GotoIf($[${DB(alarm/astricon)} = "ON"]?fired:notfired) exten => 2,n(fired),Set(${DB(alarm/astricon)="OFF"}) exten => 2,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.2:8080/rest/items/FortrezZ_Siren) exten => 2,n,Playback(thieves) exten => 2,n,Hangup exten => 2,n(notfired),Set(${DB(alarm/astricon)="ON"}) exten => 2,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.2:8080/rest/items/FortrezZ_Siren) exten => 2,n,Playback(nothieves) exten => 2,n,Hangup exten => 3,1,Noop(Sprinkler) exten => 3,n,GotoIf($[${DB(sprinkler/astricon)} = "ON"]?on:off) exten => 3,n(on),Set(${DB(sprinkler/astricon)="OFF"}) exten => 3,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.2:8080/rest/items/Sprinklers_Zone4) exten => 3,n,Playback(closedsprinklers) exten => 3,n,Hangup exten => 3,n(off),Set(${DB(sprinkler/astricon)="ON"}) exten => 3,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.2:8080/rest/items/Sprinklers_Zone4) exten => 3,n,Playback(opensprinklers) exten => 3,n,Hangup
  • 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/
  • 23. Dangerous Demo 2 23 • Asterisk Dialplan [astricon-asr] exten => s,1,Noop exten => s,n,Background(welcomeivr) exten => s,n,agi(speech-recog-tiny.agi,en-US) exten => s,n,Verbose(1,The text you just said is: ${utterance}) exten => s,n,Verbose(1,The probability to be right is: ${confidence}) exten => s,n,GotoIf($["${uterance}" = "fire alarm"]?firealarm) exten => s,n,GotoIf($["${uterance}" = "turn on"]?turnonlight:out) exten => s,n(firealarm),Goto(firealarm,1) exten => s,n,Hangup exten => s,n(turnonlight),Goto(turnonlight,1) exten => s,n(out),Hangup exten => turnonlight,1,Noop(Turn on light) exten => turnonlight,n,GotoIf($[${DB(light/astricon)} = "ON"]?lighton:lightoff) exten => turnonlight,n(lighton),Set(DB(light/astricon)="OFF") exten => turnonlight,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/Z_Socket1/) exten => turnonlight,n,Playback(lightoff) exten => turnonlight,n,Hangup exten => turnonlight,n(lightoff),Set(DB(light/astricon)="ON") exten => turnonlight,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/Z_Socket1/) exten => turnonlight,n,Playback(lighton) exten => turnonlight,n,Hangup exten => firealarm,1,Noop(Fire Alarm) exten => firealarm,n,GotoIf($[${DB(alarm/astricon)} = "ON"]?fired:notfired) exten => firealarm,n(fired),Set(DB(alarm/astricon)="OFF") exten => firealarm,n,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/FortrezZ_Siren) exten => firealarm,n,Playback(nothieves) exten => firealarm,n,Hangup exten => firealarm,n(notfired),Set(DB(alarm/astricon)="ON") exten => firealarm,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/FortrezZ_Siren) exten => firealarm,n,Playback(thieves) exten => firealarm,n,Hangup
  • 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.
  • 25. Dangerous Demo 3 25 • Asterisk Dialplan [astricon-presence] exten => s,1,Answer() exten => s,n,AGI(openhab.agi, "asterisk", "password", "Fibaro_Motion_1_Motion", "atHomeMotion") exten => s,n,AGI(openhab.agi, "asterisk", "password", "Home_Presence", "atHomeWifi") exten => s,n,GotoIf($["${atHomeMotion}" == "ON"]?athome) exten => s,n,GotoIf($["${atHomeWifi}" == "ON"]?athome:away) exten => s,n,Goto(bye) exten => s,n(athome),Playback(movementdetected) exten => s,n,Hangup() exten => s,n(away),Playback(movementnotdetected) exten => s,n(bye),Hangup() [astricon-presence2] exten => s,1,Answer() exten => s,n,GotoIf($["${PRESENCE}" == "ON"]?athome:away) exten => s,n(athome),Playback(movementdetected) exten => s,n,Hangup() exten => s,n(away),Playback(movementnotdetected) exten => s,n,Hangup()
  • 26. Dangerous Demo 3 26 • Openhab.agi #!/usr/bin/python import sys,os,datetime import httplib import base64 def send(data): sys.stdout.write("%s n"%data) sys.stdout.flush() AGIENV={} env = "" while(env != "n"): env = sys.stdin.readline() envdata = env.split(":") if len(envdata)==2: AGIENV[envdata[0].strip()]=envdata[1].strip() username = AGIENV['agi_arg_1'] password = AGIENV['agi_arg_2'] item = AGIENV['agi_arg_3'] varname = AGIENV['agi_arg_4'] auth = base64.encodestring('%s:%s' % (username, password)).replace('n', '') headers = {"Authorization" : "Basic %s" % auth} conn = httplib.HTTPConnection("localhost", 8080) conn.request('GET', "/rest/items/%s/state"%item, "", headers) response = conn.getresponse() item_state = response.read() send("SET VARIABLE %s %s"%(varname, item_state)) sys.stdin.readline()
  • 27. Dangerous Demo 3 27 • Openhab rules rule "MotionOn" when Item Fibaro_Motion_1_Motion changed from OFF to ON then counter = counter + 1 logInfo("Rules", "Motion Rule ON") executeCommandLine("/usr/src/openhab/configurations/rules/curlon.sh") pushover("Motion Detected on Astricon") end rule "MotionOff" when Time cron "0 */2 * * * ?" then if(lastCheck == counter) { counter = 0 lastCheck = -1; logInfo("Rules", "Motion Rule OFF") executeCommandLine("/usr/src/openhab/configurations/rules/curloff.sh") } else { lastCheck = counter } end
  • 28. Dangerous Demo 3 28 • Openhab rules var Timer timer = null rule "MotionOn2" when Item Fibaro_Door changed then if(Fibaro_Door.state==ON) { executeCommandLine("/etc/openhab/configurations/rules/curlondoor.sh") if(timer==null) { timer = createTimer(now.plusSeconds(10)) [| executeCommandLine("/etc/openhab/configurations/rules/curloffdoor.sh") ] } else { timer.reschedule(now.plusSeconds(10)) } } else if(Fibaro_Door.state==OFF) { if(timer!=null) { timer.cancel timer = null } } end
  • 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
  • 31. Dangerous Demo 4 31 • ari.conf [general] enabled = yes allowed_origins=http://ari.asterisk.org [asterisk] type = user read_only = no password = asterisk • http.conf [general] enabled = yes bindaddr=0.0.0.0 • manager.conf[general] enabled = yes ;webenabled = yes port = 5038 bindaddr = 127.0.0.1 [asterisk] secret = asterisk read = system,call,log,verbose,agent,user,config,dtmf,reporting,cdr,dialplan write = system,call,agent,user,config,command,reporting,originate,message
  • 32. Dangerous Demo 4 32 • extensions.conf [extensiones] exten => _2XX,1,Dial(SIP/${EXTEN},20,TtrR) exten => _2XX,n,hangup exten => 900,1,Answer exten => 900,n,Playback(policecall) exten => 900,n,Ringing() exten => 900,n,Wait(10) exten => 900,n,Hangup • alarmon.sh #!/bin/bash curl -v -u asterisk:asterisk -X POST "http://10.0.2.19:8088/ari/asterisk/variable?variable=ALARM&value=ON&api_key=asterisk:asterisk" curl -v -u asterisk:asterisk -X POST "http://10.0.2.19:8088/ari/channels?endpoint=SIP %2F201&extension=900&context=extensiones&priority=1&callerId=ALARM%20DETECTED%20ASTRICON&timeout=30&api_key=asterisk: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.
  • 35. Bonus Demo 35 • extensions.conf [extensiones] exten => 999,1,Set(${CALLERID(num)}=778811) exten => 999,n,System(curl --header "Content-Type: text/plain" --request POST --data "ON" http://10.0.2.19:8080/rest/items/Asterisk_Ring) exten => 999,n,Ringing() exten => 999,n,Wait(10) exten => 999,n,Answer() exten => 999,n,Echo() exten => 999,n,Hangup exten => h,1,System(curl --header "Content-Type: text/plain" --request POST --data "OFF" http://10.0.2.19:8080/rest/items/Asterisk_Ring) • call.sh #!/bin/bash json_clause=$(curl http://10.0.2.19:8088/ari/channels?api_key=asterisk:asterisk) state=$(echo $json_clause | jq '.[0].state') name=$(echo $json_clause | jq '.[0].name') numbercalling=$(echo $json_clause | jq '.[0].caller.number') numbercalled=$(echo $json_clause | jq '.[0].dialplan.exten') numbercalled2=$(echo $json_clause | jq '.[0].connected.number') curl --header 'Content-Type: text/plain' --request PUT --data "$numbercalling" http://localhost:8080/rest/items/Active_Calling/state/ curl --header 'Content-Type: text/plain' --request PUT --data "$numbercalled" http://localhost:8080/rest/items/Active_Called/state/
  • 36. Bonus Demo 36 • Openhab rules rule "Call" when Item Asterisk_Ring changed then if(Asterisk_Ring.state == ON) { executeCommandLine("bash /etc/openhab/configurations/rules/call.sh") } if(Asterisk_Ring.state == OFF) { executeCommandLine(" bash /etc/openhab/configurations/rules/calloff.sh") } end
  • 38. Resources 38 • www.openhab.org • https://github.com/openhab/openhab/wiki/Samples-Rules • https://github.com/openhab/openhab/wiki/Explanation-of-items • https://github.com/openhab/openhab/wiki/Linux---OS-X • http://raspberrypi.stackexchange.com/questions/4683/how-to-install-the-java- jdk-on-raspberry-pi • http://zaf.github.io/asterisk-speech-recog/ • http://tinsley.io/2015/03/openhab-presence-detection-with-dd-wrt/
  • 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!