Does command exist? IF SUNRISE or IF NOT SUNRISE

Easy to use, 100% Lua-based event scripting framework.

Moderator: leecollings

Post Reply
hoeby
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

Post 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?
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
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

Post 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 ;)
The most dangerous phrase in any language is:
"We always done this way"
User avatar
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

Post 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
}
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
hoeby
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

Post 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
Thin-client --> Docker Domoticz main environment
Pi3A+ --> Google home (GAssistPi)
Pi3B+ --> Docker (P1monitor, Domoticz test environment, Ubiquity controller)
User avatar
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

Post 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.
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest