MQTT Event Bus Subscription [3.2.0;3.4.9]

logo
Note, in the first half of 2023, this rule template will be rewritten to only support JS Scripting.

This is one of three rules used to create an MQTT Even Bus. The other rules are MQTT Online Status [3.2.0;3.4.9) and https://community.openhab.org/t/mqtt-event-bus-publication/127997.This rule is responsible for parsing the messages received on an event bus and commanding or updating Items as necessary. See Marketplace MQTT Event Bus for details on how to set up and configure an MQTT Even Bus.

Warning, to avoid infinite loops, do not publish and subscribe the same event on the same Items.

openHAB instance Publishes Subscribes
Linked to device updates commands
Remote commands updates

The rule has the following parameters:

Parameter Purpose
MQTT Broker Thing The MQTT Broker Thing connected to the MQTT broker where the event bus is running.
MQTT Event Channel The Event Channel configured on the MQTT Broker Thing that has the event bus subscription.

Language: Nashorn JavaScript

Dependencies:

  • MQTT Binding installed
  • MQTT Broker Thing created and configured
  • Event Channel configured on the MQTT Broker Thing configured to subscribe to the event bus. For example remote/out/# will subscribe to all the event bus messages for the openHAB instance named “remote”.
  • 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_eb_sub.yaml

2 Likes