I started with dzVents just now and I want to translate my lua scripts to dzVents.
All my Pir / Motion sensors in the house are called Motion-<roomname>
Now I want to know if there is some movement in the house and if none of the sensors noticed motion in the house for the last hour I want to switch off the seperate / general Motion sensor.
From what I know about the subject I came to the following. But it doesn't work.
What did I do wrong and what to change in the scrip to make it work?
Your help is appreciated.
Code: Select all
local active = 0
return {
logging = {
level = domoticz.LOG_ERROR, -- Select one of LOG_INFO, LOG_DEBUG, LOG_ERROR, LOG_FORCE to override system log level
marker = "-=# Movement #=-"
},
on = {
devices = {'Motion-*'},
timer = {'every minute'},
},
data = {},
logger = {},
execute = function(domoticz, triggeredItem)
-- check all Motion / Pir sensors
domoticz.devices().filter(function(device)
return (string.match('Motion-', device.name)~=nil)
end).forEach(function(motion)
if (domoticz.devices('Motion-', device.name).lastUpdate.minutesAgo <= 60) then
active = active + 1
end
end)
if active == 0 then
domoticz.devices('Motion').switchOff()
else
domoticz.devices('Motion').switchOn()
end
print('Aantal actieve devices = ' .. active)
end
}