Zigbee with Python

Both Pimoroni and ThePiHut seem to have had a glut of smart home devices recently, which was an excuse for me to dip into trying to automate some things around the home. I’ve had some Ikea smart devices for a while, but the interactions between them were fairly basic without the app, and one thing I absolutely want to avoid is any kind of cloud functionality or reliance on commercial apps. There are just too many instances of those being discontinued or paywalled after a time.

Most guides for DIY networks use Home Assistant, but honestly I’ve no interest in that. I tried it once briefly and bounced off it, partly because I’m more interested in writing my own scripts to manage things, rather than having HA do it for me in a way which is quite opaque, and partly because I’m not willing to let it take over an entire device as the HA operating system is intended to do. I’ve spent some time recently figuring out alternatives, and I’ve finally written up a slightly long-winded guide on how I managed this using some of the Sonoff devices Pimoroni sells, plus some of the Ikea devices I already had. This is definitely one of those “easier once you know how” things.

Essentially, I’ve got a Raspberry Pi running zigbee2mqtt. Using either a Home Assistant ZBT-1 dongle or a Sonoff Zigbee Dongle Plus (both available at Pimoroni!), this can pair with devices, and receive data over the Zigbee wireless network. This data can be passed via MQTT to a Python script, which can then send instructions back to Zigbee devices via MQTT and Zigbee.

One of the nice things about this, and which I was a bit worried about initially, is that you don’t need to know anything about Zigbee or MQTT. The Python scripts are actually pretty straightforward and don’t need you to understand what Zigbee or MQTT are, really. I’ve had a script running on a Pi Zero W 2 for a while which controls a smart socket connected to a light and a USB charger, and now that I’ve got this working I’d like to start adding other things to it. In testing, I’ve had 4-5 environmental sensors plus buttons and a socket connected to the network and it all worked fine, but I want to write a wee web dashboard to display the data before I add the sensors back in again, as opening log files to get the data isn’t that user friendly.

In future I might look into how to link this with the newer Matter/Thread systems which seem to be the up-and-coming thing. I’d also really like to learn how to build custom Zibgee (or Matter/Thread) devices with microcontrollers, but unfortunately anything but the professional level software packages don’t seem to support this very well.

Anyway, I’m just linking this here in case anyone else was thinking about trying this; hopefully it’ll save you some time.

1 Like

Great, thanks for sharing. Until now I did not invest time in home automation, mainly because I don’t feel the need. But playing with the technology is certainly tempting for me. And your write-up will give me a head start.

The lead developer of CircuitPython was working on a thing he called “CircuitMatter”. Not sure about the status, I did not here a anything about the project recently. I think the ESP32C6 has builtin support and he worked on making it available to the (Circuit) Python world.

Yep, I’m honestly more interested in battery-powered sensors to try and make sure I’m heating my house properly rather than smart lights, sockets, and switches.

Thanks, I hadn’t heard of CircuitMatter. At a quick look, it supports the Matter message passing system, but not any particular radios. You might be able to use this with WiFi or bluetooth, but not Zigbee/Thread radios unless they add support for that later. I’ll have to keep an eye on it. The zigbee2mqtt folks were having a conversation about different Matter options, but again, I’m not sure yet where the Thread implementation comes from. I’ll keep looking for something.