Migrate to zigbee2mqtt 2.x and legacy_availability_payload

I am trying to upgrade from zigbee2mqtt 1.x to a 2.x version. I need to set legacy_availability_payload: false in comfiguration.yaml (Zigbee2MQTT 2.0.0 breaking changes · Koenkk/zigbee2mqtt · Discussion #24198 · GitHub)

When I do that, I get errors on all the availability channels in OpenHAB. For example:

Command '{"state":"online"}' from channel 'mqtt:topic:aqaraContactSensor1:availability' not supported by type 'OnOffValue': No enum constant org.openhab.core.library.types.OnOffType.{"state":"online"}

I have the following Thing configuration for that channel:

Type switch : availability "Availability" [ stateTopic = "zigbee2mqtt/aqaraContactSensor1/availability", on="online", off="offline" ]

I suppose zigbee2mqtt is now sending “state”:“online” instead of “online”, but how can I fix that in my Thing definition?

I did try the following, because zigbee2mqtt sends now {“state”:“online”} instead of just online. Unfortunately, I still get the same error.

Type switch : availability "Availability" [ stateTopic = "zigbee2mqtt/aqaraClimateSensor1/availability", on="\"state\":\"online\"", off="\"state\":\"offline\"" ]

The only thing that looks odd is that on !=ON & off !=OFF I thought the switch item was particular

zigbee2mqtt can use json payload as well as discrete topics. (MQTT Output Type)

So either change this setting to attribute or attribute_and_json or setup value transformation with JSONPath.

Type switch : availability "Availability" [ stateTopic = "zigbee2mqtt/aqaraContactSensor1/availability", on="online", off="offline", transformationPattern="JSONPATH:$.state" ]
1 Like

Thanks, using the JSONPATH transformation fixed it.

I already did update the following in configuration.yaml. However, zigbee2mqtt keeps sending {“state”:“online”} instead of of just online.

From

experimental:
    output: attribute

to

advanced:
    output: attribute

availability always sends the complete json as payload no matter if output is set to attribute or attribute_and_json. It doesn’t feel right but it’s stated in the docs too:

2 Likes

Thanks for pointing that out. I just assumed that the output config parameter would also apply to availability.