Twilight Data (Is it dark outside?)

Posted on
Tue Jul 24, 2012 4:14 am
screen offline
Posts: 31
Joined: Feb 19, 2009

Twilight Data (Is it dark outside?)

I started writing this in reply to an older thread and then thought it would be better suited in it's own place. here goes:

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'.

Posted on
Tue Jul 24, 2012 8:57 am
jay (support) offline
Site Admin
User avatar
Posts: 18220
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Twilight Data (Is it dark outside?)

Great data, thanks.

I added the quote from the OP of the other thread to provide a bit more context to my quote.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Jul 24, 2012 10:47 am
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Twilight Data (Is it dark outside?)

Interesting for sure, but the occasional thunderstorm here will bring about light levels that approach night, leaving a very dark house.

Could anyone recommend a light sensor that could send Indigo at least
a decent range of intensities....as opposed to a simple on/off when a threshold is reached?
I played with a couple motion sensors that can trigger when "dark" but I'm finding it
nearly impossible to get the level I want reliably.

Thanks,

Carl

Posted on
Tue Jul 24, 2012 12:41 pm
berkinet offline
User avatar
Posts: 3290
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: Twilight Data (Is it dark outside?)

Check out the basic Phidgets light sensor. (Phidgets.com)

Posted on
Tue Jul 24, 2012 5:54 pm
ckeyes888 offline
Posts: 2425
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Twilight Data (Is it dark outside?)

Will do, thanks.

Carl

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 15 guests