- Platform information:
- Hardware: Raspberry Pi 3 B+, 120gb mSATA SSD in a USB enclosure
- OS: Raspbian Stretch
- Java Runtime Environment: 1.8.0_212
- openHAB version: 2.4.0 release build. Jython 2.7.0
Today seemed like a good day to start down the MQTT route for the first time.
I tried for a while (mistakenly) to follow Openhab 1.x tutorials to define subscriptions directly in items, and of course got nowhere. Once I figured out why (wrong Openhab version, completely different architecture) I found this example which seemed like the closest way to get multiple topics MQTT messages into a jython script for further processing.
So, here’s my question.
Why does this work just fine:
rule "Topic and Payload"
when
Channel "mqtt:broker:local:LivingRoom433" triggered
then
var rawevent = receivedEvent.toString.split(" ").get(2).split("#")
var topic = rawevent.get(0)
var payload = rawevent.get(1)
logInfo("Topic", topic + ", " + payload)
end
But this results in an error as below:
@rule("MyRule", description="", tags=["utility"])
@when("Channel mqtt:broker:local:LivingRoom433 triggered")
def MyRule_Decorators(event):
log.debug("hello");
2019-06-23 21:21:28.753 [INFO ] [rt.internal.loader.ScriptFileWatcher] - Loading script 'python/personal/kitchen_fans/kitchen_fans.py'
2019-06-23 21:21:28.860 [ERROR] [jsr223.jython.core.triggers ] - when: Exception [when: "Channel mqtt:broker:local:LivingRoom433 triggered" could not be parsed because Channel "mqtt:broker:local:LivingRoom433" is not a trigger]: [Traceback (most recent call last):
File "/etc/openhab2/automation/lib/python/core/triggers.py", line 370, in when
raise ValueError("when: \"{}\" could not be parsed because Channel \"{}\" is not a trigger".format(target, trigger_target))
ValueError: when: "Channel mqtt:broker:local:LivingRoom433 triggered" could not be parsed because Channel "mqtt:broker:local:LivingRoom433" is not a trigger
]
2019-06-23 21:21:28.867 [ERROR] [ipt.internal.ScriptEngineManagerImpl] - Error during evaluation of script 'file:/etc/openhab2/automation/jsr223/python/personal/kitchen_fans/kitchen_fans.py': TypeError: 'NoneType' object is not callable in <script> at line number 33
What am I missing?