Trouble Getting MQTT Item to Trigger a Rule

Hi Everyone,

First of all, if any OpenHAB dev’s are reading this, thanks for helping support OpenHAB! I’ve been using it for just over a year now at my house and it’s been a ton of fun. I initially just used OpenHAB to control smart lights (GE Z wave/Philips HUE) but I recently started playing around with the MySensors Arduino Library to create my own sensor network and this has opened up a ton of new possibilities. So far, I’ve successfully setup the Mosquito MQTT broker on my Raspberry Pi, connected Mosquito to OpenHAB and connected Mosquito to my MySensors network bridge (ESP8266). I used “mosquito_sub” to verify that all my sensor nodes were working properly, so the next step was to link all the MQTT topics from my sensor network to OpenHAB items. Unfortunately, I’m missing something, because when one of my Items that’s linked to a motion sensor triggers a rule, I keep getting the error “An error occurred during the script execution”.

Here’s my information:
*Hardware: Raspberry Pi 3 Model B Rev 1.2

  • OS: Openhabian
  • Java Runtime Environment: (Zulu Embedded (build 1.8.0_152-b76)
  • openHAB version: 2.2.0-1

I’ve setup my MQTT connected motion sensor as follows in my .items file. The value returned from the sensor is a 1 or 0, so I used MAP to convert it to ON/OFF.

Switch Kitchen_Motion "Kitchen Motion" {mqtt="<[oh2:mygateway1-out/3/2/1/0/16:state:MAP(]"}

I can see in the event log that the motion sensor is being triggered properly because the state changes from ON to OFF, etc when I move around in the room.

2018-04-19 13:47:52.989 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from OFF to ON

==> /var/log/openhab2/openhab.log <==

2018-04-19 13:47:53.028 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test Motion Sensor Rule': An error occurred during the script execution: index=1, size=1

2018-04-19 13:47:55.213 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'Test Motion Sensor Rule': An error occurred during the script execution: index=1, size=1

==> /var/log/openhab2/events.log <==

2018-04-19 13:47:55.693 [vent.ItemStateChangedEvent] - Kitchen_Motion changed from ON to OFF

I’ve made my rule super simple just to try to eliminate errors caused by my noob status scripting skills.

rule "Test Motion Sensor Rule" 

	Item Kitchen_Motion received update ON

I know the sensor is working properly because I can see the sensor’s status change using mosquito_sub and through OpenHab’s event log, does anyone have any suggestions as to why the rule keeps failing when triggered?


The error is because logInfo needs two arguments. Try

logInfo("test", "test")

Thanks Pacive!!! Clearly, I haven’t written many .rules for my OpenHAB yet. I added the second argument and now everything works perfectly.

I recommend using VSCode with the openHAB extension. It will highlight these sorts of syntax errors as you type.

Thanks! I’ll check it out! I was using the plugin for Vim, but I may need more help :smile: