Eric Blue’s Home Automation Hacks with Belkin, Twilio and Siri
Time to read: 3 minutes
When Eric’s friends came to visit him and pressed his apartment buzzer, he would get a call. But, if when he was watching a movie or playing a video game he’d often miss the call. So, Eric used Twilio to forward calls from his apartment buzzer to display on his TV, so he never missed a call, even if he was in the middle of a heated battle on Xbox.
Once he finished the TV hack, Eric wanted to do more. Using a Belkin Wemo, Twilio SMS and Siri, Eric developed a way to turn the lights in his apartment on and off via voice command and text. Take a look at Eric’s tutorial below originally published on his blog here
Learn more about Eric and his independent software development projects by visiting his blog here
Last year around this time on an ambitious evening I had an idea to quickly mashup some APIs, and make a cool and useful home automation hack. This example uses the Belkin Wemo power switches, my Perl API (WebService::Belkin::WeMo) for controlling them, Twilio, and the built in features of voice control with Siri on the iPhone. It sounds complicated, but with relatively little code you can automatically turn your lights on and off in your home by either sending a text message, or even using voice commands (ex: “Computer turn all lights on!”)
Overview Diagram
Belkin WeMo Perl API
Last year when I first got my Belkin WeMo switches I was disappointed to see there was no API out there yet. And, given my go to language for quick ‘hacks’ is Perl I decided to reverse engineer how it works. Luckily it’s based on UPNP (Universal Plug n’ Play) and didn’t take too much work to figure out how to search for switches and sensors, and send commands to toggle electrical outlets on and off. The code has been available on GitHub for some time, and I just recently uploaded to CPAN to make distribution and inclusion easier.
Step by Step Instructions
[API and SMS server]
- Find a computer located on the same network as your Belkin Devices. Ensure your firewall/router can open up port 9000 (default) and map to your computer.
- Check out the Perl Belkin Wemo API from CPAN (v1.0 as of this writing) for the latest stable version, or Github for the latest developments.
- Scan your local network to find all Belkin Wemo Switches and save into your /etc/belkin.db file (see examples/scan.pl under the Perl Wemo API dist)
- Create a simple test script to turn a switch on and off to make sure things are working OK
- Download the SMS server example at https://github.com/ericblue/Belkin-WeMo-Twilio-Server. The commands, your cell number, and the names of your switches should be changed.
- You can launch the server (launch.sh) or in debug mode. Going to http://your_internal_ip:9000/ should show a simple text welcome message.
[Twilio Setup]
- Go to Twilio.com and setup an account
- Register a new number and define the messaging request url as ‘http://your_public_ip:9000/sms/ and POST. Port 9000 is the default port, and should be mapped in your firewall from your public IP to internal IP of your SMS server.
- Send a text/SMS message to this computer ‘get devices’ and you should get a list of all Belkin Switches on your Network
[iPhone/Siri for Voice Control]
- See this article on setting up Siri for voice control – http://www.dummies.com/how-to/content/how-to-use-siri-for-texting.html
- Add your Twilio SMS server as a contact. I named mine ‘Computer’ (think Star Trek) , but you can name it whatever you want
- You’ll need to add a nickname or relationship/label as ‘Computer’ so when you hold down the button for Siri you can say ‘text Computer ’
my $valid_commands = {’1′ => ‘test’,’2′ => ‘get devices’,’3′ => ‘get commands’,’4′ => ‘turn all lights on’,’5′ => ‘turn all lights off’,’6′ => ‘turn upstairs lights on’,’7′ => ‘turn upstairs lights off’,’8′ => ‘turn downstairs lights on’,’9′ => ‘turn downstairs lights off’};
If you look at the sms_server.pl file you can see it’s a VERY simple and crude processor for some basic commands and translates words such as ‘upstairs’ and ‘downstairs’ to specific devices. This was created very quickly, so to customize you could modify to suit your needs or add something more sophisticated like a rule processor or XML-based config for mapping commands and devices.
That’s it! I hope you enjoyed this relatively simple hack and have fun!
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.