i'm not so expert in Lua and i'm trying to improve my scripting level.
I'm trying to make a script that depending from a list of PIR status, tell me id there is people at home and relative groups of light are switched off.
now i wrote that.
Code: Select all
local PIR = {
"Body Sensor Scala",
"Body Sensor Camera",
"Body Sensor Soggiorno",
"Body Sensor Bagno",
"Body Sensor Cucina",
"Body Sensor Sottotetto",
}
-- test presennce
local emptyhome = true
local PIRscan = dz.devices().filter(PIR)
PIRscan.forEach(function(thisPIR)
if(thisPIR.lastUpdate.minutesAgo < 10) then
dz.log(thisPIR.name)
emptyhome= false
end
-- check
if (emptyhome ) then
dz.log("noone")
--variabile globale
dz.variables('pplAtHome').set(0)
dz.notify('Casa',"none",dz.PRIORITY_NORMAL,'noppl','iPhone6S',dz.NSS_PUSHOVER)
else
dz.log("someone")
--variabile globale
dz.variables('pplAtHome').set(1)
dz.notify('Casa',"someone",dz.PRIORITY_NORMAL,'nyesppl','iPhone6S',dz.NSS_PUSHOVER)
end
Infact the next step should be redefine PIR like this
Code: Select all
local PIR = {
{"Body Sensor Scala", {"switch1","switch2"}},
{"Body Sensor Camera", {"switch3","switch4"}},
{"Body Sensor Bagno", {"switch5","switch6"}},
{"Body Sensor Cucina", {"switch7","switch8"}},
{"Body Sensor Sottotetto", {"switch9","switch10"}},
}
-- test presennce
local emptyhome = true
-- HERE I NEED HELP
-- check pir update, if false switch off corresponding swithces
if (emptyhome ) then
dz.log("noone")
--variabile globale
dz.variables('pplAtHome').set(0)
dz.notify('Casa',"none",dz.PRIORITY_NORMAL,'noppl','iPhone6S',dz.NSS_PUSHOVER)
else
dz.log("someone")
--variabile globale
dz.variables('pplAtHome').set(1)
dz.notify('Casa',"someone",dz.PRIORITY_NORMAL,'nyesppl','iPhone6S',dz.NSS_PUSHOVER)
end
Thanks in advance
Fabrizio