View Full Version : Getting Sunrise/Sunset Times with Lua
caseyp
April 23rd, 2016, 11:01 PM
Ron,
I've been digging through the forum and I've yet to find anything that can point me in the right direction. I'm wanting to get the Sunrise and Sunset times so that I can setup a scene to turn on a light only if it's past sunset and before sunrise (or apply a time offset). I do have automatic lighting that uses the scheduler to do this however this would be something triggered by a remote or amazon echo. My goal is to say "Alexa, Living Room ON" and have the TV come on and the light only if it's needed but I can't seem to figure out how to get these times from Girder using Lua.
Thanks,
Casey
Ron
April 24th, 2016, 10:05 AM
See the manual scripting/Scheduler/sunrise and scripting/scheduler/sunset
caseyp
April 24th, 2016, 10:31 AM
Thanks Ron, I somehow missed that. I'll see if I can get it working.
Casey
Ron
April 24th, 2016, 11:12 AM
no problem! let me know if you get stuck.
caseyp
April 24th, 2016, 03:51 PM
Unfortunately Ron I have gotten a little stuck. I have been able to get both sunrise and sunset using the code shown in the manual and date.now() however I'm having trouble adding a day to the date. From reading the manual I thought the following would work since it says the addDays method takes a number but I get an error.
local tomorrowsDate = date.now()
tomorrowsDate = tomorrowsDate.addDays(1)
print(tomorrowsDate)
Error:
10: bad argument #1 to 'addDays' (girder.date expected, got number)
I've never been a fan of working with Dates in any language as they all seem to do it a little differently and it can be fairly confusing.
Ron
April 24th, 2016, 05:02 PM
tomorrowsDate = tomorrowsDate:addDays(1)
tomrrowsDate is an object, you need to use the ":" symbol.
caseyp
April 24th, 2016, 05:26 PM
Well I've tried that Ron and all I get is nil. I tried both of these and both result in nil.
local tomorrowsDate = date.now()
tomorrowsDate = tomorrowsDate:addDays(1)
and
tomorrowsDate = date.now():addDays(1)
Obviously I must be doing something wrong but when it comes to Lua I feel like a blind guy trying to drive a car.
Ron
April 24th, 2016, 06:25 PM
See the manual, addDays returns nil, it operates on the object it self.
local now = date.now()
print(now)
now:addDays(1)
print(now)
caseyp
April 24th, 2016, 06:54 PM
Here's what I'm getting Ron.
----------------------------------------
print(date.now())
returns: Sun Apr 24 19:49:17 2016
----------------------------------------
local tomorrowsDate = date.now()
tomorrowsDate:addDays(1)
print(tomorrowsDate)
returns: Sun Apr 24 19:49:17 2016
---------------------------------------
So at this point I'm at a loss Ron. I love Girder, but I sure hate Lua because for some reason I just don't get it.
Ron
April 24th, 2016, 07:13 PM
This is not a good evening for that module. That is a bug on my part.... Fixing....
Ron
April 24th, 2016, 08:54 PM
Fixed in release 6.0.17.5 sorry about that!
Powered by vBulletin® Version 4.2.2 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.