SOLVED: MQTT item not updated from rule, but works from sitemap

Platform information:
Hardware: Raspberry PI 4
OS: Raspbian
Java Runtime Environment: which java platform is used and what version
openHAB version: 2.5
When changing a switch from the sitemap the item receives the command, but when using a rule to do the same the change is not triggered all the way.

String MQTT_varasto_fan “MQTT Varasto tuuletin [%s]” { channel=“mqtt:topic:mosquitto:MQTT_Storage_temperature::MQTT_storage_fan” }

Switch item=MQTT_varasto_fan label=“Varaston tuuletin [%S]” valuecolor=[ON=“red”,OFF=“black”]

logInfo(“Sami”,“Storage temperature updated - checking if FAN needs to be on”)
if((MQ_Varasto_temp > Varasto_temp_upper) && (MQ_Varasto_temp > MQ_Ulkoilma_temp))
logInfo (“Sami”,“Storage fan has received ON command”)
Rule based log:
12:32:06.991 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘Varasto_temp_sp’ received command 20
12:32:07.012 [INFO ] [smarthome.event.ItemStateChangedEvent] - Varasto_temp_sp changed from 19 to 20
12:32:07.018 [INFO ] [g.eclipse.smarthome.model.script.Sami] - Storage FAN rule evaluation started
12:32:07.026 [INFO ] [g.eclipse.smarthome.model.script.Sami] - Storage temperature updated - checking if FAN needs to be on
12:32:07.035 [INFO ] [g.eclipse.smarthome.model.script.Sami] - Storage fan has received ON command
12:32:07.035 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘MQTT_varasto_fan’ received command ON

Sitemap triggered log:
12:32:12.480 [INFO ] [smarthome.event.ItemCommandEvent ] - Item ‘MQTT_varasto_fan’ received command ON
12:32:12.494 [INFO ] [arthome.event.ItemStatePredictedEvent] - MQTT_varasto_fan predicted to become ON
12:32:12.504 [INFO ] [smarthome.event.ItemStateChangedEvent] - MQTT_varasto_fan changed from OFF to ON

You have a double colon ( : ) before MQTT_storage_fan. Is that causing the issue from rules?

1 Like

You only get a ‘changed’ event if it is not already ON. No indication here what the state was before or after your command


Thanks for the answer - for testing purposes I turned it OFF before the test (from the sitemap - as that works).

Then I triggered the rule to see what the outcome &log entries would be.

-> It sent the command, but did not change the state of the fan

Then after that I used the sitemap to turn the fan on & see the log entries.

As far as I can tell the difference between using the sitemap and the rule lies in 2 log lines:
12:32:12.494 [INFO ] [arthome.event.ItemStatePredictedEvent] - MQTT_varasto_fan predicted to become ON
12:32:12.504 [INFO ] [smarthome.event.ItemStateChangedEvent] - MQTT_varasto_fan changed from OFF to ON

-> These appear when using the sitemap, but not when the rule is run…

Thank you for the response. I removed those additional ones - with no effect on the outcome.

The items are used in both the sitemap and rules, so errors in the items should impact both - here there is a difference in the way OpenHab handles the situation after the command has been received.

I managed to solve it - through your help I took one more look at the items file, and the type “String” caught my eye.

The change in the rule was to change from:

As the item is a string item in the mqtt definition file.

Thank you for your help.

1 Like