With my new system, since I control the door operator from Indigo, I have a lot more leeway. Initially,I am basing the open and close times on sunrise & sunset plus a small wait factor. Mornings are not really an issue. But in the evening, the chick come back to roost when they think it is dark. And, depending on weather and season may be well before or after Indigo's idea of sunset. In the caveat hand, I am only worried about closing too early, not too late - that is the case where the chicks get locked out for the night.
So... I hacked a small script I found online to calculate various astronomical times (see below) and seem to be stumped as how to proceed to use these times in a schedule. (Yes, I guess I could run the script externally and just have it trigger the close action. But, I'd rather try to stay in a more Indigo mind.)
Anyway, the issue is simply, how to I get Indigo to execute my action at, say astronomical twilight (true dark). I have the time, and can convert it to a number of formats, and can place it in a variable. I just can't wrap my mid-winter hibernating brain around how to make the final connection.
Ideas, suggestions and pointers most welcome.
Here is the code
- Code: Select all
#!/usr/bin/python2.7
import ephem
# Make an observer
loc = ephem.Observer()
# PyEphem takes and returns only UTC times. 15:00 is noon in locericton
loc.date = str(datetime.datetime.utcnow()) # "2020-01-05 16:39:00"
# Location
loc.lat = str(xx.xxxx) # Note that lon should be in string format
loc.lon = str(xx.xxxx) # Note that lat should be in string format
# Elevation in metres
loc.elev = 134
# To get U.S. Naval Astronomical Almanac values, use these settings
loc.pressure = 0
loc.horizon = '-0:34'
sunrise=loc.previous_rising(ephem.Sun()) # Sunrise
noon =loc.next_transit (ephem.Sun(), start=sunrise) # Solar noon
sunset =loc.next_setting (ephem.Sun()) # Sunset
# We relocate the horizon to get twilight times
loc.horizon = '-6' # -6=civil twilight, -12=nautical, -18=astronomical
beg_twilight=loc.previous_rising(ephem.Sun(), use_center=True) # Begin twilight
end_twilight=loc.next_setting (ephem.Sun(), use_center=True) # End twilight
print("Current time is: %12s" % ephem.localtime(loc.date))
print("begin civil twilight: %12s" % ephem.localtime(beg_twilight))
print("sunrise: %12s" % ephem.localtime(sunrise))
print("noon: %12s" % ephem.localtime(noon))
print("sunset: %12s" % ephem.localtime(sunset))
print("end civil twilight: %12s" % ephem.localtime(end_twilight))