Garden lights on at specific times, but only if it's dark

Moderator: leecollings

Post Reply
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Garden lights on at specific times, but only if it's dark

Post 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
}
Last edited by rrozema on Thursday 07 June 2018 17:34, edited 1 time in total.
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post by snellejellep »

i use the timers with the after sunset and before sunrise elements
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post 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
}
snellejellep
Posts: 241
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: The Neterlands
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post by snellejellep »

well, "and" does not work with timers unfortunately, that is something i am searching for too.
raspberry pi | xiaomi vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | zigbee2mqtt | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post by rrozema »

Ok, but that part is covered by the function in my example. The function defines 2 conditional trigger moments:
  1. (domoticz.time.matchesRule('before sunrise') and domoticz.time.matchesRule('at 07:00')) = At 7:00, but only if this is before sunrise
  2. (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.
User avatar
Denny64
Posts: 53
Joined: Friday 03 February 2017 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Italy
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post 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.
dannybloe
Posts: 1355
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Ermelo
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post by dannybloe »

Eewww.. Blockly ;)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.
User avatar
Denny64
Posts: 53
Joined: Friday 03 February 2017 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Italy
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post by Denny64 »

It was not my intention to discredit dzVents... :)
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post 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.
User avatar
Denny64
Posts: 53
Joined: Friday 03 February 2017 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Italy
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post 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.
rrozema
Posts: 470
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Delft
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post 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?
User avatar
Denny64
Posts: 53
Joined: Friday 03 February 2017 11:34
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.1
Location: Italy
Contact:

Re: Garden lights on at specific times, but only if it's dark

Post 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.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest