Persistence in OH2

I am coverting my OH1 to OH2 and now I am trying to get persistence working. I have a Group Item:

Group:Number:SUM()					Alarm_Presence				

I have both enabled mapdb and rrd4j persistence service and see the same behaviour for both serviecs.

rule "Alarm Presence Changed"
	Item Alarm_Presence received update 
        logInfo("TEST ", "Alarm_Presence HistoricState: " + Alarm_Presence.historicState(now.minusSeconds(1), "mapdb").state)
        logInfo("TEST ", "Alarm_Presence PreviousState: " + Alarm_Presence.previousState(false, "mapdb").state)

The problem is that it returns null as state.

Now I just wanted to test a little, so I modified the rule to this:

rule "Alarm Presence Changed"
	Item Alarm_Presence received update 
	logInfo("TEST ", "Alarm_Presence HistoricState1: " + Alarm_Presence.historicState(now.minusSeconds(1), "mapdb").state)
        logInfo("TEST ", "Alarm_Presence PreviousState1: " + Alarm_Presence.previousState(false, "mapdb").state)

            logInfo("TEST ", "Alarm_Presence HistoricState2: " + Alarm_Presence.historicState(now.minusSeconds(1), "mapdb").state)
            logInfo("TEST ", "Alarm_Presence PreviousState2: " + Alarm_Presence.previousState(false, "mapdb").state)

Now everything works as expected, or at least it is clear that the call to persist does the trick.

My persistence strategy for mapdb looks like:

	default = everyChange, restoreOnStartup

and for rrd4j if looks like:

	default = everyChange, everyMinute

For both rrd4j and mapdb I have also defined specific strategies, both they all look the same.

I remeber that I have had similar struggles in OH1, but I ended up using db4o, which seemed to work.
Any ideas why I have to do the explicit persist??

Have you tried everyUpdate instead of everyChange?

Nope, didn’t realize that it did exist.

If this works, the problem is caused by the fact that only changes to Alarm_Presence are being persisted but your rule triggers for any update, even when the update is to the same state. Consequently the data in mapdb is older than one second and therefore the call to historicState returns nothing.

I have tried your suggestion, it doesn’t do any difference!
But I have also tried to use

	*	: strategy = everyChange, restoreOnStartup

That did the trick. So it seems that if I have a Group Item that is member of my persistence group it doesn’t work, but if I catch the Items directly it does.

By the way I have just turned back to OH1, so my last update is done on OH 1.8.3