Skip to main content

Python API to Belkin WeMo devices

Project description

ouimeaux is a Python interface to Belkin WeMo devices. It uses gevent for async I/O and requests for communication with the devices. It also provides a minimal command-line interface for discovery and switch toggling.

Python API


The main interface is presented by an Environment, which optionally accepts functions called when a Switch or Motion device is identified:

>>> from ouimeaux.environment import Environment
>>> def on_switch(switch):
...     print "Switch found!",
>>> def on_motion(motion):
...     print "Motion found!", switch.motion
>>> env = Environment(on_switch, on_motion)

Discovery of all WeMo devices in an environment is then straightforward; simply pass the length of time (in seconds) you want discovery to run:

Switch found! Living Room

During that time, the Environment will continually broadcast search requests and parse responses. At any point, you can see the names of discovered devices:

>>> env.list_switches()
['Living Room', 'TV Room', 'Front Closet']
>>> env.list_motions()
['Front Hallway']

Devices can be retrieved by using get_switch and get_motion methods:

>>> switch = env.get_switch('TV Room')
>>> switch
<WeMo Switch "TV Room">


All devices have an explain() method, which will print out a list of all available services, as well as the actions and arguments to those actions on each service:

>>> switch.explain()

  SetServerEnvironment(ServerEnvironmentType, TurnServerEnvironment, ServerEnvironment)

Services and actions are available via simple attribute access. Calling actions returns a dictionary of return values:

>>> switch.basicevent.SetBinaryState(BinaryState=0)
{'BinaryState': 0}


By default, ouimeaux subscribes to property change events on discovered devices (this can be disabled by passing with_subscribers=False to the Environment constructor). You can register callbacks that will be called when switches and motions change state (on/off, or motion detected):

>>> def on_motion(value):
...     print "Motion detected!"
>>> env.get_motion('Front Hallway').register_listeners(on_motion)
>>> env.wait()

Note the use of Environment.wait() to give control to the event loop for events to be detected.


Switches have three shortcut methods defined: get_state, on and off.


Motions have one shortcut method defined: get_state.

Command Line

The wemo script will discover devices in your environment and turn switches on and off. To list devices:

$ wemo list

Default is to search for 5 seconds; you can pass --timeout to change that.

To turn a switch on and off, you first have to know the name. Then:

$ wemo switch "TV Room" on
$ wemo switch "TV Room" off



ouimeaux requires gevent version 1.0rc2 or higher. If you don’t have the ability to compile gevent and greenlet (a sub-dependency) locally, you can find and download the binary installers for these packages here:

ouimeaux also requires use of UPnP to discover your WeMo devices. You might run into a port conflict since Windows has its own UPnP service that uses port 1900. You can work around this by disabling the “SSDP Discovery” service through the Control Panel.


Release 0.2 (April 21, 2013)

  • Fixed #1: Added ability to subscribe to motion and switch state change events.
  • Added Windows installation details to README (patch by brianpeiris)
  • Cleaned up UDP server lifecycle so rediscovery doesn’t try to start it back up.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for ouimeaux, version 0.2
Filename, size File type Python version Upload date Hashes
Filename, size ouimeaux-0.2.tar.gz (26.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page