MQTT Online Status [3.2.0;3.4.9]

logo

Note, in OH 4+, the MQTT Broker Thing supports publishing a “Birth” message which takes the place of this rule template.

A simple rule to publish a retained message “ONLINE” to a configured topic when the MQTT Broker Thing changes to ONLINE. The topic is expected to be the same topic configured in the MQTT Broker Thing as the LWT message. The Broker Thing should also be configured to publish the “OFFLINE” message as retained so all clients will know the status of openHAB at all times whether or not they were subscribed to the topic when OH actually went online/offline.

The rule has two parameters:

Parameter Purpose
MQTT Broker Thing Select the MQTT Broker Thing with an LWT configured.
LWT Topic The full LWT topic configured in the MQTT Broker Thing

Language: Nashorn JavaScript

Dependencies:

  • MQTT binding installed
  • MQTT Broker Thing created and configured
  • LWT configured on the MQTT Broker Thing
  • LWT message configured to be sent as retained on the MQTT Broker Thing
  • In OH 4 the Nashorn add-on must be separately installed or change the script type to application/javascript;version=ECMAScript-2021.

Changelog

Version 0.3

  • adjusted for breaking change, will no longer work for versions of OH prior to December 15th

Version 0.2

  • Made compatible with both Nashorn and JSScripting
    NOTE: Will remove support for Nashorn sometime after OH 3.2 release.

Version 0.1

  • initial release

Resources

https://raw.githubusercontent.com/rkoshak/openhab-rules-tools/main/rule-templates/mqttEb/mqtt_status.yaml

1 Like