How to use .previousState(true) correctly?

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

mapdb.persist

Strategies {
    default = everyChange
}

Items {
    *: strategy = everyChange, restoreOnStartup
}

.rules

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

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.

Reminders
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.