Mike Szczys Takes Back Control of His Wemo Lightswitch with MQTT, Python and a Raspberry Pi

Sick of the proprietary software, Szczys took an afternoon to build a more flexible alternative using open source software.

Mike Szczys has published the code for a build which replaces the proprietary back-end of an Internet of Things (IoT) lighting control system with an open source alternative based on MQTT and Python running on a Raspberry Pi.

"Years ago I installed a [Belkin] Wemo Wi-Fi-enabled switch to automatically turn our porch light on at dusk and off at 11pm," Szczys writes. "It is controlled via the Wemo app which I always found a bit wonky and recently decided to take back control of this functionality. I have an MQTT broker running on a Raspberry Pi. To add the Wemo switch to the system I wrote a Python script that of basic functionality as well as scheduling to turn the light on and off automatically."

The system is designed around the Raspberry Pi, which runs an MQTT message broker and a Python script installed as a systemd service to load on system boot. An MQTT client script running on the Raspberry Pi listens out for broker messages to turn the light on and off or to report its current status, and can be controlled using an MQTT app running on an Android smartphone or tablet. Finally, a scheduler turns the light on and off at the required times.

Despite replicating the necessary functionality of Belkin's Wemo application, Szczys' build didn't take long: "It was fun throwing this together in an afternoon to learn a bit more about MQTT and it took me down the rabbit hole on Python libraries for scheduling and establishing sunrise and sunset times," he writes. "I don't really have any other devices in my house that are on the network, but now that I have an MQTT broker I might pick up a current sensing clamp to add washer/dryer cycle-complete notifier."

More details on the project, including threading in Python, tracking the time of local sunset, and installing and running MQTT on a Raspberry Pi, can be found on Szczys' Hackaday project log. The Python code, meanwhile, is available on his GitHub repository.

Gareth Halfacree
Freelance journalist, technical author, hacker, tinkerer, erstwhile sysadmin. For hire: freelance@halfacree.co.uk.
Latest articles
Sponsored articles
Related articles
Latest articles
Read more
Related articles