How to fetch new device state mid script in Lua?

Moderator: leecollings

Post Reply
ben53252642
Posts: 543
Joined: Saturday 02 July 2016 5:17
Target OS: Linux
Domoticz version: Beta
Contact:

How to fetch new device state mid script in Lua?

Post by ben53252642 »

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.

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
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?
Unless otherwise stated, all my code is released under GPL 3 license: https://www.gnu.org/licenses/gpl-3.0.en.html
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 1 guest