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"
when
Item Alarm_Presence received update
then
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"
when
Item Alarm_Presence received update
then
logInfo("TEST ", "Alarm_Presence HistoricState1: " + Alarm_Presence.historicState(now.minusSeconds(1), "mapdb").state)
logInfo("TEST ", "Alarm_Presence PreviousState1: " + Alarm_Presence.previousState(false, "mapdb").state)
Alarm_Presence.persist("mapdb")
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??