Home Home Automation Adding Sonoff sensors in Zigbee2MQTT and other systems

Adding Sonoff sensors in Zigbee2MQTT and other systems

What ecosystems Sonoff sensors are compatible with?

Sonoff ZigBee Sensors (review) aren’t the only ones working with Sonoff ZigBee Bridge (review). Waiting for ITEAD sensors to arrive I tried Tuya Zigbee sensors (review), IKEA Tradfri and Xiaomi MiHome ones. It turned out that a couple of Tuya sensors worked with Sonoff ZigBee bridge and I got my preview early. Now, that I have Sonoff ZigBee sensors at hand, would they work with anything else? Will the new 1.1 firmware for Sonoff ZigBee Bridge expands its compatibility? And obviously, we shall see Sonoff sensors in Zigbee2MQTT.

Tuya/Smart Life app

To my surprise, some of the Sonoff ZigBee sensors do work with Tuya and Smart Life app. You can show around and pick and match the sensors at will. I had no problems pairing and using:

In fact, I liked the interface better. The Tuya app has pleasant to eye interface, polished animations and easy to use notifications. The temperature & humidity sensor comes with a graph that you can limit by day|week|month. I would love to see this level of polish in eWeLink app. I was even able to pair the Soonoff Basic Zigbee R3 (review) and S31 ZigBee smart socket. Unfortunately, there is one problematic sensor:

The button is recognized by Tuya hub but as 3 gang switch. It kinda makes sense since the ZigBee button has 3 actions, but these are contacts, not toggles. The button doesn’t work.

Xiaomi MiHome & IKEA Tradfri

Despite my best attempts, I was not able to pair any of the Sonoff ZigBee sensors. I tried to add them as MiHome branded sensors and as Aqara revisions. No luck. Looks like Xiaomi is using another standard for their devices. It’s a good thing that Xiaomi stuff works well with CC2531.

It was a long shot, but since I already have the hub, why not? To the surprise of no one, nothing would work, not even PIR sensor. It also confirmed my initial thoughts that IKEA Tradfri has a long way to go to be more robust and useful. I love the hardware, just not the software.

There was one more reason why I took the IKEA Tradfri hub out of the cupboard. I wanted to update the firmware on my IKEA sensors and see how they play. I read about some issues, so it would be good to have a 1st hand experience. Perhaps updated IKEA sensors will become compatible with other solutions. That’s a subject for another article.

Sonoff sensors in Zigbee2MQTT

I would be VERY surprised if Sonoff ZigBee sensors in Zigbee2MQTT caused any problems. Up until now, CC2531 flashed with Zigbee2MQTT was capable of running everything I throw at it. You can read a detailed guide of how to add compatible devices, and how to create custom drivers for devices that are not yet (officially) supported.

For reference, I used a brand new CC2531 from ITEAD flashed with Z-stack 1.2 by them, and my original ZigBee stick with older firmware:

//ITEAD CC2531
{"type": "zStack12",
    "meta": { "transportrev": 2,
               "product": 0,
               "majorrel": 2,
               "minorrel": 6,
               "maintrel": 3,
               "revision": 20180507}
}

//Latest cc2531 firmware
{"type": "zStack12",
    "meta": { "transportrev": 2,
              "product": 0,
              "majorrel": 2,
              "minorrel": 6,
              "maintrel": 3,
              "revision": 20190608}
}

//My CC2531
{"type":"zStack12",
    "meta": { "transportrev":2,
              "product":0,
              "majorrel":2,
              "minorrel":6,
              "maintrel":3,
              "revision":20190425}
}

The new firmware zStack12 - 20180507 and 20190608worked flawlessly, but the other firmware revision struggled with the motion and contact sensors. The button and the temperature sensors worked just fine. If you are stuck on revision 20190425 – just follow this flashing guide.

Buy USB Zigbee Stick CC2531

Buy it using these links to support NotEnoughTech.

Neither pairing nor using Sonoff ZigBee sensors in Zigbee2MQTT was problematic. All 4 sensors were correctly identified by my server and I was able to read the updates right away. I’m pleased to see that battery reporting is done well too. I have a profile that automatically identifies ZigBee devices and tracks the battery levels for all of them.

These are identified as:

NAMEModel IDZ2MQTT ID
eWeLink Wireless buttonRHK07WB01
eWeLink Temperature and humidity sensorRHK08TH01
eWeLink Motion sensorRHK09MS01
eWeLink Contact sensorRHK06DS01

You can use Zigbee2MQTT topics to monitor the log and to query all devices. It helps to rename things and keep track of what’s added without leaving NodeRED. To get the log output, subscribe to zigbee2mqtt/bridge/log. And if you want to get the information about the devices paired, send an empty payload to zigbee2mqtt/bridge/config/devices/getand the devices will be sent to the topic: zigbee2mqtt/bridge/config/devices .

Sonoff sensors

Zigbee2MQTT recognised all three actions and these are available as single|double|long. Unlike IKEA dimmers, there are no press down|press up actions, so you can’t create actions based on the duration of the hold-down event. Three actions are still plenty to go around and you can use this to turn the button into a dimmer.

It’s worth noting that the long press must last 3 seconds and will be automatically issued before the button is released. The payload isn’t issued button release. The whole message has this format:

{
"battery": 100,
"voltage": 4100,
"linkquality": 60,
"action": "single"   //other possible values: double|long
}

It reports the temperature and humidity in ℃ and % respectively. The update can be forced by pressing the button, otherwise, the sensor will report in pre-programmed instalments (10 sec).

{
"temperature": 22.82,
"linkquality": 118,
"humidity": 51.91,
"battery": 80,
"voltage": 2900
}

If you are on the other side of the pond and you want the values in ℉ or be super scientific, you can use the following formulas to recalculate the temperature values:

//Temp in F
function imperialWeirdos(temp){
  let tempF = Math.round((temp * 9/5) + 32);
  return tempF;
}
//temp in K
function scienceFanatics(temp){
  let tempK = Math.round(temp + 273.15);
  return tempK;
}
//sorry I could not resist!
var tempC = msg.payload.temperature;
var humidity = msg.payload.humidity;

msg.temperature = { "temp_C": tempC,
                    "temp_F": imperialWeirdos(tempC),
                    "temp_K": scienceFanatics(tempC),
                    "humidity": humidity
};
return msg;

While the sensor works as intended, we are still limited to a default timeout of 150 seconds. I wrote a great article about improving IKEA Tradfri PIR sensor, which you can use to take the PIR a step further.

{
"occupancy": true,
"tamper": false,
"battery_low": false,
"linkquality": 131,
"battery": 80,
"voltage": 2900
}

The last of the bunch is the contact sensor. Works as intended and returns true|false on contact. There is tamper prevention message as well but the sensor is not equipped with anything that would let ZigBee2MQTT know that the sensor had been tampered with. It takes less than a second to post the result over back to the server. If you come up with creative ways of using these – let me know.

{
"contact": false,
"tamper": false,
"battery_low": false,
"linkquality": 120,
"battery": 100,
"voltage": 3000
}

Buy Sonoff Zigbee Sensors

Buy it using these links to support NotEnoughTech.

Final thoughts

Sonoff ZigBee sensors in Zigbee2MQTT are easy to use. The extra battery capacity will go a long way. I read online that some people don’t like the design of the shell. If the long battery life and the fact that most of the sensors (apart from buttons) are tucked away aren’t enough of consolidation for you, perhaps 3D printing could be a solution. I may try it myself as I get better at designing enclosures – just look at thins Argon18 mod for Argon One case (review). Will you use Sonoff ZigBee sensors in Zigbee2MQTT? Let me know in this Reddit thread.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated in style with crypto-currency

Smart Ideas with

Automate your space in with these ecosystems and integrate it with other automation services

Learn NodeRED

NodeRED for beginners: 1. Why do you need a NodeRED server?

0
To server or not to server? That's a very silly question!

Best Automation Projects

ESP8266 WIFI lights under $5

0
Your Sonoff device can't do this!

Free wireless doorbell (Amazon Dash button hack)

0
The most terrifying situation I can imagine* is missing a parcel

New Amazon Dash Buttons

0
You can teach new buttons old tricks!

ESP8266 ceiling light – demo

0
Testing the ESP8266 as a WIFI light controller

Try Tasker and Raspberry Pi for your home automation needs!

0
Raspberry Pi can help you with your Tasker profiles

Smart Home

Awesome time with Wio Terminal

0
Wio Terminal from SeeedStudio is a great all-in-one development board that doesn't require soldering skills to get started with.

Flashing Tasmota on Sonoff ZigBee Bridge

0
How to flash Tasmota on Sonoff ZigBee Bridge to enable it for NodeRED and Home Assistant

Flashing Tasmota on Novostella smart bulb & floodlights

0
Flashing Tasmota on Tasmota on Novostella smart bulb & floodlights - it's quick simple and rewarding - here is how to use lights in NodeRED

Adding Sonoff sensors in Zigbee2MQTT and other systems

0
Can you use Sonoff sensors in Zigbee2MQTT and other ecosystems? Trying Tuya, Xiaomi, IKEA Tradfi and CC2531

Sonoff Zigbee sensors

0
I'm checking out Sonoff ZigBee sensors by ITEAD - what's the budget sensors like?