Sonoff Zigbee devices constantly going offline

Yes you do.

Iā€™ve had a stab at the yaml required to define my PIR sensor, but canā€™t work out what to use for payload_on. This is what I have so far:

binary_sensor:
  - platform: mqtt
    name: "PIR Sensor"
    state_topic: "tele/zigbee-bridge/SENSOR"
    device_class: motion
    qos: 1
	payload_on: ???

This is the MQTT message that I get when I trigger the motion sensor:

    "ZbReceived": {
        "0xD6EA": {
            "Device": "0xD6EA",
            "0500<00": "010000010000",
            "ZoneStatusChange": 1,
            "ZoneStatusChangeZone": 1,
            "Occupancy": 1,
            "Endpoint": 1,
            "LinkQuality": 84
        }
    }
}

What do I need to specify for payload_on, and do I need to add anything else?

Try :

binary_sensor:
  - platform: mqtt
    name: "PIR Sensor"
    state_topic: "tele/zigbee-bridge/0xD6EA/ZoneStatusChange"
    device_class: motion
    qos: 1
    payload_off: '0'
    payload_on: '1'

Thanks - Iā€™ve defined my sensor as per your YAML, but Iā€™m not seeing any MQTT messages for that state_topic when I trigger the PIR (tele/zigbee-bridge/0xD6EA/ZoneStatusChange).
I have the Topic defined in the Tasmota config (on the Sonoff Zigbee Bridge) as ā€œzigbee-bridgeā€ - it doesnā€™t contain the Device Id anywhere.
Should I be including a device variable somewhere in the topic for that state_topic to be usable?

To get around this issue Iā€™ve been exploring ways of sending sensor values to separated MQTT topicsā€¦
Using info from Zigbee - Tasmota I created this rule on the Tasmota console:

Rule1
  on zbreceived#0x3AB1#ZoneStatusChange do publish tele/zigbee-bridge/door/SENSOR %value% endon
  on zbreceived#0x3D32#ZoneStatusChange do publish tele/zigbee-bridge/pir-study/SENSOR %value% endon
  on zbreceived#0x520C#ZoneStatusChange do publish tele/zigbee-bridge/pir-hall/SENSOR %value% endon
  on zbreceived#0xD6EA#ZoneStatusChange do publish tele/zigbee-bridge/pir-lounge/SENSOR %value% endon

Rule1 1

Now whenever I trigger a sensor I get MQTT message on a topic specific to the sensor. For example:

23:16:36.820 MQT: tele/zigbee-bridge/pir-study/SENSOR = 0

The problem is that I donā€™t know how to interpret this value in my HA config. If I listen for the tele/zigbee-bridge/pir-study/SENSOR topic, for example, I simply get a value of ā€œ1ā€ when the sensor is triggered.
The config below does not pick this up:

  - platform: mqtt
    name: "PIR hall"
    state_topic: "tele/zigbee-bridge/pir-hall/SENSOR"
    device_class: motion
    qos: 1
    payload_off: '0'
    payload_on: '1'

Any idea how I can monitor for the value of ā€œ1ā€ which is now being returned from each MQTT topic?

OK it looks like HA is actually setting my binary sensors to ā€œonā€ or ā€œoffā€ based on these new topics.
The only thing I canā€™t get is battery levels from the sensors, which I could get from the ZHA solution. Is that something that I will have to live without if I use zigbee2tasmota?

I had the same setup as you and the same issues. Moved to a Conbee II about a month ago (bought from amazon under Ā£40) and I think iā€™ve had one device drop off since then (and I think it was because somebody was messing with the light switch).

Does your Conbee solution report battery levels for your sensors? Both ZHA and the Tasmota interface report battery levels, but I canā€™t get them reported in HA using zigbee2tasmota - thereā€™s a suggested solution using a Rule at the link posted by francisp above (thanks Francis!), but I couldnā€™t get it to work in my config.

The ConBee reports battery level for all my devices, however I donā€™t use any of the sonoff sensors.
But I can tell you that for most devices the battery level is more or less useless (except for Philips). I had some sensors reporting 100% over 3 years and then suddenly from one day to the next they went offline due to an empty battery.

Yes I did see some strange fluctuations in battery reporting when I was using ZHA.
Maybe I could just set up an alert if any of the sensors has not been triggered for an unusually long period of time. Is there a recommended way of doing this in HA?

Yep. Using ZHA and my mix of sonoff and aqara sensors are all reporting their batteries.

Though it looks like its not accurate!

Iā€™ve just realised that I had a another Zigbee device which was previously working with ZHA - a Sage Doorbell sensor. Iā€™ve managed to pair it with the Sonoff ZB Bridge, and am getting MQTT messages like this when I press the doorbell:

19:52:47.264 MQT: tele/zigbee-bridge/SENSOR = {"ZbReceived":{"0x1D4E":{"Device":"0x1D4E","Name":"sage-doorbell-sensor","0006!01":"","Power":1,"Endpoint":18,"LinkQuality":39}}}

Any idea how I should configure the sensor to detect these messages?

Edit: this is what the JSON looks like from the MQTT topic:

{
    "ZbReceived": {
        "0x1D4E": {
            "Device": "0x1D4E",
            "Name": "sage-doorbell-sensor",
            "0006!01": "",
            "Power": 1,
            "Endpoint": 18,
            "LinkQuality": 50
        }
    }
}

You would need to see what you get when you press the doorbell.

The json that I posted is what I get when I press the doorbell. Three occurrences of the same message are received for each button press.