Home Automation with Belkin Wemo, Twilio, and Siri

Home Automation with Belkin Wemo, Twilio, and Siri

Ultimate Hack Mashup – Belkin Wemo + Twilio + Siri


A quick note: For another home automation trick and those interested in finding out about the earlier Twillio callbox+TV popup/notification hack check out STEM (https://github.com/ericblue/STEM).  Certain models of Samsung TVs allow popups for incoming phone calls for Samsung phones, but this can be extended to support any situation through the API.

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 is overdue, but a hack worth sharing, so I’ve uploaded to GitHub and have basic instructions so others can put this to good use.  This example uses the Belkin Wemo power switches, my Perl API (WebService::Belkin::WeMo) for controlling them, the Twilio cloud-based API for sending and processing text messages, 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 goto 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]

  1. 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.
  2. 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.
  3. 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)
  4. Create a simple test script to turn a switch on and off to make sure things are working OK
  5. 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.
  6. 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]

  1. Go to http://twilio.com and setup an account (Note: this is NOT free, but the cost is minimal for sending/receiving calls and texts)
  2. 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.
  3. 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]

  1. See this article on setting up Siri for voice control – http://www.dummies.com/how-to/content/how-to-use-siri-for-texting.html
  2. Add your Twilio SMS server as a contact.  I named mine ‘Computer’ (think Star Trek :), but you can name it whatever you want
  3. 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 <say command here>’

Example commands:

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!

(Visited 2,947 times, 1 visits today)

2 Responses

  1. […] 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 […]

  2. oh hey eric thanks for the reference, perl is for masochists, even someone who is not even 1.1% dev knows that! 😀 <3

    thank you for your support and patronage in my time of need!

Leave a Reply

Your email address will not be published. Required fields are marked *