Some time ago I wrote about the Sonoff inexpensive Zigbee dongle and various Zigbee hubs etc. At the time I was experimenting with HA (Home Assistant) and a load of other new things and didn’t really give Zigbee the attention it deserved. In here I then came back to Zigbee with a vengeance, armed with the latest v3 Sonoff USB Zigbee dongle (which costs just a few €/£/$) and with Zigbee2MQTT on my RPi4 (out of the box). I’d originally left the dongle in a cupboard – so I yanked it out – and updated the firmware to the latest, not expecting a lot at first.

This time around I DO have actual uses for battery powered temperature sensors and a light sensor…. the wife won’t let me put wires in the bathroom and we have a heater in there which works on a simple timer (Spain has moved to 3 charging zones for electricity) regardless of whether it is needed or not. I also want the heater to come on only if the bathroom is cool. Finally I had a couple of cupboards sharing ONE supply and switch – can’t be having that.

Sonoff Zigbee Smart SwitchSonoff Zigbee Smart Switch

I should start by saying my knowledge of Zigbee is (was) very low – I found the zigbee2mqtt topics page really useful. I plugged in the Sonoff Zigbee dongle to my Raspberry Pi 4 (RPi4) and using Node-Red as my preferred platform to get MQTT access, checked out the dongle. It worked no problem but would not talk to the little Sonoff SNZB-02 temperature sensor (which simply reports temperature and humidity from time to time).

Well, it did but not reliably – or so I thought. It turns out there were three issues:

First and foremost there’s an issue that the RPi4 tends to interfere with Zigbee communications – I didn’t know this. Armed with that info, I put the Zigbee USB dongle on the end of a 2 metre USB extension lead – “problem one” sorted.

CR2450 Lithium BatteryCR2450 Lithium Battery

The battery in the SNZB-02 sensor was low – and also I was assuming fixed period reporting – wrong.

I sent off to Amazon for replacement 2450 Lithium batteries and inserted one into the SNZB-02. Partial success. The sensor now started responding – but not regularly – that’s when I twigged – the sensor reports when there is a change – not just for the sake of it – just breathing on it is enough to elicit a response. Now I was excited – but I’d already realised that Zigbee, like WiFi, has only limited range – and I remembered I had a Sonoff BASIC Zigbee device lying around. Some mains powered Zigbee devices like this, act as mesh nodes and can increase range. Problem sorted.

Now I was cooking…. from my Node-Red RPi4 installation I could read this horrendously-named temperature sensor and get reliable data. At that point, I took the time to read up on Zigbee and realised you can rename devices which I now do in all cases to give useful names. I’m quite happy using MQTT but I noted node-red-contrib-zigbee2mqtt and installed it in Node-Red. Why? Because it draws a pretty and very useful MAP which instantly increased my understanding of Zigbee and how to make life easy.

Zigbee MAP

Zigbee sensors

By now I’d added two more Sonoff sensors – a button and a window-sensor. Was this going to be another interesting but ultimately fruitless experiment?

Well, the map made it easy to remember which device is which so I could then easily rename and check devices. That helped a LOT.

As for Sonoff ZNB-01 buttons – here’s what you get in the payload once you have paired them with the “Zigbee coordinator” i.e. the dongle (5 seconds+ pressing the internal reset button):

action: “single”
battery: 100
linkquality: 117
voltage: 4100

“single” could also be “double” or “long” – the “long” message doesn’t appear for a while – I prefer the way the Aqara button does it with “hold” and “release” – but then – depending on postage and where you live, the Sonoff product might be the less expensive.

Next, I had a Lidl RGBW Zigbee lamp lying around from the FIRST time I attempted to use Zigbee – so I added this in – GREAT.

At that point I was dragged out of the house to go shopping. Back to Lidl – and would you believe it – they had some “Zigbee 3” hardware on special offer including a 3.6KW smart socket for a stunning €3.50 – could that be any good? Lidl Silvercrest smart plug is the official name and YES, it retains it’s power status on power cycling and yes it acts as a mesh repeater (router) – what a bargain (sadly they were all out of discount stock next time I went to the store – this was back in July 2021 – it is now mid-September and sadly, they’ve not had any Zigbee bargains since.

My test Lidl Zigbee lampMy test Lidl Zigbee lamp

The Lidl plug WORKS. The Ikea Zigbee hardware that I’ve tried, works with this arrangement as well.

I don’t know how clear the map above is to you, but you should be able to see the coordinator in RED and note that the Sonoff BASIC Zigbee and the Lidl light and plug are absolutely forming a mesh – I’ve no idea yet why the little contact sensor on the bottom right of the map has no “wires” connecting it (on the map) but trust me – it works. Also, if I temporarily unplug the BASIC controller, the network reconfigures itself – it is all working marvellously well.

Obviously, battery powered devices don’t act as range extenders – that would be daft. Some of my Zigbee devices are in my office but I have the Sonoff smart plug and temperature sensor in the bathroom through a doorway and two walls and I now have an AQARA temperature/humidity sensor upstairs in a bedroom – see the PART 2 blog entry which concentrates on Aqara Zigbee sensors and this entry in which I rave about the Aqara Zigbee battery powered, connection-freewall switches which are in constant use use controlling my office and living room RGBWW lights.

Zigbee Smart Plug and temperature sensor

In each case, simply long-pressing either a reset button or the control button (see bathroom smart-plug – manual on-off on the top – which also reports back any change of state) allowed the device to automatically be added into the network (you can turn that off in the gateway but for now I’m keeping things simple).

Node-Red has another contributed node set for Zigbee – I’ve noted it but at this time I’m happy using MQTT directly – worth looking at though.

I’m still getting to grips with updating the devices by OTA – it seems that none of my devices support OTA updates.


I’ve just now added a pair of Sonoff ZBMINI devices – simple. Here’s my flow page for the new Zigbee devices in Node-Red. At the top, the dongle – you can see on the status, the last thing it did was pair a device. Those ZBMINI devices have a pairing/toggle recessed button on the top – you can use that at any time as long as pairing is activated in the coordinator, There is also a pair of contacts (see grey connectors above) which act as a switch.

Right now the only device that is giving me any trouble is the Sonoff snzb-03 movement sensor – in that top node I can see any movement in the logs – but I can’t seem to read it in MQTT – of course it is entirely possible I’ve made a mistake somewhere.

Node-Red flow page for my Zigbee devices

For now I don’t yet know how to get any of these Zigbee devices to appear in Alexa. No doubt that’ll come.

And another link – one of the many useful compatible devices for Zigbee2MQTT – thanks to subscriber Gary for that.

Update June 9, 2021 – Livarnolux and ZBMini

Just hit my first snag – looking for feedback – already had some. You’ll note I’ve fitted a LIDL Livarno Lux RGB E27 lamp…. here’s the problem – I can turn it on and off via MQTT directly or using a little Sonoff Zigbee button… no problem… but… if I turn it OFF, then remove power to the lamp and re-apply – it always defaults to ON after applying power – unlike their PLUG as mentioned above.

Not sure what I’m supposed to see but when I remove power from the lamp – and turn it back on – I’m not seeing any debug data – in fact any data from the zig node or the lamp node… but as soon as power is re-applied, the lamp turns on instantly (then of course I can turn it on or off by MQTT – but I need it to retain it’s last state when power is cycled)… I do this all the time with Tasmota’d normal WiFi smart lamps…. so this is completely new to me.

It gets worse… My Sonoff ZBMINI-2 – on power up – THAT defaults to OFF. Again in the info I can get from the MQTT status (looking at the whole message) I’m seeing nothing about power up default states.

For these two items to have DIFFERENT power up default states seems ridiculous yet from feedback to date, it seems this kind of behaviour is not unusual in the world of Zigbee?

Update June 15, 2021 – Still using the Sonoff Zigbee Dongle but continuing to learn

Zigbee2mqtt (which I’m running on a Raspberry Pi) now has a UI (with light and dark modes – comes up in a browser on my PC). I added the following to my (Raspberry Pi 4 – based) /opt/zigbee2mqtt/data/configuration.yaml (text) file.. it creates a map, shows devices, allows some configuration.yaml alteration without getting your hands dirty…

new_api: true
port: 9099

Another possible addition to comms if needed (and it IS needed for the Electrolama dongle shown further down:

rtscts: false

And in a browser – in my case the local address of my RPi4… (that port can be changed). What other customisations specials do I yet have to discover…

Some Sonoff Links:

sonoff basic:
sonoff sensor:

I’ve just had a couple of Aqara buttons and an Aqara temperature sensor arrive, paired, renamed, working. Need to check range and of course battery life will take ages to determine.

Aqara sensorsAqara sensors

Zigbee temperature and humidity sensor

The tiny CR3032-powered Aqara Atmos temperature, humidity and pressure sensor SWDCGQ11LM came from Banggood – no mention of pressure anywhere – but trust me it’s in the array of items in the payload – see below.

battery, humidity, link quality, pressure, temperature, voltage

Good size, once it has been running for a while I’ll report back on battery life. I’ve also ordered more of these.

This page, for me is also very useful – devices compatible with Zigbee2mqtt.

Let me show you the state of my two zigbee-button-and-NR-dashboard-controlled cupboard lights as of Jun 14, 2021. I gave up on Zigbee lights as the only one I had spare was full RGB (a waste for a cupboard) and defaults to ON – how dumb is THAT.

So, first things first, I put a couple of Sonoff ZB-MINI controllers behind one of the light fittings and a couple of Aqara buttons (Original Aqara Smart Wireless Switch) from Banggood on the wall (these buttons are supposed to work only with the Aquara multi-functional hub but are working just fine with Zigbee2MQTT. Then there was the problem of how to achieve local control by EITHER the button OR my phone (so I could turn off the lights in bed (or at a distance (using NR Dashboard on my phone) when reminded I’d left them on).

If you look at the code below, you could be forgiven for asking why the delay nodes – well, all I can say is without them I was getting unreliability in state control. It could also be that I cloned the gloryhole node to the washroom without resetting node-Red – that’s been known to cause problems in the past. Anyway, here goes…

The light blue nodes above are NR-Dashboard buttons. The purple nodes are MQTT (in and out), the ORANGE nodes are Zigbee nodes (I could have used MQTT just as easily) and the light-brown nodes are Node-Red function nodes. Sticking with the washroom (the two sets are virtually identical) – firstly the function node on the button input – I entered …

if (”single”)
return msg;

Then the function node after the incoming MQTT status of the ZB-MINI…

node.status({fill:”blue”,shape:”dot”,text: “Washroom ” + msg.payload.state + global.get(“handyDate”)});
msg.payload.myIcon=”fa-power-off fa-3x”;
if (msg.payload.state==”ON”) msg.payload.back=”green”;
else if (msg.payload.state==”OFF”) msg.payload.back=”black”;
return msg;

And the function node on the output of the ZB-MINI node…

if (flow.get(“bathroom”)==”OFF”) msg.payload={“state”:”ON”};
else if (flow.get(“bathroom”)==”ON”) msg.payload={“state”:”OFF”};
node.status({fill:”blue”,shape:”dot”,text: msg.payload + global.get(“handyDate”)});
return msg;

Node-Red properties dialog

Finally the settings in the washroom NR button node. I hope this is useful to anyone playing with Zigbee,

As you can see instead of a fixed icon, I’m programming that in (didn’t need to in this case) as with the background colour – green for ON, black for OFF.

This happens regardless of whether the light is controlled by NR Dashboard or the Zigbee button.

After many weeks, all seems to be working well. If you’ve only ever used msg.topic and msg.payload in the past this might be a worthwhile eye-opener.

It’s also kind of handy having the ZB-MINIs working in a central location as they act as mesh repeaters (routers?)

Two new buttons

End result? Two new buttons on my phone… the two bottom ones – light up when ON – see the bottom left button on the photo on the left.

There is a bed showing on the bathroom radiator button (left) because the radiator does not operate in summer months.

Update June 20, 2021 – Even more new stuff:

All of the above is running smoothly and that gave me a little time to get experimental with Node-Red on my RPi4. SO, as I’m interested in both temperature and humidity, I store both in a Node-RED global variable along with an efficient timestamp so I also know WHEN, say, the little Aqara sensor last returned a reading.

Timestamps are efficient but of course not very human-readable so I’ve been using a date-formatting function in Node-Red every time I want to see a temperature reading. After a while that got to be cumbersome and this morning, though very familiar with Node-Red global variables, I figured it was about time I got to grips with initialising and using global FUNCTIONS.

Initialising and using a Node-Red global function on a global object

What you see above is firstly a simple initialisation of my new global date-handling function I keep in my first Node-Red flow called INIT. Secondly you see a typical example of use – showing the time the last reading was returned, NOT the time I used that INJECT node which in both cases is merely used as a trigger. The global object used here called bedroom-environment contains temperature and humidity as well as a timestamp stored when the sensor last returned data. = function(x) {
var hour = x.getHours();
hour = (hour < 10 ? “0” : “”) + hour;

var min = x.getMinutes();
min = (min < 10 ? “0” : “”) + min;

var sec = x.getSeconds();
sec = (sec < 10 ? “0” : “”) + sec;

var year = x.getFullYear();

var month = x.getMonth() + 1;
month = (month < 10 ? “0” : “”) + month;

var day = x.getDate();
day = (day < 10 ? “0” : “”) + day;

var weekday = new Array(7);
weekday[0] = “Sunday”;
weekday[1] = “Monday”;
weekday[2] = “Tuesday”;
weekday[3] = “Wednesday”;
weekday[4] = “Thursday”;
weekday[5] = “Friday”;
weekday[6] = “Saturday”;

return(“handyDate”,” at ” + hour + “:” + min + “:” + sec + ” on ” + day + “/” + month + “/” + year);

node.status({fill:”red”,shape:”dot”,text:global.get(“bedroom-environment.temperature”)+”xb0C and ” + global.get(“bedroom-environment.humidity”) + “%” +“bedroom-environment.when”)) });

Update June 21, 2021 – ElectroLama ZZH enters the picture

Electrolama ZZH

I received an Electrolama ZZH Zigbee dongle a little while ago (that’s the USB dongle+antenna, not the bsae, in the leftmost photo) but no matter what I did, I could not get it to work – unlike the Itead unit, the Electrolama unit does not come pre-programmed – and somehow I managed at first to put in the ROUTER firmware instead of the COORDINATOR firmware – all of this is detailed on the Electrolama site – you should take a look at their documentation. Here’s a specific Electrolama link concerning zigbee2mqtt

It turns out that once I got over that issue, it was not because of an issue with the ZZH that it would not work for me – ElectroLama have been more than helpful, but my Itead dongle was using /dev/ACM0 and the ZZH wanted /dev/USB0. See the zigbee2mqtt link

Then I discovered that Zigbee itself, If you have an existing setup and change the coordinator, insists you make sure that any routers (repeaters – mains-powered Zigbee devices) are disconnected while first starting up the new coordinator – and the whole lot needs re-pairing (generally long-press) to the new coordinator.

Thankfully I’ve found that I did NOT need to mess with the configuration file, other than changing the port from /dev/ACM0 to /dev/USB0 for reasons beyond me (same actual connector) – and because of the change of coordinator – I had to add an ADVANCED entry into the configuration.yaml file – one-liner – forcing a “pan_id” address to avoid conflict even though the Itead unit was no longer connected … hopefully readers would not hit this issue – but I have to say that Electrolama were very helpful with me (as a Zigbee newbie). Also notice that the advanced section option in configuration.yaml which I showed earlier:

rtscts: false

is essential for the ZZH.

Why go to the bother of using Electrolama’s product? Well, the chip that Sonoff use (it seems) in their dongle has a tendency to be awkward once you get over 20 devices – wisdom out there says that the more powerful chip used in the ZZH doesn’t suffer from this problem – and their dongle also has an external antenna as against a PCB antenna so should have more range.

Update June 30, 2021 – Xiaomi Mijia Smart Light Sensor

This Zigbee 3.0 sensor works well – part number GZCGQ01LM “for the Xiaomi Smart Multimode Gateway” – but more importantly in this case, compatible with Zigbee2MQTT – watch… despite the rather large box – the unit is in fact quite small and neat and comes complete with adhesive fastner. Even though the manual was in Chinese – it wasn’t needed as the device is self-explanatory – the MQTT payload shows what it does – lux level – battery state, signal quality.

battery: 100
illuminance: 19868
illuminance_lux: 97
linkquality: 156
voltage: 3200

Mijia light sensor

The two “illuminance” figures vary according to light level – and there is pairing and quick test button on the top of the unit. Banggood sell this unit though I didn’t notice reference to that part number. Meanwhile my experiments with an AliExpress-supplied light sensor have gotten me no-where so I’m really pleased about the Mijia unit (I need a sensor to detect sunlight levels for internal lighting to supplement my timers which can’t account for a cloudy, miserable day).

Update June 21, 2021 – Tuya Zigbee Mains Controller

Ok, here’s one for you: I just received a 1CH Zigbee Switch Module from TomTop. The module shown on the left supposedly controls a mains load of up to 10A. This is reminiscent of similar looking WiFi products by the likes of Blitzwolf – and on the top, just out of sight is the usual Zigbee long-press reset button. In the front (see photo) is a terminal for a switch – wire that to live and the load turns on – release, the load turns off.

I’m concerned as I’m not sure what the “Max load: LED 250W 10A” is all about – should that not be nearer (non-inductive) 1KW at 100v or 2KW at 220v? If not, why state 10A? 250W makes no sense at all.

It’s a nice looking module with a wall mounting clip-on bracket, it paired to my Zigbee2MQTT setup no problem and the output includes “state” and “Linkquality” – all standard stuff. It seems that the switch option and Zigbee control work in harmony but I was concerned that despite the accompanying sheet stating that “the last adjustment remains in memory”, the unit, when left in the OFF state, reverts to ON in the case of power cycling (just like the Lidl Livarnolux lamp – not a lot of use if you are out of the country and there’s a power failure)., unlike the Lidl Silvercrest Smart Plug mentioned higher up which retains it’s state on power cycling. And right now it is squeezed minus the bracket into a lamp shade to give me (a) control over a living room lamp and (b) another mesh node – always handy with Zigbee. Very handy as it is so small.

Update July 5, 2021 – Zigbee2MQTT – a New Software Upgrade

See bottom of THIS page for details – save it in favourites if interested. I know I have..

Update July 21 – the Xiaomi Multimode Zigbee 3.0 WiFi Bluetooth Mesh

Xiaomi Multimode Zigbee 3.0

I just recently received the Xiaomi Unit and have not yet had a chance to give it a hammering but here it is anyway – direct from Banggood. Even with VAT and postage it is still well under €30 for anyone who wants a boxed product that would look fine on a coffee table (my ZZH wouldn’t).

The brand is Xiaomi MIJIA and the device is a smart gateway handling Zigbee, WiFi, Bluetooth and Bluetooth Mesh – and in one neat round unit. For more on this unit right now, I suggest checking out the above Bangood link – I think it’s on offer right now.

Update August 9, 2021 – Zigbee2MQTT Updated

Zigbee2MQTT release 1.21.0 came out a few days ago and thanks to the excellent design, it turns out I already have an file in the /opt/zigbee2mqtt folder – so I just ran that and a few moments later – all was done – for good measure I rebooted the Raspberry Pi. All working fine, using the little ZZH dongle referred to earlier.

Update December 23, 2021 – The Native Zigbee2MQTT Map

I keep going back to find out more about ZIGBEE and now I’m back temporarily in the UK, I’ve made a new Zigbee set-up for here – I’ve noticed that the map in the Zigbee2MQTT interface on (default) port 9099 is in itself useful and is part of a web page menu with lots of setup and controls for a Zigbee installation as well as device updates where available (most devices I’ve come across up to now do not seem to support updates). The map makes it very clear which devices are being used as repeaters and to which non-repeater devices they connect. In the image below however, I’m at a loss as to why the two items on the left appear to be on their own and why the unsupported device (Z) remains on the net. The device with the big blue star is in fact the Sonoff inexpensive Zigbee dongle acting a main router. Not sure why that doesn’t get named.

TVOC is an AQARA device, the Smart socket is Sonoff as is the newzbmini-1.

Beware that Zigbee updates take several minutes because of the low data rate. Just tonight, I downloaded the latest update (November 2021) for the Tradfr1 repeater (to 2.3.086) but could not find any update for the Ikea button – actually looking at the Ikea site, for reasons beyond me it seems that exact button (rectangular with 0 and 1 engravings on the top and bottom halves) is no longer available despite working well.