Close

Wemo control in Python

A project log for MQTT Porchlight is an Intranet of Thing

Controlling a Wemo light switch with MQTT and Raspberry Pi

mike-szczysMike Szczys 12/09/2019 at 20:170 Comments

First thing's first, I set out to see if there were any packages available to control a Wemo switch from inside the LAN. There are indeed as on the local network the system uses UPNP/Rest for control.

There are tons of libraries for this across different languages. I ended up using the pywemo library:

https://github.com/pavoni/pywemo

It's easy to install with pip: 

pip3 install pywemo

And basic control is just a few lines:

>>> import pywemo
>>> devices = pywemo.discover_devices()
>>> print(devices)
[<WeMo LightSwitch "Crabapple">]
>>> devices[0].get_state()
0
>>> devices[0].toggle()
>>> devices[0].get_state()
1
>>> 

Discussions