ouimeaux 0.5.1 released: Fuzzy device matching, bug fixes

Several new features making it easier to use, as well as a lot of bug fixes. Full list here. Included:

  • wemo status/wemo switch status : Prints the current on/off status of all switches or specific switches in your environment.
  • Fuzzy device name matching: You can now use fuzzy matching on the command line so you don't have to preconfigure aliases. For example, wemo switch tvrm on will work as well as wemo switch "TV Room" on .
The command-line help is also much more complete. Check it out!
ouimeaux on GitHub
ouimeaux on PyPI


ouimeaux 0.3 released: Device Caching, Aliases, Configuration Options and More

In response to a couple of tickets, I've released ouimeaux 0.3. It includes some bug fixes and a few nice features:

Device Cache

Discovery results are now cached on the filesystem, so command-line operations will be much faster to initialize. The cache can be disabled with the --no-cache option.


Some device names are long or contain spaces, which makes using them on the command line unwieldy. You can now define aliases that make that easier to deal with. For example, you can alias "TV Room" to "tv" allowing you to run wemo switch tv on.

Discovery Response Server Binding

The UDP server that listens for responses to the UPnP broadcast can now be configured to bind to a specific IP and port.

Config File

You can configure all of the above by modifying ~/.wemo/config.yml. It's fairly self-explanatory.

Toggle command

Tiny feature: You can now pass "toggle" as well as "on" or "off" as a wemo switch command.

pip install or fork at will, and let me know how it goes.




ouimeaux 0.2 released: Now with Motion events!

Finally had a chance to fire up Wireshark and figure out how WeMo Motions and Switches talk to each other. I've worked the results of my discovery into ouimeaux 0.2. Now you can register callbacks to be notified whenever a Motion or Switch changes state (i.e., when motion is detected or a switch is switched). I also cleaned up a few bugs with the UDP server, so you should be able to discover periodically now without it throwing an error.



Controlling Belkin WeMo switch with a Raspberry Pi

Here's a simple example of a way to use the ouimeaux library. The RPi's running a server that discovers a WeMo switch by name (specified on the command line), then essentially forwards switch input from the GPIO pin to the WeMo. With a power supply circuit to let it run off 110 AC and a nicer switch, you could mount this in the wall to control your WeMo a little quicker than pulling out your phone, for those cases when you're already in the room. Said my sister: "Congratulations, you've reinvented the light switch."

The switch circuit is the simplest possible; example circuitry and code can be found here.


ouimeaux: Command line and Python API for WeMo hacking

I bought a bunch of Belkin WeMo Switches over Christmas, and while I appreciate that my lights now have IP addresses, controlling them can really only be done through the WeMo iPhone app, which (besides having a few understandable bugs) is slow to start up. More to the point, I had no way to hook the switches up to any other events beyond using IFTTT, which seems to have a one-switch limit.

Luckily, WeMo devices appear to provide a fairly complete SOAP API. Isaac Kelly posted a proof of concept discovering and controlling switches, so obviously more direct control was possible. Hacking together a decent library only took a couple of nights.

Thus: ouimeaux. It uses gevent for async I/O and the minimal UPnP functionality required (broadcasting M-SEARCH requests, listening for responses), and it uses requests to communicate directly with the devices. Service stubs are built on the fly and provide easy attribute access to actions (for example, switch.basicevent.SetBinaryState(BinaryState=1)). There's also a handy explain() method to print out all services, actions and arguments. The only useful things I had time to figure out how to do—turn switches on and off, get current switch state—I pulled up into methods on the switch object itself: switch.on(), switch.off(), switch.get_state(). The documentation gives more details.

Once that was written, a simple command line script was straightforward. Installing the package will get you the wemo script in your PATH. wemo list to discover names of devices, wemo switch "Switch Name" on to turn it on. Nothing else so far, but it's highly hackable.

I hope to explore the Motion API next, and provide the ability to listen to events from Motion devices. Firmware uploading is exposed too; might be possible to intercept and modify to get an SSH server running.


pyxdeco: Python eXtraordinary Decorators

Decorators in Python are limited to action when the function they wrap is actually called. Which is fine and all, but they can be more useful. Or at least could be, if they allowed for hooks at definition or instance creation. I've packaged up a technique I've been using to do just that and released it as pyxdeco.

I wrote the code when trying to register instance methods as event listeners automatically when the instance was created. Decorator syntax made the most sense by far:

def click_listener(self):
...but Python decorators can't be used that way, since the decorator wouldn't be invoked until click_listener was actually called.

This package adds the ability to define decorators to be called at any of the three points of the function's existence: when the function is defined, when an instance of the class containing the function is created, and when the function is itself called (the last is of course not new, just a regular decorator, but is provided for consistency and completeness).

Code is on github, downloads available from pypi. Suggestions for examples or future development welcome.


Decorator Factories (and decorator factory factories)

Decorators are a simple, handy way of implementing certain features in any language, but many people find them perplexing. When you start talking about functions that generate decorators, it gets a little twisty; when you then make helpful functions to create functions that create decorators, you might have to stop for a minute to unclench your brain. Really, though, the concept is quite simple if you take it step by step, so here it is (after the jump), hopefully demystified.