If does work for on but not for off
Posted: Sunday 14 October 2018 20:24
The goal: do some smart things with lighting when we are home or not.
Device with IDX 15 is a dummy on/off switch. When somebody is home and the switch is On everythings works ok.
But when there is nobody home it doesn't get through the "er is niemand thuis" part. It only gets into the 60 minutes before sunset part.
Am i making an huge beginners fault or is there something i'm complelty missing?
Code: Select all
return {
on = {
timer = {
'60 minutes before sunset',
'at 22:45'
}
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "LightAtDusk: "
},
execute = function(d, triggers)
logtekst = ''
d.log('The rule that triggered the event was: ' .. triggers.trigger)
logtekst = logtekst .. 'The rule that triggered the event was: ' .. triggers.trigger .. '\r\n'
--check if somebody home so
d.log("Somebody status: " .. d.devices(15).state);
logtekst = logtekst .. "Somebody status: >" .. d.devices(15).state .. '< \r\n'
if triggers.trigger == '60 minutes before sunset' then
d.notify('Remote Debug','Ik trigger wel maar negeer de status ')
d.notify('Remote Debug', d.devices(15).state)
logtekst = logtekst .. "Inside 60 minutes before " .. '\r\n'
if d.devices(15).state == "On" then
logtekst = logtekst .. "Switch on? somebody home " .. '\r\n'
--somebody is home! Allrighty check for lights and switch them on.
--No using scenes because i now we can use the checkFirst function to see if some lights *kuch* (433 mhz devices) all already on.
d.devices(36).switchOn()
--end
elseif d.devices(15).state == "Off" then
d.notify('Remote debug','Er is niemand thuis ')
logtekst = logtekst .. "Switch on? nobody home " .. '\r\n'
-- switch on the lights
d.variable('FullAutoLights').set('1')
d.devices(36).switchOn().checkFirst()
else
d.notify('Domoticz!!','Blinde paniek er is onbekend of er iemand thuis is ')
end
end
if triggers.trigger == 'at 22:45' and domoticz.variables('FullAutoLights').value == '1' then
logtekst = logtekst .. "Inside at22:45 Switch off? nobody home " .. '\r\n'
d.variable('FullAutoLights').set('0')
d.devices(36).switchOff().checkFirst()
end
d.log(logtekst)
d.notify('Remote Debug!',logtekst)
end
}
But when there is nobody home it doesn't get through the "er is niemand thuis" part. It only gets into the 60 minutes before sunset part.
Am i making an huge beginners fault or is there something i'm complelty missing?