No .historicState after restart

Hi everyone,

This may be out of the scope what persistence in openHAB was intended for, but I wanted to double-check:

I have a persistence service configured and running (mariaDB). I have a few items that are being persisted once a day and are being restored on startup.
These items contain location data from a gpstracker. I also extended my sitemap to allow me to enter a date, so that I can view historical tracker data by choosing a date in the past. This works very well until I restart the openhab system.

It seems to me that the restoreOnStartup flag restores the last state of an item, but when I then try to access past historical states through the .historicState function it doesn’t work, while it does work during runtime.
The data however is in the database but apparently it doesn’t even attempt to access it.

Is that how restoreOnStartup is supposed to work or is there a way to restore Items so that you can still access past data through .historicState.

Thanks!

Show us what you do, show us what happens.

Key concept: you may have multiple persistence services. If you don’t tell a function which to use, there is a system default choice. What’s your default, or are you selecting?

OH3 installs rrd4j by default, like it or not. We don’t know what OH version you are using.

I am using openHAB 2.5 and I have installed jdbc/mariadb persistence service and selected it as default.

I also have the following jdbc.persist settings:

Strategies {
    everyMinute    : "0 * * * * ?"
       every15Minutes   : "0 */15 * ? * *"    
       everyHour   : "0 0 * * * ?"
       everyDay    : "22 0 * * * *"
       default = everyChange
}
 
Items {
    
        Person1LocationHistory, Person1LocationTimeHistory, Person2LocationHistory, Person2LocationTimeHistory, Person3LocationHistory, Person3LocationTimeHistory, Person4LocationHistory, Person4LocationTimeHistory  : strategy = everyHour, restoreOnStartup
    
    }

I then have a rule detecting changes to my DatePicker which loads the historical values:

rule "history locations"
when
    Member of Datepickers changed
then
    HistPerson1LocationHistory.postUpdate(Person1LocationHistory.historicState(new DateTime(year.state.toString + "-" + month.state.toString + "-" + day.state.toString + "T23:59:00.000")).state.toString)
    HistPerson1LocationTimeHistory.postUpdate(Person1LocationTimeHistory.historicState(new DateTime(year.state.toString + "-" + month.state.toString + "-" + day.state.toString + "T23:59:00.000")).state.toString)
    HistPerson1Location.postUpdate(new PointType(Person1LocationHistory.state.toString.split(";").get(Person1LocationHistory.state.toString.split(";").size-1)))

This is working while the system is running. But after a restart today (first one since I built this) the .historicState give back NULL values.

I am wondering whether this is related to the fact that I only put the restoreOnStartup in the jdbc.persist file after my first restart today. I would still expect it to now load my previously persisted values, as I would expect it to load values from before the second last restart as well.

Really unlikely to be related to restoreOnStartup.
Possibly more something to do with editing persist file, changed table names or types or something.
Use REST API to inspect openhab’s idea of what is stored per Item (you may need to look beyond default 24 hrs)

You’re mixing/misunderstanding things.
For items you specify to use restoreOnStartup, only ever the LAST value is persisted.
All other values are dropped/forgotten about (unless you specify additional persistence options such as everyChange).
When you use historicState, you query for the state at a certain point in past times. But that wasn’t recorded because you didn’t tell it to.

On a sidenote, you should use a separate persistence service (preferrably mapdb) for restoreOnStartup and for your existing service to handle the ‘real’ persistence.

Thanks for the tip. I learned about the REST API and it turned out that openhab did have knowledge of these persistend items and their historical states.
For some weird reason my Datepicker group was empty and the rule never triggered. I found my items being defined multiple times in different .item files. After cleaning it up everything worked as expected. So this was not at all related to a persistence issue. Sorry for that and thanks for the help!!
Regards!

I have been using my “everyHour” strategy all along. I figure now that I may not even need to the restoreOnStartup, but I would still be able to use historicState (given that it has been persisted in the past).