Hi, I’m trying to retrieve a value from persistence using db4o in a rule but I have some problems.
I have an Item in a new binding and I want to restore it. From console I see that value is stored in db4o but I don’t know how read from db the last value.
when
Item PollerSwitch1 received command ON
then
logDebug(“REGOLA”, dimmer1.state.toString)
logDebug(“REGOLA1”, dimmer1.persist as String)
sendCommand(dimmer1, dimmer1.persist as DecimalType)
end
From debug I see:
dimmer1.persist is null
dimmer1.state is right value
dimmer1.lastUpdate I see the date of last update (correct)
dimmer1.previousState I see date and state
How can I send command and write dimmer1 state with persist value?
Take a look at the persistence extensions section in the wiki. However, if you set your persistence strategy to be everyChange then I would expect the last value in the persistence, and the current state of the item to be the same.
Hi Chris thanks for your reply, I see persistence extensions but why .persist value is null?
Sorry but I’m not a programmer so for me is not so easy to understand the problem.
So this is a command to allow you to persist a value into the database - not to read the last value. You probably want to look at using historicState() or previousState().
Thanks Chris, but I can’t able to find a solution to this problem…
I try to explain better the problem:
rule "memory test"
when
Item PollerSwitch1 received command ON
then
logDebug("REGOLA", dimmer1.state.toString)
logDebug("REGOLA1", dimmer1.historicState(now).toString)
sendCommand(dimmer1, dimmer1.historicState(now).toString)
}
end
dimmer1.historicState(now) give me a string and I can’t use as DecimalType. I’m sorry but I’m not a programmer and I don’t know ho to “extract” 23 from dimmer1.historicState(now) method.
// This rule file is autogenerated by HABmin.
// Any changes made manually to this file will be overwritten next time HABmin rules are saved.
// Imports
import org.openhab.core.library.types.*
import org.openhab.core.persistence.*
import org.openhab.model.script.actions.*
// Global Variables
rule "New Rule"
when
then
sendCommand(command, Item.historicState(now.minusSeconds(0)).state)
end
(note that there’s no when clause in the above since the Item doesn’t exist in my configuration, but normally this is added as well).