Question about persistence restoreOnStartup

Hello,
I have a question i have the following item in my sitemap

item:

Number number_openhab2operatingmodus_specialmode "Operating Modus"

sitemap

Switch item=number_openhab2operatingmodus_specialmode label="Operating Modus" icon="line" mappings=[0="Urlaub", 1="Alarm", 2="Aus"]

persistance

number_openhab2operatingmodus_specialmode : strategy = everyChange, everyDay, restoreOnStartup

But this value is not restored at startup?? What is wrong??

I tried to restore it with

number_openhab2operatingmodus_specialmode.postUpdate(number_openhab2operatingmodus_specialmode.historicState(now).state.toString)
    logInfo("number_openhab2operatingmodus_specialmode", number_openhab2operatingmodus_specialmode.historicState(now).state.toString)

but also not working…

You did not tell us whether you configured a persistence service. For persistence to work, you have to define which database you would like to store your values in. The easiest is to use mapDB for restore on backup, but watch out, it only stores the last value, but then it is fast and easy, which you want for your purpose.

The persistence is configured and working it’s mysql

well, then the next question is what does your log file say? Check back for any errors.

Nothing really…the log for the second try is

2020-03-13 21:24:00.448 [INFO ] [r_openhab2operatingmodus_specialmode] - 2.0

But the item is not updated @lipp_markus

second try?
Your test rule is flawed - postUpdate is asynchronous and your rule will not stop and wait for it to take effect before carrying to do the logInfo().
In short, the logInfo will tell you old state from before the postUpdate.

More useful would be the actual events.log

The other potential problem with your test rule is that you allow historicState() to go to the default database. Are you sure that is mySQL ?

When you only update your item, you should use everyUpdate in the persistence and not everyChange.
Just a guess but i’ve had a similar problem…

Hi,
I’ve the same behaviour with release 2.5.1 and mysql.
On restart, no button is red although the number of the switch retrieves the good value.
My item file:
Number clim_cmd “Chauffage [%d]” (gClim, gTEST)

My sitemap file:
Switch item=clim_cmd label=“Chauffage” mappings=[1=“ON”,3=“19°”,4=“20°”,6=“OFF”,7=“AUTO”]

My mysql.persist:
clim_cmd : strategy = everyChange, restoreOnStartup

Like milo I use a reference number for the switch item.
I don’t know if it is bug but this behaviour doesn’t exist on the previous release I used which was 2.0.0 and which was working correctly with the same code.

As I add “%d” on my item, I am able to check that clim_cmd is correctly retrieve after a restart but no button is red.

Regards,
Nicolas

@sac Did you find a solution?
I have the same issue: I can see that the value is restored, but the button on sitemap is not highlighted.
Item type is Number as I need several heating modes.

My config:

items:
Number AI_GR_HeatingMode (g_room_heat)

mapdb.persist:
g_room_heat* : strategy = everyChange, restoreOnStartup 

sitemap:
Switch item=AI_GR_HeatingMode label="Mode" mappings=[0="Auto",1="Manual"]
Text item=AI_GR_HeatingMode label="Mode [%s]"

I can see the value is set to 1 on sitemap, but the button ‘Manual’ is not highlighted. When I press ‘Manual’ - it becomes highlighted, and text value ‘Mode’ does not change (remains 1 as it was). Any ideas why button is not synchronized with the value?

Thanks.

If you inspect the actual Item state using REST API, you’ll probably find the restored state is e.g. 1.0 (rather than just 1).

Exactly. Thank you.

This mapping worked:
Switch item=AI_GR_HeatingMode label="Mode" mappings=[0="Auto",1.0="Manual"]

Is it safe to leave it like this or there is another solution to get rid of the extra decimal?
All my rules check for ‘item.state==1’ - don’t think there can be a problem.

When it actually is state 1 then you won’t get your red button.

I think which persist/restore service you use may influence whether you get a 1 or 1.0 from restore. Maybe Mapdb does his cleanly.

Why don’t you use Switch type Item for just two states?

@rossko57
I am already using mapdb for storing this particular value.
I need Number as example above is just a simplified example. Actually there are more options like: Auto, Manual, Override, NoOneThere.

Thanks for the tip. I found (via REST API) that a lot of values were stored in rrd4j service (I forgot it was running by default for OH3). It interfered with my mapdb settings. Thus the issue.
I have created a new file rrd4j.persist with the text:

Strategies {
	everyMinute : "0 * * * * ?"
	everyHour : "0 0 * * * ?"
	everyDay : "0 0 0 * * ?"
	default = everyChange
}

Items {
    
}

Now everything works as expected.
Thank you!

1 Like

Don’t forget rrd4j provides the default charting,you may want to put some Items back there.
You can actually setup with * to persist all like the default setup; but you don’t have to restore, unlike default.

1 Like