Pulling on a Thread

Ben's Place ·

6 min read Original article ↗

I’ve had a couple of IKEA ALPSTUGA CO2 sensors for a while now. They been running, one in my office and on in the bedroom, so I can keep an eye on the levels both while working and before sleeping.

They are part of IKEA’s second generation of smart devices, so they have Thread radios rather than Zigbee, which means that they can’t be used with either the old IKEA Trådfri Hub or with Zigbee2MQTT.

When Trådfri Hub shipped I got one and had a play at reverse engineering access which wasn’t too hard as it was basically a COAP server.

I will use the Trådfri Hub for a few lights that I have linked to Google Home but I also have a Zigbee2MQTT instance that I use with the older IKEA VINDSTYRKA Air Quality Sensors and some Movement sensors feeding into Node-RED.

Threading the Needle

Thread is a system that uses 6LoWPAN to run a IPv6 network over low power radios, which means that with a bridge device to link to the WiFi/Ethernet network devices on both networks can talk to each other. These are known as Thread Border Routers

A bunch of IoT hub devices come with Thread Border Routers built in e.g.

  • Google TV Streamer
  • Nest Hub (Gen2)
  • Amazon Echo (Gen 4)
  • Amazon Echo Dot (2026)
  • IKEA DIRIGERA

Unfortunately all my current kit is a little too old, so I had to find something else.

Thread is an open standard and there is an OpenSource implementation from Google called OpenThread. This can run on a pair of ESP32 boards (one with the WiFi radio and one with a Thread radio). You can buy development boards with both pre-mounted and there are instructions to build and deploy that. I got hold of one of these boards a little while ago and managed to build software, but at the time I didn’t 100% understand how the various parts went together so left it sat on a shelf for a while.

Then I was watching something on YouTube about “random” adaptors and one of the things in the list was a device from a company called Smlight. It was basically a repackaged version of the dev board, but with PoE Ethernet, USB, WiFi and Bluetooth all in one package. These also do versions with multiple Thread/Zigbee radios. The firmware supports OpenThread Border Router as well as Zigbee2MQTT.

I grabbed one of the SLZB-06MU devices for now rather than the multi-radio version. You can pick which firmware to install from it’s web interface and it just reboots into the mode you need.

A Matter of Time

Sam Machin (@sammachin@chaos.social) has created a Matter Controller Node-RED node (@sammachin/node-red-matter-controller) which can be used to commission devices, but out of the box it only supports devices already on the accessible via the LAN. But it is built on the Matter.JS framework which includes Bluetooth commissioning support.

I decided to have a go at seeing if I could add support and it turned out to be not that hard.

I’ve opened a Pull Request on GitHub to add the support. At the moment you need to manually set the Thread Network Name and the TLVs (This is a hex encoded version of all the crypto keys and channel information needed to join the Thread network) under the controller config node. For now both of these can be grabbed from the OTBR web interface but long term all of this should be discoverable via mDNS and some API calls on the OTBR, but that might come later.

It does require the device you are commissioning to be in range of the Bluetooth radio in the machine running Node-RED, which might not always be the case, but I managed to commission both the Office device which is in the same room as the Pi and the Bedroom sensor which is the other side of the house. There are “long range” Bluetooth adaptors available these days. Also the Smlight device also has some support for being a “remote” Bluetooth radio, Home Assistant has some support for this, but I’ve yet to dig into how it works.

To access the Bluetooth controller on Linux does require some elevated permissions, so rather than running Node-RED as root (which is not really a good idea) I granted the node binary just the permissions it needed.

$ sudo setcap cap_net_raw+eip $(eval readlink -f `which node`)

This finds the node binary and sets the cap_net_raw permission.

Though I did run into a snag that the Pi I run my Smart Home Node-RED instance on wasn’t automatically adding the advertised route from the Thread Bridge, so it couldn’t reach devices on the Thread network. Manually adding the route fixed things.

To commission the device you copy the pairing code from the bottom of the device and use a Inject node to pass this to the Device Manager node, if all goes well after a few moments it will spit out a message confirming that commissioning has completed and the device will be available in the other nodes.

I added two Subscribe nodes, one for each sensor, and have fed them into my Node-RED Dashboard view.

Spinning the Next Yarn

Now I’ve got a feed of the CO2 levels I’ve started to feed them into InfluxDB so I have a record and I’ll look at setting alerts when levels get too high or may be even automatically starting some fans to help clear out stuffy rooms.

I’ve also order a couple more IKEA sensors as they are stupidly cheap

  • Door/Window open sensor £7
  • Water Leak sensor £7

I already have one of the previous Zigbee Door/Window sensors, but the battery life is really poor at about 4-5 weeks per AAA battery. The new one looks to be the same form factor, so it will be nice to compare the battery life.

The Smlight device has crashed a few times while I’ve been playing, so I’ve submitted the crash dumps and upgraded to the latest firmware, I’ll keep an eye on it.

Given the Smlight device can also be used as a Zigbee2MQTT input, I’m tempted to see if I can get the firmware to run on the dev board. This would mean I could move Zigbee2MQTT off the old 32bit only Pi to a container running in my Kube cluster. Recent builds of Zigbee2MQTT have gone 64bit only so I’m stuck on an old version because of the old Pi.