Compare 'domoticz.time' with '20 minutes after sunrise' how?

Easy to use, 100% Lua-based event scripting framework.
Post Reply
leby
Posts: 200
Joined: Monday 28 July 2014 9:58
Target OS: Windows
Domoticz version: 3.6242
Location: Stockholm
Contact:

Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by leby » Sunday 10 September 2017 9:05

Hi all,

I have now managed to migrate most of my scripts to dzVents and all have so far been more efficient with dzVents, thx!
Now I have a few left that I'm struggling with.

For starter, I want the script to run from 05:45 in the morning until 3 hours after sunrise.
I have tried below but think it might have some mistake in the code..

I realize that it's possible to use a fixed time instead of the sunrise but it looks nicer with the dynamic sunrise ;-)

Code: Select all

	on = {
		timer = {'05:45 - 180 minutes after sunrise'}
Secondly I want to trigger a group at 05:45 if its not already on but only if the the sunrise have occurred (or will occur) later than 05:25, if its earlier then that the light outside should be enough so no light inside.

How do I accomplish above? I guess below is wrong but to give you a clearer picture of what I try to achieve.

Code: Select all

and domoticz.time.matchesRule(> '20 minutes after sunrise')
The full code would then be something in this direction..

Code: Select all

return {
	active = true, 
	on = {
		timer = {'05:45 - 180 minutes after sunrise'}
	},
	execute = function(domoticz, device)
        local Morgon = domoticz.groups(1) ----- Lampor som tänds tidigt
        local Alla = domoticz.groups(2) ----- Alla lampor inne
        local Ute = domoticz.groups(5) ----- Alla lampor Ute

		if  Morgon.state ~= 'On' and domoticz.time.matchesRule(> '20 minutes after sunrise')  then
		    Morgon.switchOn()
		    domoticz.variables('EventStatus').set('Morgon')
		end
		
		if domoticz.time.isDayTime and Ute.state ~= 'Off' then
		    Ute.switchOff()
		end
		
		if Hall_pir.lastUpdate.minutesAgo > 20
		    and Kok_pir.lastUpdate.minutesAgo > 20
		    and Alla.state ~= 'Off'
		    and domoticz.time.matchesRule('150 minutes after sunrise') then
		    Alla.switchOff()
		end
	end
}
Anyone that can assist I would appreciate any suggestions.

R/lennart
/lennart

leby
Posts: 200
Joined: Monday 28 July 2014 9:58
Target OS: Windows
Domoticz version: 3.6242
Location: Stockholm
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by leby » Sunday 10 September 2017 14:48

No one that knows?

I have managed to change so I think it will work but not so pretty...

Code: Select all

return {
	active = true, 
	on = {
		timer = {'at 05:45 - 12:00'}
	},
	execute = function(domoticz, device)
        local Morgon = domoticz.groups(1) ----- Lampor som tänds tidigt
        local Alla = domoticz.groups(2) ----- Alla lampor inne
        local Ute = domoticz.groups(5) ----- Alla lampor Ute
        local tid = domoticz.time.secondsSinceMidnight/60
	local tidig = (timeofday['SunriseInMinutes']+20)
	local sen = (timeofday['SunriseInMinutes']+150)

		if  Morgon.state ~= 'On'and tid < tidig  then
		    Morgon.switchOn()
		    domoticz.variables('EventStatus').set('Morgon')
		end
		
		if domoticz.time.isDayTime and Ute.state ~= 'Off' then
		    Ute.switchOff()
		end
		
		if Hall_pir.lastUpdate.minutesAgo > 20
		    and Kok_pir.lastUpdate.minutesAgo > 20
		    and Alla.state ~= 'Off'
		    and tid > sen then
		    Alla.switchOff()
		end
	end
}
But there has to be better solutions that someone can come up with, anyone??
/lennart

dpcreel
Posts: 38
Joined: Friday 25 November 2016 15:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by dpcreel » Sunday 10 September 2017 20:53

Not sure if this helps but I believe you syntax is wrong for dzVents if your trying to add 20 min to the sunrise time.

Code: Select all

local tidig = (timeofday['SunriseInMinutes']+20) 

should be

local tigid = domoticz.time.sunriseInMinutes + 20
This site https://www.domoticz.com/wiki/DzVents:_ ... ents_2.2.0 is an excellent source of the methods that dzVents uses.

leby
Posts: 200
Joined: Monday 28 July 2014 9:58
Target OS: Windows
Domoticz version: 3.6242
Location: Stockholm
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by leby » Sunday 10 September 2017 21:13

Yes you are right, the wiki is useful but its a lot of information and the solution was not what I was looking for.
I'll change to your code but the one I used do work, I have tested it in a separate script and printed the value and it gives the correct number.

What I wanted was a comparison of current time and the sunrise + some minutes.
Perhaps this would work?

if ((domoticz.time.secondsSinceMidnight/60) > (domoticz.time.sunriseInMinutes + 20))

Probably ??
/lennart

dpcreel
Posts: 38
Joined: Friday 25 November 2016 15:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by dpcreel » Monday 11 September 2017 2:43

It looks correct, however from a logic stand point it depends what you're trying to do. You don't need to put the whole math code in parentheses.

What I mean is midnight is an issue if it effects you: if sunrise is 6:00am
if (domoticz.time.secondsSinceMidnight/60) > (domoticz.time.sunriseInMinutes+60)
7:30am (450) > 6:00am (420) - True
11pm (1380) > 6:00am (420) - True
1am (60) > 6:00am (420) - False
4am (240) > 6:00am (420) - False

leby
Posts: 200
Joined: Monday 28 July 2014 9:58
Target OS: Windows
Domoticz version: 3.6242
Location: Stockholm
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by leby » Monday 11 September 2017 6:46

I live in sweden and the sunrise vary a lot up in scandinavia. I had it wrong in the sense of > should be <.
if (domoticz.time.secondsSinceMidnight/60) < (domoticz.time.sunriseInMinutes+60)

I start the script at 05:45 and it should only be true if if it's not light outside already (read summer not true).
/lennart

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

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by dannybloe » Monday 11 September 2017 12:03

In the upcoming 2.3 you can do this:

Code: Select all

	on = {
		timer = {
			'between 05:45 and 180 minutes after sunrise'
		}
	}	
Until then you'll have to solve it in your execute block or create a timer function:

Code: Select all

	on = {
		timer = {
			function(domoticz) 
				-- timer logic here.
			end
		}
	}	
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

dpcreel
Posts: 38
Joined: Friday 25 November 2016 15:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by dpcreel » Monday 11 September 2017 17:47

Looks much easier. Thanks for the info.

leby
Posts: 200
Joined: Monday 28 July 2014 9:58
Target OS: Windows
Domoticz version: 3.6242
Location: Stockholm
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by leby » Monday 11 September 2017 18:31

Great, that will be very useful and neater scripts.
It is very much more efficient with dzvents already and only getting better! THX
/lennart

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

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by dannybloe » Monday 11 September 2017 19:41

Code: Select all

return ((domoticz.time.secondsSinceMidnight/60) +20) == domoticz.time.sunriseInMinutes)
Something like that?
Creator dzVents - RPi3, loads of zwave devices, esp8266, evohome.

leby
Posts: 200
Joined: Monday 28 July 2014 9:58
Target OS: Windows
Domoticz version: 3.6242
Location: Stockholm
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by leby » Tuesday 12 September 2017 6:55

This one works for me, thx

if (domoticz.time.secondsSinceMidnight/60) < (domoticz.time.sunriseInMinutes + 20) then....
/lennart

jandirkv
Posts: 23
Joined: Monday 19 February 2018 7:20
Target OS: Raspberry Pi
Domoticz version: 3.9117
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by jandirkv » Saturday 03 March 2018 22:00

[/code]Hallo all,

I have search this forum for many hours to solve my Problem and already started a thread but still no succes. Maybe someone here can help me. I have a outdoor light I want to turn on at Night and turn off during the day. I can't get the script to work. It looks like this:

Code: Select all

return {
	on = {
		timer = { 'every minute'}
		},
	execute = function(domoticz,timer)
		 if (domoticz.time.matchesRule('between 15 minutes before sunset and 15 minutes after sunrise') and domoticz.devices('Lamp Buiten').state =='Off') then
			domoticz.devices('Lamp Buiten').switchOn()
		else
			if (domoticz.time.matchesRule('between 17 minutes after sunrise and 17 minutes before sunset') and domoticz.devices('Lamp Buiten').state == 'On') then
				domoticz.devices('Lamp Buiten').switchOff()
			end
		end
	end
}
Is there also a Manual for all the commands like mentioned above. A lot of the used commands are not on the domoticz dzvents manual website.

SweetPants
Posts: 2277
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.10069
Location: The Netherlands
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by SweetPants » Saturday 03 March 2018 22:08

Ubuntu 16.04.5 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (from source)

User avatar
waaren
Posts: 1072
Joined: Tuesday 03 January 2017 15:18
Target OS: Raspberry Pi
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?

Post by waaren » Saturday 03 March 2018 22:46

jandirkv wrote:
Saturday 03 March 2018 22:00
[/code]Hallo all,

I have search this forum for many hours to solve my Problem and already started a thread but still no succes. Maybe someone here can help me. I have a outdoor light I want to turn on at Night and turn off during the day. I can't get the script to work. It looks like this:

Code: Select all

return {
	on = {
		timer = { 'every minute'}
		},
	execute = function(domoticz,timer)
		 if (domoticz.time.matchesRule('between 15 minutes before sunset and 15 minutes after sunrise') and domoticz.devices('Lamp Buiten').state =='Off') then
			domoticz.devices('Lamp Buiten').switchOn()
		else
			if (domoticz.time.matchesRule('between 17 minutes after sunrise and 17 minutes before sunset') and domoticz.devices('Lamp Buiten').state == 'On') then
				domoticz.devices('Lamp Buiten').switchOff()
			end
		end
	end
}
Is there also a Manual for all the commands like mentioned above. A lot of the used commands are not on the domoticz dzvents manual website.

you could try:

Code: Select all

 --[[ 
 LightTest checkFirst() available in dzVents > 2.3.0
]]-- 
 
return {
	on = { timer = { 'between 15 minutes before sunset and 15 minutes after sunset',
			 'between 15 minutes before sunrise and 15 minutes after sunrise' } },
				  
	execute = function(domoticz,_)
		if domoticz.time.hour > 11 then
			domoticz.devices('Lamp Buiten').switchOn().checkFirst()
		else
			domoticz.devices('Lamp Buiten').switchOff().checkFirst()
		end
	end
}
Raspberry (debian stretch via berryboot on Synology DS916+) , Domoticz (almost) latest Beta, , dzVents 2.6, RFLink, RFXtrx433e, P1, Youless, Harmony, Hue, Yeelight, Xiaomi, HomeWizard, Zwave, Amazon echo

Post Reply

Who is online

Users browsing this forum: credenty and 4 guests