Item Linked to Thing status

Hi All,
I have a Zigbee2Mqtt thing:
defined as .things file like:

    Thing topic LUCE_COMODINO "Luce Comodino" @ "Camera" [availabilityTopic="zigbee2mqtt/LUCE_COMODINO/availability", payloadAvailable="online", payloadNotAvailable="offline"]{
		Type switch : l_button		"Left Button"  	[ commandTopic="zigbee2mqtt/LUCE_COMODINO/set", formatBeforePublish="{\"state_left\": \"%s\"}",  stateTopic="zigbee2mqtt/LUCE_COMODINO", transformationPattern="JSONPATH:$.state_left" ]
		Type switch : r_button		"Right Button" 	[ commandTopic="zigbee2mqtt/LUCE_COMODINO/set", formatBeforePublish="{\"state_right\": \"%s\"}", stateTopic="zigbee2mqtt/LUCE_COMODINO", transformationPattern="JSONPATH:$.state_right" ]
		Type number : linkquality	"LinkQuality"  	[ stateTopic="zigbee2mqtt/LUCE_COMODINO", transformationPattern="JSONPATH:$.linkquality",	unit="lqi",	 min=0, max=255 ]

My goal is to have a item that is on when the thing is online and off when the thing is offline so i defined this .item :

Switch L_COMODINO			"Luce Comodino"					<light>					{channel="mqtt:topic:MQTT_CASA:LUCE_COMODINO:availability" [profile="transform:MAP", function=""]}

and this transform map:


but doesn’t work.
Where is my mistake?
I already found a workaround using 2 rules that set the item on or off according to thing change…
But i want to bettern learn how to create objects to have clean code.

Thanks in advance for the help.

Not to be too blunt, but you’ve guessed at how things work and invented syntax that is not supported. The “availabilityTopic” isn’t a Channel. You can’t link it to an Item. That part of the Thing config will cause the Thing to go OFFLINE if “offline” is published to that topic. It controls the Thing’s state and has nothing to do with Items.

  • You could create a switch Channel to subscribe to that topic and link that to an Item.
  • You can use rules. There is nothing “unclean” about using rules. You could probably consolidate it down to one rule. And you don’t even need to write the this rule. There’s a Thing Status rule template you can install and use. OH 3.4.2 version, OH 4.0 version.
  • You can forego the Item entirely. As an admin user you can see the status of the Thing in MainUI. In your rules you can get the status of the Thing using the thingStatusInfo Action. The status of the Thing is not something the end users of your home automation are likely to care about so there should be no reason to expose it to them as an Item.
1 Like

Thank you very much!
Now i understand!

Here’s how you can do it:

Thing topic LUCE_COMODINO "Luce Comodino" @ "Camera" [availabilityTopic="zigbee2mqtt/LUCE_COMODINO/availability", payloadAvailable="online", payloadNotAvailable="offline"]{
		Type switch : availability "Availability" [ stateTopic="zigbee2mqtt/LUCE_COMODINO/availability", on="online", off="offline" ]

Switch L_COMODINO			"Luce Comodino"					<light>					{channel="mqtt:topic:MQTT_CASA:LUCE_COMODINO:availability", autoupdate="false" }
1 Like