Page 1 of 1

[SOLVED] Get sunrise and sunset time from domoticz

Posted: Saturday 07 May 2022 21:46
by zavjah
Hi there,

I'd like to show the sunrise and sunset time that is shown e.g. on the dashboard or in the settings in in a virtual device. I've tried to calculate the time out of sunriseInMinutes but it results in a diferent time than in domoticz. I assume it is because of the location I've set in domoticz.

Thx for any hints,
Zavjah

Re: Get sunrise and sunset time from domoticz

Posted: Sunday 08 May 2022 8:27
by hoeby
Is this where you are looking for?
Where you need to devices (Sunset and Sunrise)
Found the code on the forum, all credits to Waaren (viewtopic.php?t=26677)

Code: Select all

-- dzVents version >= 2.4.7
return {
    timer     =   { "at 00:03", "at 06:03" }, -- twice a day to be sure and 3 min past the hour because at the hour already quite busy 
     
    execute = function( dz )
        local function minutes2time(minutes)   -- integer in; string out 
            local hour      = string.format("%02d",math.floor(minutes / 60))
            local minutes   = string.format("%02d",minutes - (hour * 60))
            return (hour .. ":" .. minutes) --  string out 
        end
        
        dz.devices("Sunset").updateText("Sunset: " .. minutes2time(dz.time.sunsetInMinutes).. "\nCivil twilight end: " .. minutes2time(dz.time.civTwilightEndInMinutes or "-"))
        dz.devices("Sunrise").updateText("Sunrise: ".. minutes2time(dz.time.sunriseInMinutes).. "\nCivil twilight start: " .. minutes2time(dz.time.civTwilightStartInMinutes or "-"))
    end
}
Or have a look on this link, a lot of time options
viewtopic.php?f=72&t=28103

Re: Get sunrise and sunset time from domoticz

Posted: Sunday 08 May 2022 13:23
by zavjah
Hi there,

thx hoeby, thx waaren, that's exactly what I was looking for. It seems my converion of minutes into hours was wrong, that's why i got different times than shown on dashboard.

Cheers,
zavjah

Re: [SOLVED] Get sunrise and sunset time from domoticz

Posted: Sunday 08 May 2022 21:08
by Treve
FYI, Waaren is not with us anymore. He past away.