How to get previous state
Moderator: leecollings
-
- Posts: 331
- Joined: Monday 03 July 2017 19:58
- Target OS: NAS (Synology & others)
- Domoticz version:
- Contact:
How to get previous state
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?
-
- Posts: 94
- Joined: Thursday 24 November 2016 14:55
- Target OS: Linux
- Domoticz version: >=Béta
- Location: Netherlands
- Contact:
Re: How to get previous state
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.
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"]})
Domotica/graphs "freak" :)
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam
https://www.frijduurzaam.nl
NUC8i3BEH(8gb/250gb),
Lubuntu 19.04,
Aeotec Z-Stick S2(Gen5)
HarmonyElite
HUE(5 bulbs, 2 blooms)
NetAtmo(complete setup)
MiLight iboxV6(2 MiLightBulbs)
IP-Cam
https://www.frijduurzaam.nl
Who is online
Users browsing this forum: No registered users and 1 guest