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?
Does command exist? IF SUNRISE or IF NOT SUNRISE
Moderator: leecollings
-
- Posts: 531
- Joined: Saturday 02 June 2018 11:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.1
- Location: Echt, Netherlands
- Contact:
Does command exist? IF SUNRISE or IF NOT SUNRISE
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
- emme
- Posts: 909
- Joined: Monday 27 June 2016 11:02
- Target OS: Raspberry Pi / ODroid
- Domoticz version: latest
- Location: Milano, Italy
- Contact:
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
have a look to the domoticz Utils embedded in dzVents... specially to the domoticz.time.matchesRule('<time rule>') that return a true or false 

The most dangerous phrase in any language is:
"We always done this way"
"We always done this way"
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
-
- Posts: 531
- Joined: Saturday 02 June 2018 11:05
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.1
- Location: Echt, Netherlands
- Contact:
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
@ 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
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
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
- waaren
- Posts: 6028
- Joined: Tuesday 03 January 2017 14:18
- Target OS: Linux
- Domoticz version: Beta
- Location: Netherlands
- Contact:
Re: Does command exist? IF SUNRISE or IF NOT SUNRISE
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 thishoeby 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
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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Who is online
Users browsing this forum: No registered users and 1 guest