Page 1 of 1

Sunset in function

Posted: Friday 29 May 2020 8:33
by robbert1977
Hi all,

Just to check if there is an easier way.

I have triggers (devices) and based on their state there are several different actions.
One of them is if switch triggered and Lux < maxlux then postpone switching the lights till XX minutesAfterSunset.

As far as I know the sunset time is in a function only available in minutes after midnight not as a real time.. is that correct?

As a work around I now do:

Code: Select all

            local hoursstring = dz.utils.stringSplit((dz.time.sunsetInMinutes+minutesAfterSunset)/60,".")
            local hours = hoursstring[1]
            local minutestring = dz.utils.stringSplit (hoursstring[2] / 100 * 60,".")
            local minutes = minutestring[1]
            local sunset = (hours..':'..minutes)
Which is working fine btw just wondering if it could be done smarter :)
Happy to learn.

Kind regards

Re: Sunset in function  [Solved]

Posted: Friday 29 May 2020 9:33
by waaren
robbert1977 wrote: Friday 29 May 2020 8:33 Just to check if there is an easier way.
...
Which is working fine btw just wondering if it could be done smarter :)
Not necessarily smarter. But making use of what others invented for this. :)

Code: Select all

        local lz = dz.utils.leadingZeros
        local hours, minutes = minutesToTime(dz.time.sunsetInMinutes)
        print (lz(hours, 2) .. ':' .. lz(minutes, 2))
        
        local hours, minutes = minutesToTime(dz.time.sunriseInMinutes)
        print (lz(hours,2) .. ':' .. lz(minutes,2))

Re: Sunset in function

Posted: Friday 29 May 2020 12:39
by robbert1977
thnx that helps :)
Yes it definitely helps..
mine had a flaw that it only worked on whole numbers ..
could solve that easily with decimals checked but this is much easier :P