MQTT 2.5 Event Bus

Tags: #<Tag:0x00007f174f568fc0>

Why does everyone sound mean around here? Or as someone smart once told me, “Its a cultural thing” lol Oh well, I’ll take the help I can get. FWIW, I think optimism and hope is a good thing :slight_smile: Ok, back to the EB…

Ok, unfortunately I’m still having the same issue on the receiver/main openhab/subscriber. I’m still seeing my helloworld script running every 10 seconds so I think I may be good with the Helper Libraries install (these are the steps I did JSR223 Helper Libraries/ Jython Support Install Guide )

My Interpreted Install Steps:
  • Install (all openhab instances):
    • Prerequisites: Install MQTT Broker binding & JSR223-Python Scripting Install
    • Download scripts: From here, click GitHub pull request link->Commits tab->"<>" symbol to “Browse the repository at this point in history”->Clone or Download zip link
    • Implement scripts:
      • Copy /Community/MQTT Eventbus/automation/jsr223/python/community/mqtt_eventbus/. -> /etc/openhab2/automation/jsr223/python/community/mqtt_eventbus/.
      • Copy /Community/MQTT Eventbus/automation/lib/python/ -> /etc/openhab2/automation/lib/python/ (Rename existing to *.ORIG ?? Need it?)
      • Merge contents of /Community/MQTT Eventbus/automation/lib/python/ WITH /etc/openhab2/automation/lib/python/ & edit PUBLISHER or SUBSCRIBER sections as applicable
    • Add Broker Thing: Set IP/Hostname, QOS:2, ClientId: [openhabX], openhabian_mqtt / password
  • Install - Publisher:
    • Create Group item in /etc/openhab2/items/groups.items: Group:String PubItems
    • Add Items to this group (All items in this group will get published to an MQTT topic): eg.

Contact Door “Door [%s]” (PubItems) {channel=“zwave:device:415c59ca:node3:sensor_door”}

  • Install - Subscriber:
    • MQTT Broker: Add “Publish Trigger” Channel: ID:openhab1, label:subscription to openhab2, MQTT Topic:openhab2/out/#, Seperator character:#
    • Create all Items that will be synched ???
  • Restart openhab service: sudo systemctl restart openhab2
Logs around Errors:

2020-01-21 18:50:57.306 [INFO ] [ome.model.script.SubscribeMQTT.rules] - Subscribe update to the event bus
2020-01-21 18:50:57.310 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Subscribe for commands and updates from the event bus’: ‘split’ is not a member of ‘’; line 8, column 20, length 24
2020-01-21 18:50:57.464 [vent.ChannelTriggeredEvent] - mqtt:broker:40b306d8:openhab1 triggered openhab2_EB/out/Multisensor_Humidity/state#32
2020-01-21 18:50:57.472 [INFO ] [ome.model.script.SubscribeMQTT.rules] - Subscribe update to the event bus
2020-01-21 18:50:57.477 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule ‘Subscribe for commands and updates from the event bus’: ‘split’ is not a member of ‘’; line 8, column 20, length 24
2020-01-21 18:51:00.329 [DEBUG] [e.automation.internal.RuleEngineImpl] - The trigger ‘Time_cron_0_10_2b96c3003cb111ea867bdca6322133ca_2bf0068f3cb111eabc22dca6322133ca’ of rule ‘2d5e4294-5f63-4cd4-8346-a81fda7709f8’ is triggered.
2020-01-21 18:51:00.334 [.event.RuleStatusInfoEvent] - 2d5e4294-5f63-4cd4-8346-a81fda7709f8 updated: RUNNING
2020-01-21 18:51:00.356 [INFO ] [Jython Hello World (cron decorators)] - Hello World!
2020-01-21 18:51:00.358 [DEBUG] [e.automation.internal.RuleEngineImpl] - The rule ‘2d5e4294-5f63-4cd4-8346-a81fda7709f8’ is executed.
2020-01-21 18:51:00.360 [.event.RuleStatusInfoEvent] - 2d5e4294-5f63-4cd4-8346-a81fda7709f8 updated: IDLE

automation/lib/python/ config:

LOG_PREFIX = “jsr223.jython”
admin_email = “”
openhabHost = “localhost”
openhabPort = “8080”# “8443”
eb_in_chan = “mqtt:broker:40b306d8:openhab1”

Please let me know if there’s anything else I can supply!

I will stop saying anything along these lines. It seemed clear that acceptance of this pr above was all that was missing to get to install it through the usual add-ons mechanism, since oh 2 5 add-on development is continuing.

It also seemed clear that if python was going to become the default and Rules DSL completely eliminated that Python would just come with OH 3.

I’m getting lies of mixed messages regarding where this is all going so I’ll just shut up.

If your see that then your Python is installed and working. Reply in the event bus thread and we will debug further there.

Man I’m losing it! But isnt this the event bus thread? (Apologies)

Wait now I’m losing it. Too many threads going on.

Give me a day and let me redo the event bus stuff and post it here with better instructions.

You know I’ll be your guinea pig…and good or bad…give feedback :slight_smile: And when were done it’ll support NOOBS that never even heard of an event bus or Jython! lol We can either do it here or PM. Thank you Rich!

I’ve rewritten the OP to include the Python example rather than just the link to the PR on the Helper Libraries. See if you can follow the new tutorial as written above to copy over the Rules and get them to run.

Works like a charm. :grinning: Thanks Rich for your patience!

(For new readers, my Rules DSL error ‘split’ is not a member of ‘’ is now resolved via Richs OP.)

The “Subscribing” DSL code has a string detokenization bug if users configure their subscription channels in accordance with the screen shot (ie “#” as the “Separator Character”). The fix is:

var topic = receivedEvent.toString.split("#").get(0)
var state = receivedEvent.toString.split("#").get(1)
val itemName = topic.split("/").get(2)
val type = topic.split("/").get(3)

I’ve corrected the OP. It’s no secret that I don’t use Rules DSL any more so the error escaped detection before now. Thanks for the correction.

Worked fine for about a month now i get this error:

Rule ‘Publish updates to the local and cloud event bus’: Instance is not an MQTTActions class.

What is caussing this?

EDIT: Disabling and Enabling the Broker in the PaperUI solved the problem… How can we fix this?

Post the full error. Post the Rule as you have it implemented. If it happens again, file an issue on the MQTT binding. This isn’t directly related to the Event Bus rules, it’s something going on in the MQTT binding.

Sometimes this kind of thing turns out to be a variation on the file load time sequence issue.
If the “get actions” is a global, it gets executed during the chaos of startup, relying on binding and Things to be ready.

If its local in the rule, it should work better when that is the issue.

These are the rules that i’m running to communicate to the cloud mqtt and to the local mqtt:

rule "Publish updates to the local and cloud event bus"
    Member of PubItems received update
    val mqttActionsLocal = getActions("mqtt","mqtt:broker:local")
    val mqttActionsCloud = getActions("mqtt","mqtt:broker:cloud")

rule "Subscribe for commands and updates from the local event bus"
    Channel 'mqtt:broker:local:bus' triggered
    val itemName = receivedEvent.toString.split("/").get(3)
    val type = receivedEvent.toString.split("/").get(4)
    val state = receivedEvent.toString.split("#").get(1)

    if(type == "command") sendCommand(itemName, state)
    else postUpdate(itemName, state)

rule "Subscribe for commands and updates from the cloud event bus"
    Channel 'mqtt:broker:cloud:bus' triggered
    val itemName = receivedEvent.toString.split("/").get(4)
    val type = receivedEvent.toString.split("/").get(5)
    val state = receivedEvent.toString.split("#").get(1)

    if (type == "command") sendCommand(itemName, state)
    else postUpdate(itemName, state)

The full error that i get is this:

Rule ‘Publish updates to the local and cloud event bus’: Instance is not an MQTTActions class.

Like you already noticed, i did a few changes to the example above becausse i’m sending updates and recieving commands to/from 2 mqtt brokers (one localy and one in the cloud)

The wierd thing is that when i did a restart of the whole system it didn’t help :confused:
when i disabled the broker thing and enabled it back it was working fine again, and no error’s so far…
This happend 3 times so far.

Perhaps a better approach for that would be to bridge the two brokers and skip OH entirely for that part.

The problem is with the binding and not the Rules. There isn’t much I can do to help. You’ll need to file an issue on the binding.

Tnx for the feedback, i will post an issue to the Binding on GitHub

Oh, today i have the same error when starting the rule:

2020-04-23 22:31:41.188 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Request ZigBee Network Map in Graphviz format': Instance is not an MQTTActions class.

Command was send to local broker (mosquitto).

Starting what Rule? The name of the Rule in the error has nothing to do with the MQTT Even Bus.

This one:

val mqttActions=getActions("mqtt", "mqtt:broker:mosquitto")

rule "Request ZigBee Network Map in Graphviz format"
    Time cron "0 1 * * * ?" or
    Item zigbee_NetworkUpdate received command ON
    // ask zigbee2mqtt to generate graphviz network map (in DOT format)
    mqttActions.publishMQTT("zigbee2mqtt/bridge/networkmap", "graphviz")
    logInfo("zigbee_map", "DotFileState: " + zigbee_NetworkMap.state)

This rule working more then one year without any errors…until today (

OK, so it’s far better to post a new thread rather than reopening an old thread that has nothing to do with your problem.

But, if you are using the OP as an example for how to use the publishMQTT Action, you will notice a difference between your Rule and the example Rules above. The call to getActions and saving that to mqttActions is done inside the Rule. Try doing the same.