I have troubles with the previousState for a String Item.
what is the correct syntax to check the previousState?
I`ve setup RRJ4D and MapDB as persistences…
CallState.previousState.state == “IDLE”
var Number Volumememory = 0
rule "Call State Trigger"
when
Item CallState changed
then
if (CallState.state == "IDLE") {
if (Matthias_Handy.state == ON) {
logInfo("CallState", "IDLE")// No call activity
SqueezeboxVolume1.sendCommand(Volumememory)
}
}
else if (CallState.state == "RINGING") {
if (Matthias_Handy.state == ON) {
Volumememory = SqueezeboxVolume1.state as Number
SqueezeboxVolume1.sendCommand(30)
//Player_Office.sendCommand(PAUSE)
logInfo("CallState", "Ringing")// A new call arrived and is ringing or waiting. In the latter case, another call is already active.
}
}
else if (CallState.state == "OFFHOOK" && CallState.previousState.state == "IDLE") {
if (Matthias_Handy.state == ON) {
SqueezeboxVolume1.sendCommand(30)
Volumememory = SqueezeboxVolume1.state as Number
//Player_Office.sendCommand(PAUSE)
logInfo("CallState", "Offhook")// At least one call exists that is dialing, active, or on hold, and no calls are ringing or waiting.
}
}
end
rule " test"
when
Item VSwitch1 changed
then
logInfo("testrule", "Callstate: "+CallState.previousState().state
end
output is “0.0” 2019-12-11 10:36:31.065 [INFO ] [ipse.smarthome.model.script.testrule] - Callstate: 0.0
but the Callstate is either “IDLE”, “OFFHOOK” or “RINGING”…
There are two completely different things called previousState.
One is an implicit variable , that exists in any rules with a changed trigger. It’s derived from the changed event, not from the Item, not from persistence.
logInfo(“test”, "implicit " + previousState)
The other is a method of an Item to access persistence. Obviously any results there depend on if/how your Item is persisted and your service defaults.