Storing state for Thing

What is the best / most “openHAB-way” to store a (Hash)Map from a Thing?
In this case I have a Map with the 10-20 latest used Apps for my PlayStation binding, both key and value are Strings. This is per Thing/PlayStation.
I have everything working, just want the Map to be restored if openHAB is restarted.

The openHAB way is to not store state in the binding. But to configure to restore state on startup, but I don’t know if this is possible for list states and not specific for a binding.
Is this list something you track in the binding or is it something the device provides?

This is something I track in my binding for convenience to the user (if they want).
If I could read it from the PlayStation I would not try to store the map.

I was wondering pretty much the same. I’m reading ‘all time total power’ from a device, but I would also like to provide ‘total power since midnight’. So for that I would need to remember ‘total power at midnight’, even after a restart of my binding.

But I guess, in line will hilbrand’s answer, this should not be the responsibility of a binding or a thing.

openHab can persist the ‘all time total power’ state for every change (or at midnight) and within rules/widgets where I want to use ‘total power at midnight’ I can ask for the historic state of ‘all time total power’ (though I can’t find how exact the timestamp must be in the historicState() call, or whether there is a stateClosestToTimestamp() call)

Alternatively I guess I could create a rule that copies the current ‘all time total power’ state into a ‘power at midnight’ state if that has a time stamp from the previous day and enabled restore on start up for that one.

I think you’re asking “how it works”. The assumption is that a persisted state remains valid until the next persisted state is recorded. So historicState() returns the next-oldest record from before the designated time, because as you say you’ll never guess the exact time of a record.

Note that the existence of records will depend on how you chose to configure your persistence - everyChange, everyMinute etc. and you might need to take that into account in how you interpret results.

The returned state could of course be weeks old if it was never updated, but it does come with a timestamp if you are interested in that.

1 Like

The idea of bindings is that they are only interfaces to devices and don’t do add anything. This keeps it clean. For example. If the binding misses a last app, due to some communication issue, the binding won’t show it and the user wonders why, because the user expects what comes from the binding to be exactly what the device did.

I thought so, but I wanted to hear it from you :wink: