Mqtt thing with zigbee2mqtt - availability vs status of Thing

Hi there:

Thing status vs zigbee2mqtt device status. Device is a thing.

Thing:

UID: mqtt:topic:mymqttbroker:Temp_1
label: Termperatura 1
thingTypeUID: mqtt:topic
configuration: {}
bridgeUID: mqtt:broker:mymqttbroker
channels:
  - id: temperature
    channelTypeUID: mqtt:number
    label: Temperatura
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/Temp_1
      transformationPattern:
        - JSONPATH:$.temperature
  - id: humidity
    channelTypeUID: mqtt:number
    label: Wilgotnosc
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/Temp_1
      transformationPattern:
        - JSONPATH:$.humidity
  - id: battery
    channelTypeUID: mqtt:number
    label: Bateria
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/Temp_1
      transformationPattern:
        - JSONPATH:$.battery
  - id: linkquality
    channelTypeUID: mqtt:number
    label: Link
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/Temp_1
      transformationPattern:
        - JSONPATH:$.linkquality
  - id: voltage
    channelTypeUID: mqtt:number
    label: Napiecie
    configuration:
      retained: false
      postCommand: false
      step: 1
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/Temp_1
      transformationPattern:
        - JSONPATH:$.voltage
  - id: availability
    channelTypeUID: mqtt:switch
    label: dostepnosc
    configuration:
      retained: false
      postCommand: false
      formatBeforePublish: "%s"
      stateTopic: zigbee2mqtt/Temp_1/availability
      off: offline
      on: online

Problem:
Thing is offline in zigbee2mqtt and reporting Availability OFF - with i can parse and use for further automations but Thing representing the device is ONLINE which is quite confusing

What i am looking for - if zigbee2mqtt device is offline the Thing should be offline also. I can achieve it by auto doscovered things via openassistant discovery, but i am not sure how to create such think using a textual definition

Why
at the end ai have a healt-check of my thigns using such script to send notifications about oflfine things.


rules.JSRule({
    name: "Things offline",
    description: "Powiadomienia o rzeczach offline",
    triggers: [triggers.GenericCronTrigger("1 9 8 * * ?")],
    execute: (event) => {

        var thingi = things.getThings();
        console.log(thingi[0].isEnabled)
        var offline = "Rzeczy offline: \n"
        for (let i = 0; i < thingi.length ; i++) {
            if ( thingi[i].status !== "ONLINE" && thingi[i].isEnabled === true) {
           offline = offline + thingi[i].label + " stan : " + thingi[i].status + " " + " \n"
           }
        }
       actions.notificationBuilder(offline).send()
       console.log(offline)

    },

    id: "Things"
  });

Probably i miss these availability config in my thing definition

channels:
  - id: 0x70b3d52b600181c7_5Fswitch_5Fl1_5Fzigbee2mqtt#switch
    channelTypeUID: mqtt:ha-switch
    label: L1
    configuration:
      component: switch
      config: '{"availability":[{"topic":"zigbee2mqtt/bridge/state"},{"topic":"zigbee2mqtt/switch_4/availability"}],"availability_mode":"all","command_topic":"zigbee2mqtt/switch_4/l1/set","device":{"identifiers":["zigbee2mqtt_0x70b3d52b600181c7"],"manufacturer":"TuYa","model":"2
        gang switch module
        (TS0002_switch_module_2)","name":"switch_4","sw_version":"202+TZTDQ22CL108","via_device":"zigbee2mqtt_bridge_0x385b44fffe002adc"},"json_attributes_topic":"zigbee2mqtt/switch_4","name":"L1","object_id":"switch_4_l1","origin":{"name":"Zigbee2MQTT","sw":"1.36.0","url":"https://www.zigbee2mqtt.io"},"payload_off":"OFF","payload_on":"ON","state_topic":"zigbee2mqtt/switch_4","unique_id":"0x70b3d52b600181c7_switch_l1_zigbee2mqtt","value_template":"{{
        value_json.state_l1 }}"}'
      nodeid: "0x70b3d52b600181c7"
      objectid: switch_l1

Hi, try this in your thing configuration.

configuration:
  payloadNotAvailable: '{"state":"offline"}'
  availabilityTopic: zigbee2mqtt/Temp_1/availability
  payloadAvailable: '{"state":"online"}

Greets

The thing might be missing the availability.
You have to click advanced on the thing to see the options.

UID: mqtt:topic:mqttbroker:shed4gang
label: Shed 4 gang zigbee switch
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  payloadAvailable: online
  transformationPattern:
    - JSONPATH:$.state
  availabilityTopic: zigbee2mqtt/shed4gang/availability
bridgeUID: mqtt:broker:mqttbroker

It should look like this:

Does this work for you today? I’ve got the same as @Baschtlwaschtl with a JSON string, using one of the latest versions (1.41) of zigbee2mqtt.

I was at z2m 1.39 and used

payloadNotAvailable: offline
payloadAvailable: online

Then I updated to 1.42 and had to change to

payloadNotAvailable: '{"state":"offline"}'
payloadAvailable: '{"state":"online"}

today I updated to 2.0.0 and it’s all good..
Greets

1 Like

Yes mine works because I have the transformation.
Like you I had to change this with different version changes.
It used to work with just offline and online without the transformation.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.