Sonoff SNZB-01 switch. How to create a proper flow in NodeRed

Hi! I’m yet another new HA/NodeRed newbie :smile:

I apologise for the not so good English - it’s not my first language. If clarification is required, I would be happy to provide it.

I am trying to create an automation that would allow me to control a lamp with the Sonoff SNZB-01 button. The button is connected via a Sonoff ZBBridge flashed with Tasmota firmware. I am using the ZigBee2Tasmota integration. The data is coming through the Mosquitto MQTT broker.

The button can produce three states depending on the press type: 2 - single press, 1 - double press, 0 - long press (longer than 4 seconds).
On press broker receives next data from Tasmota:


Where “Power” defines press type.

The button is defined as a sensor:

- platform: mqtt
  name: Switch
  state_topic: "tele/zbbridge/0BF3/SENSOR"
  value_template: > 
    {{ value_json['ZbReceived']['0x0BF3']['Power'] }}
  qos: 0

I tried to find a way to control the lamp with this button. I tried connecting directly to the MQTT broker with MQTT in node (this way is preferred way). MQTT node’s output is ok:


But for some reason I can’t parse the value of Power from it. Tried to do it with Switch node, applying JSONata filter $.ZbReceived.'0x0BF3'.Power=2 in it. Filter produced empty value (tested it on - it works!).
Tried to use Template node with template {{ ZbReceived.'0x0BF3'.Power }} - no way.

I also tried to run automation with Trigger: State or Event: State nodes, but there were problems with the states not being reset after the button was pressed, and the next press not triggering.

What is my mistake? What is the correct way to connect these devices?

The way you work with mqtt in NR is by using an mqtt node connected to a switch. On the bottom of the switch you can add as many additional values as needed.

[{"id":"3398f6b6a84f647d","type":"switch","z":"f80b6c338afd5483","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"value 1","vt":"str"},{"t":"eq","v":"value 2","vt":"str"},{"t":"eq","v":"value 3","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":410,"y":1820,"wires":[[],[],[]]}]
1 Like

Thank you very much for your reply. After hours of trial and error, I’ve come to roughly the same way myself. Only apart from value I use contains to determine the press type.