Issue of the topic: I have a number of devices that run on Tasmota and communicate with OH via MQTT. The OH MQTT Binding always shows a thing status as ONLINE. Tasmota devices, on the other hand, utilize a special MQTT topic LWT (Last Will and Testament) that correctly reflects an Online/Offline status of a device.
Question: Is it possible and how to align/update an MQTT thing status with/from a specific MQTT topic? Can a thing status be updated from a Rule?
Please, note, that I am asking about a thing not an an item. Thanks in advance.
Thanks, but I don’t think it’s what I am looking for. The channels are dependants of a thing meaning that any particular channel does not have its own status. The thing status is common for all channels and has to be defined at the thing level.
Configuration of the MQTT Broker thing allows defining a Last will topic but which is kind of I am looking for on the thing level. From the documentation it’s not clear what this topic is used for and whether it’s applicable for discovering things’ statuses, and also if it can be configured with wildcard syntax for different things.
Can anyone shed more light on this?
On every Generic MQTT Thing you can set a LWT topic and an online and offline message in it’s configuration. When the LWT has the offline message posted the Generic Thing will be marked as OFFLINE and all the Items linked to the Channels will be set to UNDEF.
Note that for this to work the device needs to publish both an ONLINE and OFFLINE message to the LWT topic and the messages must be published as retained.
UID: mqtt:topic:mosquitto:cerberos_sensor_reporter
label: Cerberos sensor_reporter
thingTypeUID: mqtt:topic
configuration:
payloadNotAvailable: OFFLINE
availabilityTopic: sensor_reporter/cerberos/status
payloadAvailable: ONLINE
bridgeUID: mqtt:broker:broker
location: Garage
channels:
- id: garagedoor1
channelTypeUID: mqtt:contact
label: Large garage door
description: Large garage door open status
configuration:
stateTopic: sensor_reporter/cerberos/garagedoor1/state
off: CLOSED
on: OPEN
- id: garagedoor2
channelTypeUID: mqtt:contact
label: Small garage door
description: Small garage door open status
configuration:
stateTopic: sensor_reporter/cerberos/garagedoor2/state
off: CLOSED
on: OPEN
- id: garagedoor1_opener
channelTypeUID: mqtt:switch
label: Large garage door opener
description: ""
configuration:
commandTopic: sensor_reporter/cerberos/garagedoor1/cmd
off: OFF
on: ON
- id: garagedoor2_opener
channelTypeUID: mqtt:switch
label: Small garage door opener
description: Small garage door opener controller
configuration:
commandTopic: sensor_reporter/cerberos/garagedoor2/cmd
off: OFF
on: ON
- id: online
channelTypeUID: mqtt:switch
label: Online status
description: Indicates online status of this sensor_reporter
configuration:
stateTopic: sensor_reporter/cerberos/status
off: OFFLINE
on: ONLINE
That is not what you are looking for. The Broker Thing’s LWT is to define the message that the broker publishes on openHAB’s behalf when openHAB disconnects.
I missed that. If that’s the case @aturlov, the answer is no, you can’t. The 2.4 version binding doesn’t have these options to set the LWT on the Generic MQTT Thing and there is no way to set the status of a Thing from a Rule.
Thing status can updated from REST API in a way - you can enable or disable it at least. Disabled will result in status OFFLINE, enabling will do whatever initializing is needed and go eventually to ONLINE all being well.
I do not think you can manipulate Thing status directly, because that is the binding’s job.
You can use REST API from a rule with sendHttpGetRequest() or similar.
I’m not convinced you need to do this though …
There’s no problem with that. The Thing does not represent the device really, it represents a collection of topics you might be listening to from a broker. You’ve no idea when the next message might come, even if you think the device is currently powered off. If you disable/OFFLINE this Thing you will never find out when it wakes up.
The Thing status really represents your listening ability to the broker.
Thanks, everyone. What @rlkoshak explained is exactly what I was looking for and I understand it’s only available in OH 3, so I need to upgrade first. At least, I have one more motivation to upgrade.
The feature was introduced sometime after OH 2.5.3 I think. If you upgrade to 2.5.11 you should get it with minimal work and you can save the upgrade to OH 3 to do at your leisure.