Page 1 of 1

How to get previous state

Posted: Tuesday 07 November 2017 8:58
by febalci
In my selector switch i have "Armed", "Stay" and "Disarm". In Lua script i want to get the condition of "When Disarm Mode is selected while in Armed position" so that i can write a coming home event. I can get the current state of the selector switch with otherdevices["switch"]. I can also get the last update time but how can i get the previous or last switch status before the last change? Any ideas?

Re: How to get previous state

Posted: Tuesday 07 November 2017 9:51
by Freemann
IN these cases I create an dummy device with the same name as the original "switch" with the addition "Prev"
So "AlarmSwitch" would be "AlarmSwitchPrev" and in my Lua Code I update the "Prev" switch on the end of my LUA code.

Code: Select all


if(otherdevices["AlarmSwitch"] == "On" and otherdevices["AlarmSwitchPrev"] == "Off" and )Then
-- do some magic
end

-- set the Prev switch to the current state, so on the next run we can check what the previous state of the switch was.
table.insert (commandArray, { ['AlarmSwitchPrev'] = otherdevices["AlarmSwitch"]})