Sunrise/sunset in LUA

Moderator: leecollings

Post Reply
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Sunrise/sunset in LUA

Post by manjh »

Can I detect Sunrise and Sunset in a LUA script? I realize it is easy in Blockly, but I can't figure it out in LUA.

I found timeofday['SunriseInMinutes'] and timeofday['SunsetInMinutes'], but how do I get the time of day in minutes to compare with?
Hans
User avatar
jvdz
Posts: 2445
Joined: Tuesday 30 December 2014 19:25
Target OS: Raspberry Pi / ODroid
Domoticz version: 4.107
Location: Netherlands
Contact:

Re: Sunrise/sunset in LUA

Post by jvdz »

Something like this:

Code: Select all

minutesnow = timenow.min + timenow.hour * 60
if (minutesnow == timeofday['SunsetInMinutes']+2) then
   -- this runs 2 minutes after SunSet
end
Jos
manjh
Posts: 859
Joined: Saturday 27 February 2016 12:49
Target OS: Raspberry Pi / ODroid
Domoticz version: 2020.2
Location: NL
Contact:

Re: Sunrise/sunset in LUA

Post by manjh »

you beat me to it. I figured out:
test = os.date("%H") * 60 + os.date("%M")
Gives me the time of day in minutes. Really simple, actually...
Hans
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests