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