ZigBee2MQTT Device Availability

Hi, i hope someone can help me understand this.

I have a lot of ZigBee devices. Configured via ZigBee2MQTT. So far so good. Everything works fine. Now i would love to have an extra channel for every device which shows me the current state (online/offline)

I already defined it in the configuration.yaml.

availability:
  active:
    timeout: 10
  passive:
    timeout: 1440

The frontend already shows me the current state. But i don’t know if its possible to get an extra channel for every single device. I already tried:

advanced:
  legacy_availability_payload: true

But my ZigBee2MQTT seems to stop working after adding this line. I hoped, it adds a second JSON-attribute to the received payload. Like this: {"state":"offline"}

EXAMPLE:

{"state":"offline","battery":100,"battery_low":false,"device_temperature":35,"power_outage_count":381,"tamper":false,"voltage":3005,"water_leak":false}

But as my ZigBee2MQTT fails to start after adding it in the configuration.yaml i don’t know how to achieve this.

Thanks in advance :slight_smile:

Please read https://www.zigbee2mqtt.io/guide/configuration/device-availability.html:

The availability feature checks whether your devices are online. The availability state of a device is published to zigbee2mqtt/[FRIENDLY_NAME]/availability (this message is a retained MQTT message).

I have these statements in my zigbee2mqtt configuration.yaml
legacy_api: true
legacy_availability_payload: true

If I run this mosquitto command:
mosquitto_sub -h 192.168.1.164 -W 1 -v -t “zigbee2mqtt/+/availability”

I get the out put like this:
zigbee2mqtt/switch-backup-server/availability online
zigbee2mqtt/sensor-hue-lounge/availability online

This is the thing set up:

Thank you. Your replies helped me a lot.

I managed to get a working status for all my MQTT.things.
But now i would like to get a switch-item to show me the current state. I tried following without success:

Thing mqtt:topic:FRIENDLY_NAME "Z2M: FRIENDLY NAME" (mqtt:broker:823098e4c9) [availabilityTopic="zigbee2mqtt/FRIENDLY_NAME/availability", payloadAvailable="online", payloadNotAvailable="offline", transformationPattern="JSONPATH:$.state"] {
    Channels:
    Type switch : online "Availability" [stateTopic="zigbee2mqtt/FRIENDLY_NAME/availability", transformationPattern="JSONPATH:$.state", on="online", off="offline"]
}

My switch is not updating at all. What am i doing wrong now?

Set it like this and make the thing an on off switch:

UID: mqtt:topic:mqttbroker:9569f6beeb
label: Zigbee door front middle
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  availabilityTopic: zigbee2mqtt/door-front-middle/availability
  payloadAvailable: online
bridgeUID: mqtt:broker:mqttbroker
location: Loungeroom
channels:
  - id: zigbeetestonline
    channelTypeUID: mqtt:switch
    label: Zigbee online
    description: ""
    configuration:
      commandTopic: zigbee2mqtt/door-front-middle/availability
      stateTopic: zigbee2mqtt/door-front-middle/availability
      off: online
      on: offline

Then create a switch: