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