Page 1 of 1
Does command exist? IF SUNRISE or IF NOT SUNRISE
Posted: Tuesday 08 October 2019 9:53
by hoeby
I want to make a script for the front door lamp.
The lamp goes on at 6:30hour and off at 10 minutes after sunrise
In the winter this is no problem. Sunrise is after 6:30hour.
But in the summer sunrise could be at 5:30hour. So in the summer the light goes off at 5:40hour, but on at 6:30hour. Which keeps the light on for the rest of the day.
There i was thing for something like:
if 6:30hour and before sunrise then --> ON
else --> off
But is it possible to use "before sunrise" without minutes added?
I only see the before sunrise option in the timer part. But not used in the script.
Could somebody help me with this?
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
Posted: Tuesday 08 October 2019 12:40
by emme
have a look to the domoticz Utils embedded in dzVents... specially to the domoticz.time.matchesRule('<time rule>') that return a true or false

Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
Posted: Tuesday 08 October 2019 13:49
by waaren
hoeby wrote: ↑Tuesday 08 October 2019 9:53
IThere i was thing for something like:
if 6:30hour and before sunrise then --> ON
else --> off
Have a look at the attached. Using this you can experiment with the the different checks
Code: Select all
return {
on = {
timer = { 'every minute' },
},
execute = function(dz)
timeTests = {
atTimeTest_1 = dz.time.matchesRule('at 13:40'),
betweenTest_1 = dz.time.matchesRule("between sunset and sunrise"),
betweenTest_2 = dz.time.matchesRule("between sunrise and sunset"),
combineTest_1 = dz.time.matchesRule("between sunrise and sunset") and dz.time.matchesRule('at 13:20-04:00'),
combineTest_2 = dz.time.matchesRule("between sunrise and 06:30"),
combineTest_3 = dz.time.matchesRule("at 06:30") and dz.time.matchesRule('before sunrise'),
}
for testName, test in pairs(timeTests) do
dz.log(testName .. ' ==>> ' .. tostring(test),dz.LOG_FORCE)
end
end
}
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
Posted: Wednesday 09 October 2019 21:20
by hoeby
@ waren, i tried the options.
The dz.time.matchesRule("before sunrise") doesn't work. I don't get an error, but the switch is not set.
The dz.time.matchesRule("between sunrise and 06:30") is a strange setting.
When using like written. And sunrise would be 05:30. Then i thoughed domoticz handles it as "between 05:30 and 06:30"
But when i change it to "between 06:30 and sunrise" and sunrise still would be 05:30. Then also domoticz handles it as "between 05:30 and 06:30".
Domoticz doesn't look which archument is before and after the AND
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
Posted: Thursday 10 October 2019 21:19
by waaren
hoeby wrote: ↑Wednesday 09 October 2019 21:20
The dz.time.matchesRule("between sunrise and 06:30") is a strange setting.
When using like written. And sunrise would be 05:30. Then i thoughed domoticz handles it as "between 05:30 and 06:30"
But when i change it to "between 06:30 and sunrise" and sunrise still would be 05:30. Then also domoticz handles it as "between 05:30 and 06:30".
Domoticz doesn't look which argument is before and after the AND
Lua (domoticz) first evaluate the first expression in a combined one and only if true evaluates the next one. The dzVents time rules do evaluate like this
If sunrise is at 6:00 then ('Between sunrise and 06:30') will evaluate to true only between 6:00-6:30
if sunrise is at 8:00 then ('Between sunrise and 06:30') will evaluate to true between 08:00-00:00 and between 00:00 and 06:30
Please play a bit with the example script below and you will see how dzVents and within time rule differs from the Lua and.
Code: Select all
return {
on = {
timer = { 'every minute' },
},
logging = {
level = domoticz.LOG_DEBUG,
marker = "timer"
},
execute = function(dz)
timeTests = {
['at 13:40'] = dz.time.matchesRule('at 13:40'),
['between sunset and sunrise'] = dz.time.matchesRule("between sunset and sunrise"),
['between sunrise and sunset'] = dz.time.matchesRule("between sunrise and sunset"),
['between sunrise and sunset and at 13:20-04:00'] = dz.time.matchesRule("between sunrise and sunset") and dz.time.matchesRule("at 13:20-04:00"),
['between sunrise and 06:30'] = dz.time.matchesRule("between sunrise and 06:30"),
['at 06:30 and before sunrise'] = dz.time.matchesRule("at 06:30") and dz.time.matchesRule("before sunrise"),
['at 06:30'] = dz.time.matchesRule("at 06:30"),
['at 20:44 and before sunse'] = dz.time.matchesRule("at 21:44") and dz.time.matchesRule("before sunset"),
['before sunrise'] = dz.time.matchesRule("before sunrise"),
['at 06:30 and before sunrise'] = dz.time.matchesRule("at 06:30") and dz.time.matchesRule("before sunrise"),
['at 09:30 and before sunrise'] = dz.time.matchesRule("at 09:30") and dz.time.matchesRule("before sunrise"),
['between 9:30 and sunrise'] = dz.time.matchesRule("between 9:30 and sunrise"),
}
dz.log('-----6:30-Sunrise-------------------------------sunset-----------------------6:30--------Sunrise -----',dz.LOG_FORCE)
dz.log('-----|----|-------------------------------------|----------------------------|-----------|------ ',dz.LOG_FORCE)
for testName, test in pairs(timeTests) do
dz.log(testName .. ' ==>> ' .. tostring(test),dz.LOG_FORCE)
end
end
}
If you have questions after that then please include the log output of this script to help me understand where you see any unexpected behavior.