Sonoff Zigbee (SNZB) Sensors & Switches with Zigbee2MQTT

Thanks for this, looks great!

You can do at least this one, and probably a few more directly in the channel without the JS transformation:

Cheers!

Will have to re-evaluate the JS transformations as they are probably not all necessary, I know the contact sensor one is useful though as it flips the OPEN = True mapping to the opposite of the rest. They helped me get through implementation without errors so I included them here.

Bring on the improvements though. Let’s trim-the-fat/shed-some-weight/less-is-more this approach!

I hear you - I went on the same journey recently with WLED stuff!

I think you can trim this down very easily already. For example, on your motion sensor, you could get rid of all the JS transforms by changing your things file as follows:

Type contact : occupancy   "Occupancy"    [ stateTopic="zigbee2mqtt/UNIQUE_ZIGBEE_ID", transformationPattern="JSONPATH:$.data.occupancy", on="true", off="false"]
Type contact : tamper      "Tamper"       [ stateTopic="zigbee2mqtt/UNIQUE_ZIGBEE_ID", transformationPattern="JSONPATH:$.data.tamper", on="true", off="false"]
Type contact : battery_low "Battery Low"  [ stateTopic="zigbee2mqtt/UNIQUE_ZIGBEE_ID", transformationPattern="JSONPATH:$.data.battery_low", on="true", off="false"]
     

The above will use the JSONPATH transform to extract the required values, then map true and false to on and off (which for a contact channel actually means true and false will map to open and closed). If you want to switch it, you can map on="false" and off="true"

(I’ve made an assumption here on what the device actually returns on these topics, so you may need to tweak)

2 Likes

Good idea. Done! Replaced with a few simple maps. Much cleaner now.

Also improved my Zigbee2MQTT item by leaning on what I picked up from your post on the topic. Muchas gracias :+1:

1 Like

I have this setup in place, but the range is not that good. Sonoff also released a ZigBee bridge which can be flashed with Tasmota. I saw some tutorials to connect it directly with home assistant through their ZigBee binding. Is this also possible with the Openhab ZigBee binding?
Connecting everything via mqtt is possible, but it can be easier :smile:

Hey there,
I know you decided to go the MQTT way, but was wondering if anyone has any idea if it will just work with Zigbee Binding directly!
I’m thinking of buying some of those, but would be nice if someone had a positive experience already.

Yes, I was able to get SONOFF SNZB-03 motion sensor working with standard ZigBee binding directly. The key to discovering is to change the ZigBee USB stick channel to 15. See this thread. I believe it is a ZigBee 3.0 strangeness. (Zigbee 3.0 Installation Code )

1 Like

I’m not able to get the SNZB-02 temperature/humidity sensor to work. I was able to join the device, but the sensor doesn’t send any data.

“date_code” : “20201026”,
“definition” : {
“description” : “Temperature and humidity sensor”,
“exposes” : [ {
“access” : 1,
“description” : “Remaining battery in %”,
“name” : “battery”,
“property” : “battery”,
“type” : “numeric”,
“unit” : “%”,
“value_max” : 100,
“value_min” : 0
}, {
“access” : 1,
“description” : “Measured temperature value”,
“name” : “temperature”,
“property” : “temperature”,
“type” : “numeric”,
“unit” : “°C”
}, {
“access” : 1,
“description” : “Measured relative humidity”,
“name” : “humidity”,
“property” : “humidity”,
“type” : “numeric”,
“unit” : “%”
}, {
“access” : 1,
“description” : “Link quality (signal strength)”,
“name” : “linkquality”,
“property” : “linkquality”,
“type” : “numeric”,
“unit” : “lqi”,
“value_max” : 255,
“value_min” : 0
} ],
“model” : “SNZB-02”,
“vendor” : “SONOFF”
},
“endpoints” : {
“1” : {
“bindings” : [ {
“cluster” : “msTemperatureMeasurement”,
“target” : {
“endpoint” : 1,
“ieee_address” : “0x00124b0018e1aba5”,
“type” : “endpoint”
}
}, {
“cluster” : “msRelativeHumidity”,
“target” : {
“endpoint” : 1,
“ieee_address” : “0x00124b0018e1aba5”,
“type” : “endpoint”
}
}, {
“cluster” : “genPowerCfg”,
“target” : {
“endpoint” : 1,
“ieee_address” : “0x00124b0018e1aba5”,
“type” : “endpoint”
}
} ],
“clusters” : {
“input” : [ “genBasic”, “genIdentify”, “msTemperatureMeasurement”, “msRelativeHumidity”, “genPowerCfg” ],
“output” : [ “genIdentify” ]
},
“configured_reportings” : [ {
“attribute” : “measuredValue”,
“cluster” : “msTemperatureMeasurement”,
“maximum_report_interval” : 1800,
“minimum_report_interval” : 5,
“reportable_change” : 50
}, {
“attribute” : “measuredValue”,
“cluster” : “msRelativeHumidity”,
“maximum_report_interval” : 3600,
“minimum_report_interval” : 10,
“reportable_change” : 100
}, {
“attribute” : “batteryVoltage”,
“cluster” : “genPowerCfg”,
“maximum_report_interval” : 62000,
“minimum_report_interval” : 3600,
“reportable_change” : 0
} ]
}
},
“friendly_name” : “TH01_SENSOR1”,
“ieee_address” : “0x00124b002268578f”,
“interview_completed” : true,
“interviewing” : false,
“model_id” : “TH01”,
“network_address” : 32103,
“power_source” : “Battery”,
“supported” : true,
“type” : “EndDevice”

With the SONOFF SNZB-03 Motion Sensor there was no problems it instantly begin to publish its data to my ZigBee2Mqtt bridge.

info 2021-02-12 11:12:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/occupancy’, payload ‘true’
info 2021-02-12 11:12:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/tamper’, payload ‘false’
info 2021-02-12 11:12:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/battery_low’, payload ‘false’
info 2021-02-12 11:12:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/linkquality’, payload ‘47’
info 2021-02-12 11:13:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/occupancy’, payload ‘false’
info 2021-02-12 11:13:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/tamper’, payload ‘false’
info 2021-02-12 11:13:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/battery_low’, payload ‘false’
info 2021-02-12 11:13:41: MQTT publish: topic ‘zigbee2mqtt/MS01-MOTION1/linkquality’, payload ‘47’

1.) Is it paired corretly with the Zigbee bridge?

2.) Have you checked with a mqtt Client

3.) is your openhab Configuration right

4.) Did you read that

The solution was for me to switch to the DEV branch of Zigbee2Mqtt, after that sensors immediately begun to publish their data. Thanks, anyway Dibbler42.

I switched only because of the SNZB-02 sensor. All other Zigbee2Mqtt devices that I’m using were working without issues (e.g. IKEA bulbs, IKEA motion sensors and even SNZB-03 motion sensor).

Sonoff SNZB-02 issue

How to Switch to DEV branch of Zigbee2Mqtt

1 Like

Have you thought about using the Sonoff Zigbee Bridge itself flashed with tasmota2mqqt?
That is how im currently receiving data from all my sensors. It takes out the need for any other binding as openhab just pick up the mqqt that the bridge outputs. Worth having a look anyway :grinning:

1 Like

A tip. Don’t use Contact as the Type use Switch. If you don’t put anything in the Command parameters the device becomes a read only switch (which is what it is really). Dealing with the state then becomes easier.
I think the original idea of the Contact was for an alarm sensor which in untriggered state is Closed and Open is actuated.

Does anyone know how to publish a message from true and false to 1 & 0? my door contact has values of true and false but my security system only recognises 1 & 0.

cheers

Continuing the discussion from Sonoff Zigbee (SNZB) Sensors & Switches with Zigbee2MQTT:

First of all, thanks for the great tips. Without you I would never have been able to set up my Sonoff devices.

With your tips I was able to integrate the temperature sensor.

Here is my version of the working SNZB-02 setup.
I only had to adjust the motion detector setup a little bit.

temperatursensor.items

Group TemperatureSensoren "Temperatursensoren" <motion>

Group  SNZB_02_1_Temperatur_Humidity_Sensor "Important Room Motion Sensor" <sonoff_snzb02> (GF_ImportantRoom, Sonoff_SNZB_02)
Number SNZB_02_1_Temperatur_Humidity_Sensor_temperature   "Temperatur [%s]" <motion> (SNZB_02_1_Temperatur_Humidity_Sensor, TemperatureSensoren) { channel="mqtt:topic:snzb02a:temperature" }
Number SNZB_02_1_Temperatur_Humidity_Sensor_humidity      "humidity [%s]"              <none>   (SNZB_02_1_Temperatur_Humidity_Sensor)                { channel="mqtt:topic:snzb02a:humidity" }
Contact SNZB_02_1_Temperatur_Humidity_Sensor_Battery_Low "Battery low [%s]"         <none>   (SNZB_02_1_Temperatur_Humidity_Sensor)                { channel="mqtt:topic:snzb02a:battery_low" }
Number  SNZB_02_1_Temperatur_Humidity_Sensor_Link        "Link quality [%d]"                             <none>   (SNZB_02_1_Temperatur_Humidity_Sensor)                { channel="mqtt:topic:snzb02a:linkquality" }
Number  SNZB_02_1_Temperatur_Humidity_Sensor_Battery     "Battery [%d]"                                  <none>   (SNZB_02_1_Temperatur_Humidity_Sensor)                { channel="mqtt:topic:snzb02a:battery" }
Number  SNZB_02_1_Temperatur_Humidity_Sensor_Voltage     "Voltage [%d]"                                  <none>   (SNZB_02_1_Temperatur_Humidity_Sensor)                { channel="mqtt:topic:snzb02a:voltage" }

temperatursensor.things

Thing mqtt:topic:snzb02a "Temperatur Sensor" (mqtt:broker:MQTT-Broker) @ "Important Room" {
   Channels:
     Type number : temperature   "Temperature"    [ stateTopic="zigbee2mqtt/Temperatursensor_02", transformationPattern="JSONPATH:$.temperature"]
     Type number : humidity      "Humidity"       [ stateTopic="zigbee2mqtt/Temperatursensor_02", transformationPattern="JSONPATH:$.humidity"]
     Type contact : battery_low "Battery Low"  [ stateTopic="zigbee2mqtt/Temperatursensor_02", transformationPattern="JSONPATH:$.battery_low", on="true", off="false"]
     Type number : linkquality  "Link Quality" [ stateTopic="zigbee2mqtt/Temperatursensor_02", transformationPattern="JSONPATH:$.linkquality"]
     Type number : battery      "Battery"      [ stateTopic="zigbee2mqtt/Temperatursensor_02", transformationPattern="JSONPATH:$.battery"]
     Type number : voltage      "Voltage"      [ stateTopic="zigbee2mqtt/Temperatursensor_02", transformationPattern="JSONPATH:$.voltage"]
}

Did some had success with SNZB-01 Wallswitch (Better Tochbutton) ?

I was able to integrate sucsessfuly the SZNB-2 Temp& Humid. Sensor SNZB-03 IR Detector also the SNZB-04 Window/Door Contacts in obenhab3 inbox over the homeassistant / zigbee2mqtt discovery …

But when i try to to link the item´s / Channels from the SNZB-01 i get a error Message
“there is no profile available for the selected item”

There is not much informations i could find…
May be it´is s the proble that these trigger sends "single, double an long an not “open” or “close” ?

May be some one have a working .thing and .item file for the SNZB-01 ?

How do you Bind the sonoff devices?
You must use zigbee2mqtt

I tried it with the normal zigbee binding an Id did Not work

The ONLY WAY is the zigbee2mqtt binding

But if you bind it so it will work Perfect
You Can assable 3 Touch functions
Short
Double Long

Let me know If you Need More help

I use zigbee2mqtt

May be you can share your config for the SNZB-01 ?

No Problem i Post it tomorrow

i have it!
the solution is in the first post… point 7…
i had to open the spoiler… :man_facepalming:

perfect - have fun with your new wallswitch