How to fetch new device state mid script in Lua?
Posted: Tuesday 13 February 2018 17:17
I am trying to setup a security Lua script which checks if a condition is true, sleeps for a time period then re-checks if the condition is true.
The issue seems to be that the script is not checking the new state of the switch after sleeping.
The idea of sleeping for the 9 seconds is to wait to see if a presence is detected (eg it can take time to detect a phone via WiFi or Bluetooth, so it pauses, then re-checks after x seconds).
Has anyone found a way to do this or should I be abandoning Lua for this particular task and using PHP or BASH?
The issue seems to be that the script is not checking the new state of the switch after sleeping.
Code: Select all
commandArray = {}
if (devicechanged['Main Entrance Door Sensor'] == 'Open' and otherdevices['Ben is Home'] == 'Off') then
os.execute("sleep " .. tonumber(9))
if (otherdevices['Ben is Home'] == 'Off') then
commandArray['SendNotification']='Security#The main entrance door was just opened'
end
end
return commandArray
Has anyone found a way to do this or should I be abandoning Lua for this particular task and using PHP or BASH?