jay (support) wrote:CraigM wrote:Unfortunately Indigo isn't smart enough to account for mountains, trees, or other obstacles.
No HA software that I know of can exactly calculate daylight/dark at every point on the map so I guess no HA software is "smart enough".
Hope that's not too out of context but what was stated is exactly correct, having only sunrise/sunset when the picture is much more complicated than that did leave me a little wanting. There are six twilight times that can be pretty useful in determining a some things. When is it actually getting light out in the morning to close east facing shades? Of course this is not a static time period before sunrise.
The military keeps track of this data and makes in available online and it is pretty static for the next 100 years or more for a given location. I've pulled this data down for San Francisco from the US navy here:
http://aa.usno.navy.mil/data/docs/RS_OneYear.php
I manually clean up and convert the downloaded excel spreadsheet into a text file containing a python dictionary of tuples that is dropped into the appropriate python site-packages directory. This is brought into some indigo variables with a simple python script on indigo startup:
data looks like this:
- Code: Select all
suntimes = { "0101":("0551","0623","0656","0725","1701","1731","1804","1835"),
"0102":("0551","0623","0656","0725","1702","1732","1804","1836"),....
startup script:
- Code: Select all
import twilightdata
import pytz, time, datetime
from pytz import timezone
Today = twilightdata.suntimes[datetime.date.today().strftime("%m%d")]
localTZ = timezone(indigo.variables['timeZone'].value)
localOffset = localTZ.localize(datetime.datetime.today()).dst()
def process_time(t):
if (localOffset):
dt = datetime.datetime.combine(datetime.datetime.today(), datetime.time(int(t[:2]), int(t[-2:]))) +localOffset
return dt.strftime("%H%M")
else:
return t
indigo.variable.updateValue("timeATStart", process_time(Today[0]))
indigo.variable.updateValue("timeNTStart", process_time(Today[1]))
indigo.variable.updateValue("timeCTStart", process_time(Today[2]))
indigo.variable.updateValue("timeSunrise", process_time(Today[3]))
indigo.variable.updateValue("timeSunset", process_time(Today[4]))
indigo.variable.updateValue("timeCTEnd", process_time(Today[5]))
indigo.variable.updateValue("timeNTEnd", process_time(Today[6]))
indigo.variable.updateValue("timeATEnd", process_time(Today[7]))
Coupled with a minute timer and then some triggers the six new events are usable. The twilights with start and endings are:
- Astronomical Twilight
Nautical Twilight
Civil Twilight
Good detail to read on these at Wikipedia: http://en.wikipedia.org/wiki/Twilight#Civil_twilight
Here's the script that gets run every minute:
- Code: Select all
import datetime
indigo.variable.updateValue("timeNow", datetime.datetime.now().strftime("%H%M"));
At the start of nautical twilight I know the sun is about to rise (close east shades). At the end of astronomical twilight in the evening it will always be as dark as the night will get until the morning (close west shades relative to this).
Something like this would probably make a great plugin, hope I get around to that. For now though I made sure the scripts are shareable, timezones are supported properly by setting a 'timeZone' variable with your descriptive TZ, like 'US/Pacific'.