WeMo API Hacking

WeMo Hacking part two!

In short! It works! miranda, with some tweaks and fixes is a good tool for tinkering with your Belkin WeMo switch with Python. I'd suggest starting with my toolkit here: https://github.com/issackelly/wemo

The WeMo is communicating over pretty standard UPnP, though like anything else, it has some quirks.

It wanted a very specific namespace string for the SOAP envelope that contained a trailing slash and Miranda wasn't sending that.

I also added the same User-Agent that the mobile app uses for the HTTP (via UDP for UPnP) headers, and fixed the character encoding, and used consistent namespacing with the mobile app.

If you poke at Miranda you'll see that you should be able to figure out how to set schedules, and settings pragmatically through the SOAP interface, it's all there.

A simple session would go like this:

rivendell:~/P/p/wemo [master] 
$ ./miranda.py 
upnp> msearch

Entering discovery mode for 'upnp:rootdevice', Ctl+C to stop...

****************************************************************
SSDP reply message from 192.168.1.1:5431
XML file is located at http://192.168.1.1:5431/dyndev/uuid:0016-b639-af9e00408084
Device is running Custom/1.0 UPnP/1.0 Proc/Ver
****************************************************************

****************************************************************
SSDP reply message from 192.168.1.133:49153
XML file is located at http://192.168.1.133:49153/setup.xml
Device is running Linux/2.6.21, UPnP/1.0, Portable SDK for UPnP devices/1.6.6
****************************************************************

^CDiscover mode halted...

# You'll see that the first device found by miranda is my router, you can tell by the IP address, that leaves the other device as the WeMo
upnp> host get 1 

Requesting device and service info for 192.168.1.133:49153 (this could take a few seconds)...

Host data enumeration complete!

upnp> host send 1 controllee ### tab completion is very nice in miranda!
WiFiSetup        basicevent       firmwareupdate   metainfo         remoteaccess     rules            timesync         
upnp> host send 1 controllee basicevent GetSerialNo 

SOAP request failed with error code: 500 Internal Server Error
SOAP error message: Action Failed

upnp> host send 1 controllee basicevent GetBinaryState 

BinaryState : 1

upnp> host send 1 controllee basicevent SetBinaryState 

Required argument:
    Argument Name:  BinaryState
    Data Type:      Boolean
    Allowed Values: []
    Set BinaryState value to: 2


upnp> host send 1 controllee basicevent SetBinaryState

Required argument:
    Argument Name:  BinaryState
    Data Type:      Boolean
    Allowed Values: []
    Set BinaryState value to: 1


upnp> host send 1 controllee basicevent SetBinaryState

Required argument:
    Argument Name:  BinaryState
    Data Type:      Boolean
    Allowed Values: []
    Set BinaryState value to: 0

If you want to use my utility on top of miranda, it should work for you. No promises Get it from github: https://github.com/issackelly/wemo/zipball/master

Open a shell and locate the wemo directory

$ cd ~/Downloads/
$ unzip issackelly-wemo-1afe45d.zip
$ cd wemo
$ python
>>> from wemo import on, off, get
>>> on()
True
>>> get()
True
>>> off()
True
>>> get()
False

Read through wemo.py to get a better understanding of scripting miranda. (again, start with my miranda.py, as it's tailored to the WeMo)

If you'd like to buy a WeMo, I'd certainly appreciate you using my referral link:


Belkin WeMo Switch


I'm Issac Kelly. I like to build things, with software and hardware. By day I do that at Nonchalance in San Francisco. I like to teach people, but mostly about the things I'm interested in. I'm currently a mentor at Hackbright Academy. I'm building open source automation, albeit slowly at Plum Garage.


If you want to know when I write

If you want to know when I write, you should give me your email address, or if rss is your thing, subscribe