HomeAlexaHow to make Sonoff ZB Mini and ZigBee2MQTT work together

How to make Sonoff ZB Mini and ZigBee2MQTT work together

Making Sonoff ZB Mini even better - integration with ZigBee2MQTT

We all knew this would happen! Sonoff ZB Mini (review) was made to work with Sonoff ZigBee Bridge (review), but there is nothing stopping me from trying it with ZigBee2MQTT and my USB stick of choice CC2531. I’m sure, I’m not the only person that wants to take the advantage of Sonoff Mini (review) form factor and ZigBee protocol, which means no flashing is involved.

Good to have choices

ZigBee is the biggest advantage here, there is no need for hardware flashing, no messing about with Sonoff DIY as well. We can simply pair Sonoff ZB Mini with a ZigBee sniffer of our choice. Then, the sky is the limit, as Sonoff ZB Mini will work with any ecosystem you want thanks to the power of NodeRED (or Home Assistant if that’s your thing). By the way, if you want to know more how to wire it, take a look at my Sonoff Mini article. The same principles apply for both devices.

Sonoff ZB Mini & ZigBee2MQTT

I have some good and bad news. At the time of the writing, Sonoff ZB Mini isn’t supported by default by ZigBee2MQTT. Fortunately, I will show you how to make it work. The good news is that I would expect the device to be added to the list of supported devices within a couple of weeks.

The device pairs in the usual way. Enable joining flag in the configuration.yaml, press and hold the Sonoff ZB Mini button for 5 seconds, and you will be greeted with a message like this:

21:46:07: Successfully interviewed '0xecxxxxxx536', device has successfully been paired
Oct 27 21:46:07 automation npm[1931]: zigbee2mqtt:warn  
2020-10-27 21:46:07: Device '0xexxxxxf536' with Zigbee model '01MINIZB' is NOT supported, please follow https://www.zigbee2mqtt.io/how_tos/how_to_support_new_devices.html

The device will be paired with your CC debugger, but the configuration is missing. I already covered the process of adding unsupported devices in this article. Please read it, as in here I will only provide you with a template to use in your devices.js file without further explaining.

{
        zigbeeModel: ['01MINIZB'],
        model: 'Sonoff ZB Mini',
        vendor: 'Sonoff',
        description: 'Smart switch - 1 gang, 3.3V switch logic',
        supports: 'on/off',
        fromZigbee: [fz.on_off],
        toZigbee: [tz.on_off],
    },

Please add the following template to the file, then restart the ZigBee2MQTT with the following commands:

 #Stopping zigbee2mqtt
 sudo systemctl stop zigbee2mqtt

 #Starting zigbee2mqtt
 sudo systemctl start zigbee2mqtt

You shouldn’t see any errors in your ZigBee2MQTT log after this.

Sonoff ZB Mini in NodeRED

From there it’s just plain sailing. The device is paired with my CC2531 and I can send and receive commands via MQTT. Reading log messages isn’t fun so let’s quickly add some functionality:

Buy Sonoff Zigbee Sensors

Buy it using these links to support NotEnoughTech.

Each section is covered in detail in relevant articles linked in the list above, so I’m just going to mention some changes.

Alexa comes thanks to Alexa NodeRED skill. You will have to remember to change the payloads from true|false to {"state": "ON"} respectively as ZigBee2MQTT uses these commands instead.

While NORA can be configured to send the correct payload to the MQTT node, so it’s pretty much plugged and play! Awesome.

I have a great inching node, which enables inching via dashboard or payload. Just add the node according to the instruction in the article and you will see the switch on the dashboard. The default inching is set to 10 sec and can be adjusted in the script. I also added an option to sync your Android alarm with NodeRED so you can turn on the lights before your alarm goes off!

As for timers, you could use the big-timer node or try my timer related writeups to set up a timer with dashboard support.

You can try the flow listed for yourself by importing the NodeRED from below:

NodeRED example flow
[{"id":"8ea492c.db7f27","type":"tab","label":"Sonoff ZB Mini","disabled":false,"info":""},{"id":"1dab420e.c6735e","type":"group","z":"8ea492c.db7f27","name":"Control","style":{"stroke":"#ff0000","fill":"#ffbfbf","label":true,"label-position":"n","color":"#000000"},"nodes":["114e990f.ea2947","e5758553.0bc618","dfaa3b78.f554b8","82da01c1.9f308"],"x":94,"y":279,"w":532,"h":202},{"id":"32c5f655.760e7a","type":"group","z":"8ea492c.db7f27","name":"inching","style":{"stroke":"#0070c0","fill":"#bfc7d7","label":true,"label-position":"n","color":"#000000"},"nodes":["38336031.2b6fb","c64ee4a0.8b8ea8","dfede585.4e6a28","55c12a6d.d55874"],"x":734,"y":79,"w":752,"h":182},{"id":"7d758f5b.2f962","type":"group","z":"8ea492c.db7f27","name":"Google Home","style":{"stroke":"#ffff00","fill":"#ffffbf","label":true,"label-position":"n","color":"#000000"},"nodes":["51fea57.de9d65c","8dfb1e93.f4603"],"x":734,"y":339,"w":772,"h":82},{"id":"b404c252.bc9a9","type":"group","z":"8ea492c.db7f27","name":"Basic communication","style":{"stroke":"#92d04f","fill":"#e3f3d3","label":true,"label-position":"n","color":"#000000"},"nodes":["5aeb0cf4.ab47a4","fe897488.75a4a8","88ee218b.4ed55","21e7cfbe.11f1c"],"x":94,"y":79,"w":532,"h":162},{"id":"d353f5fb.6c2808","type":"group","z":"8ea492c.db7f27","name":"Alexa","style":{"stroke":"#0070c0","fill":"#bfdbef","label":true,"label-position":"n","color":"#000000"},"nodes":["44ed4835.4a5188","17bbef91.ad37d","2a47a74c.1566d8"],"x":734,"y":439,"w":772,"h":82},{"id":"5aeb0cf4.ab47a4","type":"mqtt in","z":"8ea492c.db7f27","g":"b404c252.bc9a9","name":"","topic":"zigbee2mqtt/SonoffZBMini","qos":"0","datatype":"json","broker":"6e117ba5.8026e4","x":230,"y":120,"wires":[["fe897488.75a4a8"]]},{"id":"fe897488.75a4a8","type":"debug","z":"8ea492c.db7f27","g":"b404c252.bc9a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":120,"wires":[]},{"id":"88ee218b.4ed55","type":"mqtt out","z":"8ea492c.db7f27","g":"b404c252.bc9a9","name":"","topic":"zigbee2mqtt/SonoffZBMini/get","qos":"0","retain":"","broker":"6e117ba5.8026e4","x":470,"y":200,"wires":[]},{"id":"21e7cfbe.11f1c","type":"inject","z":"8ea492c.db7f27","g":"b404c252.bc9a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":190,"y":200,"wires":[["88ee218b.4ed55"]]},{"id":"114e990f.ea2947","type":"inject","z":"8ea492c.db7f27","g":"1dab420e.c6735e","name":"ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\": \"ON\"}","payloadType":"json","x":190,"y":320,"wires":[["dfaa3b78.f554b8"]]},{"id":"e5758553.0bc618","type":"inject","z":"8ea492c.db7f27","g":"1dab420e.c6735e","name":"OFF","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"state\": \"OFF\"}","payloadType":"json","x":190,"y":360,"wires":[["dfaa3b78.f554b8"]]},{"id":"dfaa3b78.f554b8","type":"mqtt out","z":"8ea492c.db7f27","g":"1dab420e.c6735e","name":"","topic":"zigbee2mqtt/SonoffZBMini/set","qos":"0","retain":"","broker":"6e117ba5.8026e4","x":470,"y":340,"wires":[]},{"id":"44ed4835.4a5188","type":"alexa-home","z":"8ea492c.db7f27","g":"d353f5fb.6c2808","conf":"241b578d.91d228","device":"119207","acknoledge":true,"name":"Sonoff Mini","topic":"","x":820,"y":480,"wires":[["2a47a74c.1566d8"]]},{"id":"51fea57.de9d65c","type":"nora-outlet","z":"8ea492c.db7f27","g":"7d758f5b.2f962","devicename":"Sonoff Mini","roomhint":"Office","name":"","passthru":false,"nora":"f42822fd.eb6d","topic":"","onvalue":"{\"state\": \"ON\"}","onvalueType":"json","offvalue":"{\"state\":\"OFF\"}","offvalueType":"json","x":830,"y":380,"wires":[["8dfb1e93.f4603"]]},{"id":"17bbef91.ad37d","type":"mqtt out","z":"8ea492c.db7f27","g":"d353f5fb.6c2808","name":"","topic":"zigbee2mqtt/SonoffZBMini/set","qos":"0","retain":"","broker":"6e117ba5.8026e4","x":1350,"y":480,"wires":[]},{"id":"2a47a74c.1566d8","type":"change","z":"8ea492c.db7f27","g":"d353f5fb.6c2808","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"{\"state\": \"ON\"}","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"{\"state\": \"OFF\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1020,"y":480,"wires":[["17bbef91.ad37d"]]},{"id":"82da01c1.9f308","type":"ui_switch","z":"8ea492c.db7f27","g":"1dab420e.c6735e","name":"","label":"Sonoff ZB Mini","tooltip":"","group":"5b72dc71.346384","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"{\"state\": \"ON\"}","onvalueType":"json","onicon":"","oncolor":"","offvalue":"{\"state\": \"OFF\"}","offvalueType":"json","officon":"","offcolor":"","x":200,"y":440,"wires":[["dfaa3b78.f554b8"]]},{"id":"38336031.2b6fb","type":"function","z":"8ea492c.db7f27","g":"32c5f655.760e7a","name":"inching","func":"var button = msg.payload;\nvar topic = msg.topic;\nvar alarm = context.get(\"alarmState\");\nvar timeout = (flow.get(\"timeout\")) *1000;\n\n// delayed payload\nfunction inching(){\n    if(alarm === true){\n    msg = {payload: false};\n    context.set(\"alarmState\", false);\n    msg1 = {payload: false, topic: \"inching\"};\n    node.send([msg, msg1]);\n    }\n}\n\nif(topic !== \"inching\"){\n// alarm not set\n    if(alarm === false){\n        if(button === true){\n            context.set(\"alarmState\", true);\n            setTimeout(inching, timeout);\n            return [msg, null];\n        }\n        if(button === false){\n            return[msg, null];\n        }\n    }\n//alarm set    \n    if(alarm === true){\n        if(button === true){\n            let x = setTimeout(inching, timeout);\n            clearTimeout(x);\n            setTimeout(inching, timeout);\n            return [msg, null];\n        }\n        \n        if(button === false){\n            let x = setTimeout(inching, timeout);\n            clearTimeout(x);\n            return[msg, null];\n        }\n    }\n}\n\n","outputs":2,"noerr":0,"initialize":"","finalize":"","x":840,"y":140,"wires":[["55c12a6d.d55874"],["c64ee4a0.8b8ea8"]]},{"id":"c64ee4a0.8b8ea8","type":"ui_switch","z":"8ea492c.db7f27","g":"32c5f655.760e7a","name":"","label":"Sonoff inching","tooltip":"","group":"5b72dc71.346384","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":840,"y":220,"wires":[["38336031.2b6fb"]]},{"id":"8dfb1e93.f4603","type":"mqtt out","z":"8ea492c.db7f27","g":"7d758f5b.2f962","name":"","topic":"zigbee2mqtt/SonoffZBMini/set","qos":"0","retain":"","broker":"6e117ba5.8026e4","x":1350,"y":380,"wires":[]},{"id":"dfede585.4e6a28","type":"mqtt out","z":"8ea492c.db7f27","g":"32c5f655.760e7a","name":"","topic":"zigbee2mqtt/SonoffZBMini/set","qos":"0","retain":"","broker":"6e117ba5.8026e4","x":1330,"y":120,"wires":[]},{"id":"55c12a6d.d55874","type":"change","z":"8ea492c.db7f27","g":"32c5f655.760e7a","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"{\"state\": \"ON\"}","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"{\"state\": \"OFF\"}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":120,"wires":[["dfede585.4e6a28"]]},{"id":"6e117ba5.8026e4","type":"mqtt-broker","z":"","name":"MQTT","broker":"automation.local","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"241b578d.91d228","type":"alexa-home-conf","z":"","username":"quintaar"},{"id":"f42822fd.eb6d","type":"nora-config","z":"","name":"NORA","group":"","notify":false},{"id":"5b72dc71.346384","type":"ui_group","z":"","name":"Inching in NodeRED","tab":"1d956ad4.4f89d5","order":1,"disp":true,"width":"6","collapse":false},{"id":"1d956ad4.4f89d5","type":"ui_tab","z":"","name":"Inching Switch","icon":"dashboard","order":7,"disabled":false,"hidden":false}]

Buy Sonoff ZB Mini

Buy it using these links to support NotEnoughTech.

Final thoughts

With a small effort, Sonoff ZB Mini had been added to my NodeRED sever. Now I can integrate the switch with any ecosystem I want. I already did so for other Sonoff ZigBee gadgets. It’s ZigBee, so you don’t have to stick to a single ecosystem, you can take a look at these Tuya sensors, compatible Aqara devices or IKEA Tradfri integration. Also if you want you can add an external antenna to the Sonoff ZB Mini and CC2531 – I have a tutorial about it too. Mix and match it all! I hope you enjoyed the article, leave me a comment 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 with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

Smart Ideas with

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

client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image
client-image

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

Tuya SDK for beginners: Intro to Tuya Cloud API

0
Working with Tuya Cloud API. A guide to Cloud automation for beginners, get started with REST!

NEST your old thermostat under $5

0
Nest-ing up your older thermostat under $5

Nora – Google Assistant in NodeRED

0
Integrate Google Assistant with NodeRED thanks to Nora - NodeRED home automation

DIY Smart Washing Machine – for about 15 bucks!

0
Learn how to add washing machine notifications to your Google Home on the cheap

Sonoff Zigbee Bridge – review

0
Sonoff line up will soon include Sonoff Zigbee Bridge and more Zigbee sensors - here is the first look

Smart Home

Remotes aren’t done with us yet: SwitchBot Remote

0
If you hate having 20 remotes hidden in your sofa, or your parents despise talking to Alexa to turn the lights on - SwitchBot Universal Remote is here to deal with all this!

We’ve seen this before: SwitchBot K10+ PRO

0
This is an odd one. Building on the success of SwitchBot K10+ they released SwitchBot K10+ PRO - but is the experience actually better?

Is this the smart panel we have waited for?

0
ITEAD has released a new smart panel: Sonoff NSPanel Pro 120 - have they learned the lesson from the terrible launch of the original Pro? Let's see what's new.

Aqara FP1E detects motionless humans

0
This isn't exactly a new device, it's an interaction of the original Aqara presence sensor. Aqara FP1E brings Matter, ZigBee and new triggers to your smart home

SwitchBot S10: cleaning re-imagined!

0
SwitchBot S10 promises unattended vacuuming and mopping so you can focus on things you love and care for. Does it deliver?