Anybody home?
Posted: Monday 04 June 2018 15:02
Once you've got presence detection working (or almost, as both the mac/ip address and gps/ifttt methods are still not very reliable) you'll want to have domoticz make decisions based on whether someone is at home or not. If you live alone, this is easy: you just check the one presence switch. If however multiple people live in your house, you'll need some easy way to see if anyone is at home or everyone is away. What I did is add 2 more dummy On/Off switches, one called 'Iemand thuis' (someone at home) and another called 'Niemand thuis' (noone at home). This script sets the both buttons according to all people's away settings. If I change my presence detection method(s), I don't need to change anything else. If I add another presence button I simply add it in the list in the top of the script and I just as easily remove one or more from there without having to go through any other scripts to find other references. All decisions in other scripts look at the state of the 'Iemand thuis' or the 'Niemand thuis' switches.
Code: Select all
local PRESENCE_DEVICES = {
'Presence Jane',
'Presence Tarzan',
'Presence Poemba',
'Presence Timo'
}
local IEMAND_THUIS = 'Iemand thuis'
local NIEMAND_THUIS = 'Niemand thuis'
return {
on = {
devices = PRESENCE_DEVICES
},
execute = function(domoticz, device)
local iemand_thuis = domoticz.devices().filter( PRESENCE_DEVICES )
.reduce(
function (acc, device)
if device.state == 'On' then
acc = true
end
return acc
end, false)
local sw_home = domoticz.devices(IEMAND_THUIS)
local sw_away = domoticz.devices(NIEMAND_THUIS)
if iemand_thuis == true then
if sw_home.state ~= 'On' then
sw_home.switchOn()
end
if sw_away.state ~= 'Off' then
sw_away.switchOff()
end
else
if sw_home.state ~= 'Off' then
sw_home.switchOff()
end
if sw_away.state ~= 'On' then
sw_away.switchOn()
end
end
end
}