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

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

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

Post by rrozema » Monday 04 June 2018 23:15

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: 124
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 4.1xxxx
Location: The Neterlands
Contact:

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

Post by snellejellep » Tuesday 05 June 2018 11:56

i use the timers with the after sunset and before sunrise elements
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ

rrozema
Posts: 124
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi
Domoticz version: beta
Location: Delft
Contact:

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

Post by rrozema » Tuesday 05 June 2018 12:03

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: 124
Joined: Tuesday 16 May 2017 13:05
Target OS: Raspberry Pi
Domoticz version: 4.1xxxx
Location: The Neterlands
Contact:

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

Post by snellejellep » Tuesday 05 June 2018 12:41

well, "and" does not work with timers unfortunately, that is something i am searching for too.
raspberry pi | xiaomi gateway/vacuum | yeelight | philips hue | zwave | ubiquiti unifi | harmony | sonoff | https://www.youtube.com/channel/UC2Zidl ... m1OLuNldfQ

rrozema
Posts: 124
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi
Domoticz version: beta
Location: Delft
Contact:

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

Post by rrozema » Tuesday 05 June 2018 12:51

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: 48
Joined: Friday 03 February 2017 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Italy
Contact:

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

Post by Denny64 » 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.

dannybloe
Posts: 1481
Joined: Friday 29 August 2014 11:26
Target OS: Raspberry Pi
Domoticz version:
Location: Ermelo
Contact:

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

Post by dannybloe » Thursday 07 June 2018 11:04

Eewww.. Blockly ;)
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

User avatar
Denny64
Posts: 48
Joined: Friday 03 February 2017 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Italy
Contact:

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

Post by Denny64 » Thursday 07 June 2018 11:17

It was not my intention to discredit dzVents... :)

rrozema
Posts: 124
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi
Domoticz version: beta
Location: Delft
Contact:

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

Post by rrozema » Thursday 07 June 2018 12:00

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: 48
Joined: Friday 03 February 2017 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Italy
Contact:

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

Post by Denny64 » 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.

rrozema
Posts: 124
Joined: Thursday 26 October 2017 13:37
Target OS: Raspberry Pi
Domoticz version: beta
Location: Delft
Contact:

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

Post by rrozema » Thursday 07 June 2018 12:53

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: 48
Joined: Friday 03 February 2017 12:34
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Italy
Contact:

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

Post by Denny64 » Thursday 07 June 2018 17:23

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