Sunset in function  [Solved]

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

Moderator: leecollings

Post Reply
robbert1977
Posts: 15
Joined: Saturday 18 April 2020 22:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Sunset in function

Post 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
Raspberry Pi 4
domoticzVersion: 2020.2
dzVentsVersion: 3.0.2
OpenZWave USB: 1.6-1033-g3661f170
RFXCOM - RFXtrx433 USB: Pro XL1/1043, Noise: 109 dB
Homebridge - Siri integration
User avatar
waaren
Posts: 6028
Joined: Tuesday 03 January 2017 14:18
Target OS: Linux
Domoticz version: Beta
Location: Netherlands
Contact:

Re: Sunset in function  [Solved]

Post 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))
Debian buster, bullseye on RPI-4, Intel NUC.
dz Beta, Z-Wave, RFLink, RFXtrx433e, P1, Youless, Hue, Yeelight, Xiaomi, MQTT
==>> dzVents wiki
robbert1977
Posts: 15
Joined: Saturday 18 April 2020 22:12
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Contact:

Re: Sunset in function

Post 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
Raspberry Pi 4
domoticzVersion: 2020.2
dzVentsVersion: 3.0.2
OpenZWave USB: 1.6-1033-g3661f170
RFXCOM - RFXtrx433 USB: Pro XL1/1043, Noise: 109 dB
Homebridge - Siri integration
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest