Sunrise sunset script using http://sunrise-sunset.org/
I've come to the conclusion that earthtools is gone, so I've modified the sunforcast script to use sunrise-sunset.org.
It's not as pretty as Brett would write but it's functional, however if you feel you can improve on it, feel free
I think Earthtools have moved to here: new.earthtools.org
Will this still work?
Mark I never had a use for the sun rise/set app so far, but thought it would be a good idea for turning on and off our outside Christmas lights. Well I am not a programmer but got your applet working second attempt in conjunction with Brett’s automatic lights applet. What surprised me was how light it was when the lights turned on and subsequently when they turned off. To get round this I am going to enter a latitude further south than I really am (fudge factor). Obviously this will not work for all the year.
What would be great if there was a way of having a plus or minus time padding factor. As an example if the sun sets at 16:00 a 30min delay could be added so the lights turn on at 16:30 or sun rise at 08:00 but lights go off at 07:30.
To do a better job we need a JSON parser for LUA to be bundled as part of the HAH build.
There are some options. One written in pure LUA
Or a fast C based one with LUA bindings.
I'm thinking the C one would be a nice addition. Its a been a while since I have done anything HAH so I'll dust off my trustly beaglebone that has been gathering my solar array feed and spewing xAP without a fault all year and give it a little upgrade as a xmas present.
I added lua-cjson to the portable distribution - however on my debian BeagleBone the packge is already setup and available for usage. COOL.
root@beaglebone:~# apt-get install lua-cjson
Making it use the new json decode is easy however as the reply is in UTC i need to the times back into localtime so they are meaningful and this is where things break down for me. The penlight library just isn't handling this correctly - after burning way too many hours debugging somebody elses code i threw in the towel for today.
The fetching side changes are easy enough ....
local url = string.format("http://api.sunrise-sunset.org/json?lat=%s&lng=%s&formatted=0",latitude,longitude )
local response,statuscode = http.request(url)
if response == nil or statuscode ~= 200 then return end
t = cjson.decode(response)
if t.status ~= 'OK' then return end
sunrise = t.results.sunrise
sunset = t.results.sunset
The only change on the PARSE side it remove the format mask and it will deal natively with the ISO8601 format being returned.
local df = Date.Format(nil)
The UTC->localtime conversion that's another story....
I agree Mark a few lines of cron script seem to be the easiest way for me too.
You are both absolutly correct, a couple of lines added to cron would do.
I was trying to justify to myself a reason to use the sun rise/set apps and then discovering it was turning on the lights about half an hour before it was dark.
I used the earthtools version for a while when I was out of the country for an extended period. But as you say I had to tell porkies about my Lat/long in order to make the lights work at realistic times. Then, one year, while I was away the whole site went belly up and I had to remote in and set the whole thing up again using cron. As someone said cron is more reliable because it doesn't rely on an external data source.
In the end I decided that it was just too much bother.
I now use something like this:
#01 20 1-7 4 * aliasmsg "rf 4 on"
#15 20 8-16 4 * aliasmsg "rf 4 on"
#29 20 17-22 4 * aliasmsg "rf 4 on"
#45 20 23-30 4 * aliasmsg "rf 4 on"
#47 20 23-30 4 * aliasmsg "rf 5 on"
#00 21 1-8 5 * aliasmsg "rf 4 on"
#02 21 1-8 5 * aliasmsg "rf 5 on"
#15 21 9-16 5 * aliasmsg "rf 4 on"
#17 21 9-16 5 * aliasmsg "rf 5 on"
#30 21 17-25 5 * aliasmsg "rf 4 on"
#32 21 17-25 5 * aliasmsg "rf 5 on"
and just un rem the lines as and when I need them.
Ah, yes that's just a sample from the cron to show the section used to change the timings as the evenings get lighter. The off commands go every night irrespective of whether the lights are being controlled by the HAH (good hint to the kids to go to bed). The # is in effect a rem because those lines are not run until I delete the # from the beginning of the line.