How to use .previousState(true) correctly?

Hi, i need to get an old item state. .previousState(true) looks fine for me.


Strategies {
    default = everyChange

Items {
    *: strategy = everyChange, restoreOnStartup


rule "Test"
    //something triggers
    logInfo("Persistence", item1.previousState(true))
    logInfo("Persistence", item1.previousState(true).state)
    logInfo("Persistence", item1.previousState())
    logInfo("Persistence", item1.previousState().state)

All of them result in null

What am i doing wrong?

Script execution of rule with UID 'myRule-1' failed: cannot invoke method public abstract org.openhab.core.types.State org.openhab.core.persistence.HistoricItem.getState() on null in myRule

mapdb only stores the last value - not a history of values.

ah dammit. Which persistence add on is perfect to store EVERY value, no matter if its decimal or text, and stores historicItems?

That would be all execpt mapDB and rrd4j, I think.

What is your real use case? If you do need the state just before an actual change you could use a rule with a “changed” trigger. In this rule the implicit variable “previousState” would be your needed state.

I want an item to store the “Temperature when not home” and update the targettemperature from each thermostat, when i am not home with that value.
When i am back home, i want the thermostat to be updated with the last state i had, before i left my home.

So the implicit variable previousState is not working for me.

You can configure more than one persistence service, for different purposes.
Each service can be configured to operate with a selection of Items, the selections may overlap.
When you access persistence from rules, you can select service by name or rely on going to a default service that you choose.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.