Code: Select all
-- for each room you want to monitor add:
--
-- device: [room name] .. ' beweging' ; a PIR device to monitor movement in the room
-- group: [room name] ; a group containing all the devices you want to switch off
local roomsToCheck = {
-- table with rooms to check and the minutes before the first warning is given
-- name: [room name]
-- threshold: number of minutes without movement before switching the group off
{ ['name'] = 'Keuken', ['threshold'] = 30 },
{ ['name'] = 'Woonkamer', ['threshold'] = 120 },
{ ['name'] = 'Studeerkamer', ['threshold'] = 60 },
{ ['name'] = 'Eetkamer', ['threshold'] = 60 },
}
--
return {
active = true,
on = {
timer = {'every 15 minutes'}, -- adjust this to suit your needs
},
logging = {
level = domoticz.LOG_INFO,
marker = "SRO"
},
execute = function(domoticz)
for i, roomToCheck in pairs(roomsToCheck) do -- check all rooms in the table
local name = roomToCheck['name']
local sensor = name .. ' beweging' -- get the sensor name
local threshold = roomToCheck['threshold'] -- get the threshold for this room
local minutes = domoticz.devices(sensor).lastUpdate.minutesAgo -- get the minutes without movement
if (minutes > threshold) then -- do we need to do something
if (domoticz.groups(name).state == 'On') then -- anything on?
domoticz.log('No movement in ' .. name .. ' for ' .. minutes .. ' minutes, turn everything off.')
domoticz.groups(name).switchOff() -- turn stuff off
else
domoticz.log('Everything in ' .. name .. ' already switched off.')
end
else
domoticz.log('Recent movement in ' .. name .. ', ' .. minutes .. ' minutes ago, do nothing.')
end
end
end
}