Page 1 of 1
Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Sunday 10 September 2017 9:05
by leby
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
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Sunday 10 September 2017 14:48
by leby
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??
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Sunday 10 September 2017 20:53
by dpcreel
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.
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Sunday 10 September 2017 21:13
by leby
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 ??
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Monday 11 September 2017 2:43
by dpcreel
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
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Monday 11 September 2017 6:46
by leby
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).
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Monday 11 September 2017 12:03
by dannybloe
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
}
}
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Monday 11 September 2017 17:47
by dpcreel
Looks much easier. Thanks for the info.
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Monday 11 September 2017 18:31
by leby
Great, that will be very useful and neater scripts.
It is very much more efficient with dzvents already and only getting better! THX
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Monday 11 September 2017 19:41
by dannybloe
Code: Select all
return ((domoticz.time.secondsSinceMidnight/60) +20) == domoticz.time.sunriseInMinutes)
Something like that?
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Tuesday 12 September 2017 6:55
by leby
This one works for me, thx
if (domoticz.time.secondsSinceMidnight/60) < (domoticz.time.sunriseInMinutes + 20) then....
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Saturday 03 March 2018 21:00
by jandirkv
[/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.
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Saturday 03 March 2018 21:08
by SweetPants
Re: Compare 'domoticz.time' with '20 minutes after sunrise' how?
Posted: Saturday 03 March 2018 21:46
by waaren
jandirkv wrote: Saturday 03 March 2018 21: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
}