Page 1 of 1
Garden lights on at specific times, but only if it's dark
Posted: Monday 04 June 2018 23:15
by rrozema
We're all on the clock. Only the sun is not. So how do I get my garden lights to switch on only when they are needed? Here is a small script that switches on my garden lights, but only if the sun is not up that time. The garden lights are switched off by normal timers on the switch at 07:00 and at sunrise. This script applies a function as a timer trigger to combine 2 timer rules using the "and" operation. One rule is a time-range, the other is a specific time. Only if the specific time is within the time range the combination will be true. Using this technique I implemented the following 2 rules:
- 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
}
Re: Garden lights on at specific times, but only if it's dark
Posted: Tuesday 05 June 2018 11:56
by snellejellep
i use the timers with the after sunset and before sunrise elements
Re: Garden lights on at specific times, but only if it's dark
Posted: Tuesday 05 June 2018 12:03
by rrozema
snellejellep wrote: Tuesday 05 June 2018 11:56
i use the timers with the after sunset and before sunrise elements
I didn't know you could do that? The documentation says 'xx minutes after sunset', but you say it is possible to just say 'after sunset'? And this matches any time after sunset? Excellent!, I'll try that.
Does that mean I can do "before 21:00" too? So I could do something like this?
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
}
Re: Garden lights on at specific times, but only if it's dark
Posted: Tuesday 05 June 2018 12:41
by snellejellep
well, "and" does not work with timers unfortunately, that is something i am searching for too.
Re: Garden lights on at specific times, but only if it's dark
Posted: Tuesday 05 June 2018 12:51
by rrozema
Ok, but that part is covered by the function in my example. The function defines 2 conditional trigger moments:
- (domoticz.time.matchesRule('before sunrise') and domoticz.time.matchesRule('at 07:00')) = At 7:00, but only if this is before sunrise
- (domoticz.time.matchesRule('before 21:00') and domoticz.time.matchesRule('at sunset')) = At sunset, but only if this is before 21:00
The part that I didn't find a solution for is to create a script that can both switch the lights on
and off. I couldn't think of an easy way to see what rule exactly triggered the script to run (both are the same function, remember?), so this is why I have this script conditionally switch the lights on and have timers on the switch that switch the lights (unconditionally) off.
Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 10:59
by Denny64
Why don't you use a lux meter?
With it you can turn on the lights when it's getting dark (regardless of the time) and turn off at sunrise.
With a simple blockly you can also do conditions to satisfy your needs and do much more with indoor lights or actuators.
I suggest Fibaro FGMS001. I have been using it for over two years and it's perfect.
Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 11:04
by dannybloe
Eewww.. Blockly

Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 11:17
by Denny64
It was not my intention to discredit dzVents...

Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 12:00
by rrozema
Denny64 wrote: Thursday 07 June 2018 10:59
Why don't you use a lux meter?
With it you can turn on the lights when it's getting dark (regardless of the time) and turn off at sunrise.
With a simple blockly you can also do conditions to satisfy your needs and do much more with indoor lights or actuators.
I suggest Fibaro FGMS001. I have been using it for over two years and it's perfect.
Using a lux meter doesn't change the situation at all. What I'm demonstrating here is a way to trigger a switch at a certain time, but only if some condition is met. In my example I've got 2 such trigger moments: In the morning at 7, but only if it is still dark, and the other: In the evening at sunset but only if it is before 21:00. So If the sun comes up before 7:00, the lights will not come on that morning. And likewise: if the sun goes down after 21:00 the lights will not come on that evening.
You can do similar things with other conditions, for example: "at 18:00 but only if someone is at home". This is not possible with "normal" timers on the switches, using dzVents it is possible as I've demonstrated.
Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 12:46
by Denny64
I do not discuss the script, but one condition.
For my experience, the condition "only if it's dark" is only really satisfyed using a lux meter.
Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 12:53
by rrozema
Denny64 wrote: Thursday 07 June 2018 12:46
I do not discuss the script, but one condition.
For my experience, the condition "only if it's dark" is only really satisfyed using a lux meter.
Point taken. Sunrise and sunset were sufficient for my garden lights though. I didn't need an additional investment for that. But while we're on this topic, do you know of any outside z-wave lux sensor?
Re: Garden lights on at specific times, but only if it's dark
Posted: Thursday 07 June 2018 17:23
by Denny64
I honestly don't know if exists an external Z-Wave luxmeter. In my case, for over two years I have been using a Fibaro FGMS001 without problems and is installed under a roof. To protect it from moisture, I also put a small rubber ring (those used to close the watch cases) between the two half-shells of the sensor.