Item update fires rule multiple times

  • Platform information:
    • Hardware: Raspberry Pi 3
    • OS: raspbian
    • Java Runtime Environment: openjdk 8
    • openHAB version: 2.5.0M1
  • Issue of the topic: please be detailed explaining your issue
  • Please post configurations (if applicable):
    • Items configuration related to the issue
Number:Temperature		Sensor_Salon_Temperature			"Salon Temperature [%.1f %unit%]" <temperature>	(gPersist, gMonitorLastUpdate)	{channel="mqtt:homie300:MQTTBroker:pi:salon#temperature"}
Number:Temperature		Sensor_Garden_Temperature			"Garden Temperature [%.1f %unit%]" <temperature> (gPersist)		{channel="mqtt:homie300:MQTTBroker:pi:ogrodek#temperature"}
Number                  Sensor_Salon_LastUpdate			"Timestamp [%d]" <clock>
Number                  Sensor_Salon_MinutesSinceUpdate	"Minutes since update" <clock> (gPersist)
String                  Sensor_Salon_SinceUpdate			"Time since update" <clock>
  • Rules code related to the issue
rule "LastUpdate"
when
    Member of gMonitorLastUpdate received update
then
    val time = new DateTimeType()
    val namePrefix = triggeringItem.name.toString.substring(0, triggeringItem.name.lastIndexOf('_'))
    logInfo("lastUpdate", "Result:" + triggeringItem.name + " | " + namePrefix)
    //postUpdate(namePrefix + "_LastUpdate", time.getZonedDateTime.toInstant.toEpochMilli.toString) 
end
  • If logs where generated please post these here using code fences:
2019-04-06 23:00:14.848 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.854 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.861 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.861 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.875 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.874 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.871 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.877 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon
2019-04-06 23:00:14.887 [INFO ] [se.smarthome.model.script.lastUpdate] - Result:Sensor_Salon_Temperature | Sensor_Salon

Sensors are being updated using a script that is run from cron:

*/2 5-22 * * * /home/pi/sensors.sh

sensors.sh:

#!/bin/sh
MOS_IP=pi

OGRODEK=$(cat /sys/bus/w1/devices/28-0000035a5030/w1_slave | awk -F= '/ t=/ {print $NF/1000.0}')
mosquitto_pub -h $MOS_IP -r -t homie/pi/ogrodek/temperature -m "$OGRODEK"
echo $(date +%Y-%m-%dT%H:%M:%S) $OGRODEK >> /tmp/temp-ogrodek-$(date +%Y-%m-%d).txt

SALON=$(cat /sys/bus/w1/devices/28-000003bb3a34/w1_slave | awk -F= '/ t=/ {print $NF/1000.0}')
echo $(date +%Y-%m-%dT%H:%M:%S) $SALON >> /tmp/tempi-salon-$(date +%Y-%m-%d).txt
mosquitto_pub -h $MOS_IP -r -t homie/pi/salon/temperature -m "$SALON"

(the rest of homie is in sensors-schema.sh:

MOS_IP=pi
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/$homie' -m "3.0"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/$name' -m "Raspberry PI w salonie"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/$state' -m "ready"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/$extensions' -m ""
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/$nodes' -m "ogrodek,salon"

mosquitto_pub -h $MOS_IP -r -t 'homie/pi/ogrodek/temperature/$name' -m "Temperatura"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/ogrodek/temperature/$unit' -m "°C"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/ogrodek/temperature/$datatype' -m "float"

mosquitto_pub -h $MOS_IP -r -t 'homie/pi/ogrodek/$name' -m "Ogrodek"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/ogrodek/$properties' -m "temperature"

mosquitto_pub -h $MOS_IP -r -t 'homie/pi/salon/temperature/$name' -m "Temperatura"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/salon/temperature/$unit' -m "°C"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/salon/temperature/$datatype' -m "float"

mosquitto_pub -h $MOS_IP -r -t 'homie/pi/salon/$name' -m "Salon"
mosquitto_pub -h $MOS_IP -r -t 'homie/pi/salon/$properties' -m "temperature"

)

The issue is that the rule is run 247 times per second for that sensor, but the sensors.sh file is executed only once per 2 minutes.
I have two other items marked with the group that is run in the rule, and one of them is executed correctly only once, and the second one is executed 4 times per each update.

Why this might happen? Do I have somewhere a bug or is it a bug in 2.5.0M1? Why one item is being updated correctly only once?

And BTW. why I don’t see the value of the updated items in Control on Paper UI (when I uncomment postUpdate)?

What is in events.log? Is that Item getting multiple events or just the one event and the Rule is triggering lots of times?

The origina items are updated only once, only the newly added LastUpdate which are postUpdate in rule are being updated multiple times.

BTW. Now the LastUpdate is updated different number of times, one is updated 3 times, the other 4 times.

What is happening here?
I cleaned cache, restarted openhab multiple times.

When I disable the postUpdate and do just the logging I have exactly the same situation, 3 or 4 times the same log appears.

When I changed the Member of gMonitorLastUpdate received update to Member of gMonitorLastUpdate changed I the rule is executed correctly only once (or never if there was no change).

Please post your code as it exists now and your logs.

I’m curious if you see the multiple triggers if you change the trigger to…

Item Sensor_Salon_Temperature received update

… as this could eliminate Member of from the equation.

I doubt this is important, but how is the group defined?

Please show the logs, and the output for the device from sensors.sh.

Only Items linked to Channels will show up there. You will need to setup a UI for displaying Items. Paper UI is only for administration.