If you haven’t checked out Twilio.com, you should. It lets one create interactive voice applications. This is a first pass at calling out to twilio from vera. All it does wrap their restful interface which will call back to twiml file you have hosted somewhere (like Dropbox.com). This twiml can do anything you want, such as call back to Vera’s web interface when key pads are pressed.
See the twiml documentation for more information:
http://www.twilio.com/docs/api/2008-08-01/twiml/
http://www.twilio.com/docs/api/2008-08-01/twiml/gather
And here is the code, I’m not sure if this can be packaged up in something more elegant, this is my first time playing with Lua/Luup/Vera. You’ll have to sign up for your own twilio account (free demo).
Luup code:
-- Edit this information with the valid info from your twilio account.
-- To and from phones can be the same!
local account_sid = "ACCOUNT SID HERE"
local auth_token = "AUTH TOKEN"
local from_phone = "FROM PHONE"
local to_phone = "TO PHONE"
-- Host your twiml file somewhere like dropbox.com
local twiml_url = "http://path.to.your/twiml.xml"
local function twilio(twiml)
local url = "https://api.twilio.com/2008-08-01/Accounts/"..account_sid.."/Calls"
local data = "Caller="..from_phone.."&Called="..to_phone.."&Url="..twiml.."&Method=GET"
local cmd = 'curl -k -d "'..data..'" -u '..account_sid..':'..auth_token..' '..url
--luup.log(cmd)
local rc = os.execute(cmd)
if (rc ~= 0) then
luup.log('ERROR: os.execute returned '..rc)
return false
else
return true
end
end
-- Place the call!
return twilio(twiml_url)
And a basic twiml file. Example, we’ve got a cabin out at my grand parents ranch. We’re about an hour away, the grand parents are about 3 minutes away. If the basement is flooding we want them to know, unfortunately they don’t have cell phones and if they did they wouldn’t know what a sms message was. This twiml will call them and let them know the cabin is flooding (triggered from a water sensor):
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>This is an emergency, the cabin might be flooding. Please check ASAP and call Tys!</Say>
</Response>
To go further, one could use the twiml verb to send a request back to Vera. Some work would have to be done to process which digits were pressed on the Vera side of things. In theory it could be used to do something like when an alarm gets triggered, call the user and ask for user input, ie “Press one to turn on all lights and trigger the home defences”, “Press two to release the fembots”, etc.
Enjoy!
- Tys