- If the sun is not up at 07:00
- if the sun goes down before 21:00
Code: Select all
return {
on = {
timer = {
function(domoticz)
return (domoticz.time.matchesRule('between 00:00 and sunrise') and domoticz.time.matchesRule('at 07:00'))
or (domoticz.time.matchesRule('between sunset and 21:00') and domoticz.time.matchesRule('at sunset'))
end
}
},
execute = function(domoticz, triggeredItem, info)
local d = domoticz.devices('Tuin: Buitenlamp')
if (d.state ~= 'On') then
d.switchOn()
end
end
}
EDIT: snellejellep suggested the range conditions could be denoted a lot easier using "before" and "after". Following his suggestion I made the conditions easier to read by changing 'between 00:00 and sunrise' into 'before sunrise', and 'between sunset and 21:00' into 'before 21:00'. Resulting in below improved example code version 2:
Code: Select all
return {
on = {
timer = {
function(domoticz)
return (domoticz.time.matchesRule('before sunrise') and domoticz.time.matchesRule('at 07:00'))
or (domoticz.time.matchesRule('before 21:00') and domoticz.time.matchesRule('at sunset'))
end
}
},
execute = function(domoticz, triggeredItem, info)
local d = domoticz.devices('Tuin: Buitenlamp')
if (d.state ~= 'On') then
d.switchOn()
end
end
}