Page 1 of 1

Sunrise/sunset in LUA

Posted: Wednesday 09 March 2016 18:19
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?

Re: Sunrise/sunset in LUA

Posted: Wednesday 09 March 2016 18:27
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

Re: Sunrise/sunset in LUA

Posted: Wednesday 09 March 2016 18:59
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...