Page 1 of 1

Timer (x) minutes before sunset

Posted: Wednesday 30 August 2017 10:05
by DespyNL
Hi,

Is it possible to trigger a script (x) minutes before sunset?

I have some lights which I switch on at sunset. Sometimes it's already dusk so I would like to switch them a little earlier.
I could create a dummy switch with a timer, but I was wondering if this can also be done with Dzvents timer trigger.

Re: Timer (x) minutes before sunset

Posted: Wednesday 30 August 2017 10:58
by Milifax
I use this in my Dzvents-script.
Basically LUA what Dzvents basically is as I understood.

Code: Select all

-- Only let the lights switch on if they are within a set time before sunset
        local HoursNow = tonumber(os.date("%H"));
        local MinutesNow = tonumber(os.date("%M"));
        local TimeInMinutesNow = MinutesNow + HoursNow * 60
       
        local SetTimeBeforeSunset  = timeofday['SunsetInMinutes']-150 -- 2 1/2 hour before sunset (150 minutes)
    
        if ( ......blablabla.... and  (TimeInMinutesNow > SetTimeBeforeSunset) and .....blabla.........) then
         .............
Hope this helps

Re: Timer (x) minutes before sunset

Posted: Wednesday 30 August 2017 11:35
by bimse
my method.


return {

active = true,

on = {

timer = { '65 minutes before sunset'}
},

execute = function(domoticz)

if domoticz.time.matchesRule('65 minutes before sunset') then

domoticz.devices('Light Switch').switchOn().forMin(320)

end

Re: Timer (x) minutes before sunset

Posted: Wednesday 30 August 2017 11:54
by snuiter
Please see the wiki page on DzVents as it offers many options to simplify you LUA scripts. For e.g. for the timers functions where with LUA you had to do calculations.

http://www.domoticz.com/wiki/DzVents:_n ... er_options

Just add one of the many timer options in the timer section : 'xx minutes before sunset', 'xx minutes after sunset', 'xx minutes before sunrise', 'xx minutes after sunrise'

My script for sunset
Spoiler: show

Code: Select all

return {
	active = true,
	on = {
        timer = {
            '40 minutes before sunset'
        },
	},
	execute = function(domoticz)
	        domoticz.setScene('woonkamer lampen','On')
	        domoticz.notify('','ACTION: sunset',domoticz.PRIORITY_LOW)
            domoticz.log('ACTION : Sunset', domoticz.LOG_INFO)
    end
}

Re: Timer (x) minutes before sunset

Posted: Wednesday 30 August 2017 12:16
by Toulon7559
Simplest is to use the Timer linked to a Switch.
Go to Dashboard/ Switches, select the desired Switch, select Timers, and then you have plenty of choices, relative to fixed clocktime, relative to sunrise, relative to sunset, related to certain days, incl./excl. ambiguity, etc.

Re: Timer (x) minutes before sunset

Posted: Wednesday 30 August 2017 13:44
by DespyNL
I've read the manual, but I totally missed the 'xx minutes before sunrise' part.
Thanks for all the help!