My rule is not being triggered by MQTT topic publish

Hi I have a rule setup in the openhab configurations files to listen to a change in the item attached to an mqtt subcription.

Item:

Number fsr1 {mqtt="<[home:test/fsr1/out:state:default]"}

Rule

rule "test"
when 
  Item fsr1 changed
then
  logInfo("test","*** test ***")
end

I am using a Mosquitto broker running on raspberry pi, the openhab server is also running there too.

I have run start_debug.sh to see what is happening and I have the following to report.

20:55:30.041 [INFO ] [.io.transport.mqtt.MqttService:108  ] - MQTT Service initialization completed.
20:55:30.044 [INFO ] [o.i.t.m.i.MqttBrokerConnection:114  ] - Starting MQTT broker connection 'home'
20:55:30.058 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:294  ] - Creating new client for 'tcp://192.168.1.80:1883' using id 'OpenHabClient' and file store '/tmp/home'

20:56:00.257 [DEBUG] [.b.mqtt.internal.MqttActivator:34   ] - MQTT binding has been started.
20:56:00.320 [DEBUG] [i.internal.GenericItemProvider:341  ] - Start processing binding configuration of Item 'fsr1 (Type=NumberItem, State=Uninitialized)' with 'MqttGenericBindingProvider' reader.


20:56:00.342 [DEBUG] [b.mqtt.internal.MqttItemConfig:71   ] - Loaded MQTT config for item 'fsr1' : 1 subscribers, 0 publishers
20:56:00.346 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:476  ] - Starting message consumer for broker 'home' on topic 'test/fsr1/out'
20:56:00.370 [DEBUG] [i.internal.GenericItemProvider:341  ] - Start processing binding configuration of Item 'feedingMusic (Type=StringItem, State=Uninitialized)' with 'MqttGenericBindingProvider' reader.

20:57:46.859 [INFO ] [runtime.busevents             :26   ] - fsr1 state updated to 1023

When i use MQTTLense to publish a value to the topic the rule is not triggered at all.

P.s I am using openhab 1.7.0 and have made sure that that the addons folder has the correct .jar files there.

Any help would be much appreciated.

Try changing your rule trigger to;

Item fsr1 updated

If the value is updated but doesn’t actually change, then your changed trigger will not fire.

I tried that but still I just get

21:40:32.979 [INFO ] [runtime.busevents :26 ] - fsr1 state updated to 1022

Im confused as it used to work so well and then it just stopped. I have tried deleting the openhab directory and starting from scratch. This didn’t work either.

It seems like the rule is not being triggered. I think the mqtt binding is ok and the item file is ok too as I get the recognition in the log file that there has been a change to the topic.

Where are you looking for the *** test *** logging? Should be in openhab.log.

I expect to see the message from the rule in the terminal console from where i invoked start.sh

I used to see all messages here that are posted to the the log. Essentially what is in openhab.log will also show in the terminal console window.

Do you see your rule file being loaded in the startup log?

Yes I see that, here is the extract from the log

20:56:00.320 [DEBUG] [i.internal.GenericItemProvider:341  ] - Start processing binding configuration of Item 'fsr1 (Type=NumberItem, State=Uninitialized)' with 'MqttGenericBindingProvider' reader.
20:56:00.342 [DEBUG] [b.mqtt.internal.MqttItemConfig:71   ] - Loaded MQTT config for item 'fsr1' : 1 subscribers, 0 publishers
20:56:00.346 [DEBUG] [o.i.t.m.i.MqttBrokerConnection:476  ] - Starting message consumer for broker 'home' on topic 'test/fsr1/out'

Btw thank you in advance for your time, I really appreciate it.

I may have to hit the bed wake up to look at this tomorrow

You need to see a line in the startup log saying your rule file was loaded. It is possible the permissions on the file with your rule prevent it from being seen by openHAB and thus the rule is never getting loaded.

1 Like

How would I change the permissions on the file? and which file would it be?

The file that contains your rule.

do you mean using chmod ?

I have changed the permissions using chmod 777 on opt/openhab/configurations/rules/home.rules

Could it be that there is some config that is pointing at a default rules file and not my own one that I have which is home.rules

You just need to check the openHAB logs during startup to see if the home.rules file is being loaded. There will be a line indicating every rule file that gets picked up.

I tried setting up version 1.8.0 on my windows machine and running the mosquitto broker locally too and it all works fine.
This evening i’ll try to copy all the files straight to my raspberry pi and hopefully that should work.

You maybe right in that there might be a permissions issue.

Have you ever ran openhab on a raspberry pi?

Many Thanks

If your rules are under /opt, then you probably didn’t use the apt-get method of installing openHAB, which might solve permissions or other issues.

I used the following commands to install openhab

sudo mkdir /opt/openhab
cd /opt/openhab
sudo wget https://bintray.com/artifact/download/openhab/bin/distribution-1.7.1-runtime.zip
sudo unzip distribution-1.7.1-runtime.zip
sudo rm distribution-1.7.1-runtime.zip

Is this not right? If not are there any website that use the apt-get method, I couldn’t find any

The official docs should work, and it has the advantage of easy upgrades. Your method works but results in differences and may require knowledge of things that the apt-get method doesn’t.

1 Like