the status 'Away' is determined when all detection devices in a group aren't active for the last 20 minutes.
Code: Select all
return {
on = {
timer = {
'every 15 minutes'
}
},
execute = function(domoticz)
minInactive = 20 -- grace period in minutes
if domoticz.devices('Status').state == 'Off' then -- selector switch : 10 = away; 20 = asleep; Off = people are present,
local away = true
domoticz.groups('Afwezig').devices().forEach(function(device) -- all relevant devices are in the Group 'Afwezig', about 14 devices, being PIRs, window/door sensor and pinged devices like television and computers
if device.lastUpdate.minutesAgo < minInactive or device.active then -- if any device is active or was active in the grace period then people are present
away = false
end
end)
if away then
domoticz.devices('Status').switchSelector(10) -- set Status to away; This triggers another script
end
end
end
}