Sometimes rule sends old state instead of new

when using this pushover rule, it happens from time to time that the old state is send instead of the new

rule "Push"
when
	Item Push received update
then
	val pusholi = getActions("pushover", "pushover:pushover-account:oli")
	if (Bitte_nicht_stoeren.state == OFF) {
		pusholi.sendMessage(Push.state.toString.replace("ue","ü").replace("_"," ") + " " + new DateTimeType().format("%1$tk:%1$tM:%1$tS"), "openHAB")
	}
end

i fire up with something like this

Push.sendCommand("Die Post ist da!")

and i’m getting and old state (text)

can you help me to fix this?

Note that your rule triggers on update, not change. For some updates, before and after are the same.

1 Like

i cant use “changed” because it should send even when the state is the same
example:
when the post arrives and after some time new post arrives and in the time between no new push has send
is there any chance to fix the bug i described?

Perhaps you could demonstrate this bug with evidence? Item state logs perhaps.

That doesn’t seem to have much to with old/new states? It sounds now like your rule is being triggered when you don’t expect it.

i dont think you know what i mean
i cant use “changed” because i need to send every message which is executed by Push.sendCommand
even if it has the same content (“changed” will not send pushover if two times new post in mailbox arrives and between the two messages there was no new trigger with other content)
the bug is sometimes it sends old content when there was new content
i show you an example

2021-12-09 18:01:42.401 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Luftqualitaet_Flur' changed from 1569 to 1514
2021-12-09 18:01:42.573 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Technik_Kueche_links_W' changed from 0.4 to 0.6
2021-12-09 18:01:42.585 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Gesamt_W' received command 219.79999
2021-12-09 18:01:42.589 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Gesamt_W' changed from 219.59998 to 219.79999
2021-12-09 18:01:43.009 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Briefkasten_Ausloeser' changed from 3 to 1
2021-12-09 18:01:43.014 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Push' received command Die Post ist da! Batt: 3.09V
2021-12-09 18:01:43.016 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Push_Jule' received command Die Post ist da!
2021-12-09 18:01:43.019 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Briefkasten' received command ON
2021-12-09 18:01:43.029 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Push' changed from Bewegung Keller! to Die Post ist da! Batt: 3.09V
2021-12-09 18:01:43.031 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Push_Jule' changed from Bewegung Keller! to Die Post ist da!
2021-12-09 18:01:43.032 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Briefkasten' changed from OFF to ON
2021-12-09 18:01:43.279 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Luftqualitaet_Wohnzimmer' changed from 1708 to 1709

and

2021-12-09 18:03:54.301 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Luftqualitaet_Flur' changed from 1566 to 1538
2021-12-09 18:03:54.430 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Luftqualitaet_Wohnzimmer' changed from 1707 to 1699
2021-12-09 18:03:54.912 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'KeyMatic_Open' changed from ON to OFF
2021-12-09 18:03:54.977 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Briefkasten_Ausloeser' changed from 1 to 3
2021-12-09 18:03:54.981 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Push' received command Briefkasten entleert Batt: 3.09V
2021-12-09 18:03:54.986 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Push_Jule' received command Briefkasten entleert
2021-12-09 18:03:54.989 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Briefkasten' received command OFF
2021-12-09 18:03:55.005 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Push' changed from Alarm deaktiviert! to Briefkasten entleert Batt: 3.09V
2021-12-09 18:03:55.007 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Push_Jule' changed from Alarm deaktiviert! to Briefkasten entleert
2021-12-09 18:03:55.009 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Briefkasten' changed from ON to OFF
2021-12-09 18:03:55.250 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'TV_Schlafzimmer_W' changed from 20.9 to 20.8
2021-12-09 18:03:55.260 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Gesamt_W' received command 219.1
2021-12-09 18:03:55.264 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Gesamt_W' changed from 219.19998 to 219.1
2021-12-09 18:03:55.849 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Technik_Kueche_W' changed from 40.6 to 40.5
2021-12-09 18:03:55.860 [INFO ] [openhab.event.ItemCommandEvent      ] - Item 'Gesamt_W' received command 219.0
2021-12-09 18:03:55.864 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Gesamt_W' changed from 219.1 to 219.0

look for 18:01:43 and 18:03:54 on the screenshot, it does not match with the rule and log

the problems started with OH 3, under OH 2 this bug was not there

Fine, I didn’t tell you to use trigger changed. I wanted you to be aware that you can get duplicate messages if you trigger on update, because two updates may have the same value.
You are complaining about duplicate messages, after all.

If you are updating your Item very fast, there is the possibility of the Item state changing from what is was at trigger time while the rule is in progress. That wouldn’t give you “old” values, it would miss some out instead and give you duplicate “new” messages.

You should be able to avoid that by using newState implicit variable.

Okeydoke, the important parts -

2021-12-09 18:01:43.029 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Push' changed from Bewegung Keller! to Die Post ist da! Batt: 3.09V
2021-12-09 18:03:55.005 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'Push' changed from Alarm deaktiviert! to Briefkasten entleert Batt: 3.09V

Which should trigger your rule. Not shown here are any ‘updates-to-same’, which would also trigger your rule.

I can see a lot of Push messages, some of which may or may not have something to do with your rule.

I’d guess this is about Pushover, but let’s find out.
Add some logging so that you know when your rule is triggered and what it thinks it is trying to send.

rule "Push"
when
	Item Push received update
then
	logInfo("mypushrule", "Rule starts with state " + Push.state.toString)
	val pusholi = getActions("pushover", "pushover:pushover-account:oli")
	if (Bitte_nicht_stoeren.state == OFF) {
		pusholi.sendMessage(Push.state.toString.replace("ue","ü").replace("_"," ") + " " + new DateTimeType().format("%1$tk:%1$tM:%1$tS"), "openHAB")
	}
	logInfo("mypushrule", "Rule ends with state " + Push.state.toString)
end

I note you are sending several messages per minute - does Pushover work okay with that? I’ve no idea.