I'v some problems with my first LUA script. Below i placed 2 parts of my script (i believe those are wrong) and complete script. Can you guys help me to fix the problems? No errors appears, but script is only working for a small part.
Code: Select all
if (otherdevices['Alarm'] == 'On') then
if (otherdevices['Alarm Trigger'] == 'Off' and otherdevices['Eetkamerdeur'] == 'On' or otherdevices['Voordeur'] == 'On' or otherdevices['Keukendeur'] == 'On' or otherdevices['Woonkamer PIR'] == 'On') then
commandArray['Alarm Trigger']='On'
end
Code: Select all
elseif (timedifference(otherdevices_lastupdate['Alarm Trigger']) > 45 and otherdevices['Alarm Trigger'] == 'On' and otherdevices['Alarm'] == 'On') then
commandArray['Alarm Switch']='On'
Code: Select all
time = os.date("*t")
function timedifference (s)
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
t1 = os.time()
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = os.difftime (t1, t2)
return difference
end
commandArray = {}
-- Controle methodiek t.b.v. openstaande deuren of beweging
if (otherdevices['Alarm'] == 'On') then
if (otherdevices['Alarm Trigger'] == 'Off' and otherdevices['Eetkamerdeur'] == 'On' or otherdevices['Voordeur'] == 'On' or otherdevices['Keukendeur'] == 'On' or otherdevices['Woonkamer PIR'] == 'On') then
commandArray['Alarm Trigger']='On'
end
-- Alarm activeren als aan voorwaarden wordt voldaan
elseif (timedifference(otherdevices_lastupdate['Alarm Trigger']) > 45 and otherdevices['Alarm Trigger'] == 'On' and otherdevices['Alarm'] == 'On') then
commandArray['Alarm Switch']='On'
-- Alarm deactiveren als aan voorwaarden wordt voldaan
elseif (otherdevices['Alarm Trigger'] == 'On' and otherdevices['Alarm'] == 'Off') then
commandArray['Alarm Trigger']='Off'
end
return commandArray