[SOLVED] Item receives update but rule does not fire

  • Platform information:
    • Hardware: _CPUArchitecture/RAM/storage_Rpi 3B, 16 GB SD-card
      Openhabian 2.3.0 build #1209

I have a rain gauge reporting rain every five minutes. The amount is reported in the item Number Fryk_Rain via an MQTT message. The message is sent every five minutes no matter if there is rain or not.
These are the item definitions

Number	Fryk_Rain				"Regn 5 min. [%.2f mm]"			<rain>			(gFrykin, gRain)		{mqtt="<[ib9sensors:ib9sensors-out/43/1/1/0/6:state:default]"}
Number	Fryk_Rain_Acc			"Regn under dygnet [%.1f mm]"	<rain>			(gFrykin)
Number	Fryk_Rain_Last			"Regn förra dygnet [%.1f mm]"	<rain>			(gFrykin)

I try to accumulate the rainfall during the day with the following rule(s):

// Accumulate rain readings

	var Number rainThisDay = 0
	var Number rainLastDay = 0
	
	
	rule "Reset rain this 24 hrs"
	
	when
		Time cron "0 59 23 * * ?"
		
	then
		rainLastDay = rainThisDay
		Fryk_Rain_Last.postUpdate(rainLastDay)
		rainThisDay = 0
		
	end	
	
	
	rule "Accumulate rainfall"
	
	when
		Item Fryk_Rain received update
		
	then
		rainThisDay = rainThisDay + Fryk_Rain.state as DecimalType
		Fryk_Rain_Acc.postUpdate(rainThisDay)
		
	end

The issue is that if the rainfall during a number of 5 minute periods is the same, the rule does not fire. The MQTT does report a new measurement but if the reported value is the same, for some reason this is not perceived as an update it seems. If every MQTT message is different, the accumulation works.

Change the incoming binding to a command

Number	Fryk_Rain				"Regn 5 min. [%.2f mm]"			<rain>			(gFrykin, gRain)		{mqtt="<[ib9sensors:ib9sensors-out/43/1/1/0/6:command:default]"}

And then your rule:

rule "Accumulate rainfall"
when
    Item Fryk_Rain received command
then
    rainThisDay = rainThisDay + Fryk_Rain.state as DecimalType
    Fryk_Rain_Acc.postUpdate(rainThisDay)
end

Thank you for the quick reply @vzorglub! I will update and wait for the next rainfall.:grinning:

You don’t need to wait. If there is no rainfall, the command should be received every 5 minutes as you said above and report a 0
The received update will only trigger with the mqtt binding if the value has changed
Monitor your log and you should be a command received every 5 minutes with a value of 0

Yes, Updates are visible in the log. Thanks again!

Coolio, please mark the thread as solved, Thanks