Beta Script
import datetime
import ephem
# set these at the beginning of flower
# do not change after!
latitude = ## lat goes here
longitude = ## lon goes here
elevation_m = ## elevation in meters
init_time = datetime.datetime(year=2021, month=1, day=5) # set at first day of flower
cycle_start = datetime.datetime(year=2021, month=8, day=1) # simulated start date of flower
# calculate current simulated date based in inits
offset = cycle_start - init_time
current_dt = datetime.datetime.utcnow()
simulated_dt = current_dt + offset
# in
obs = ephem.Observer()
obs.lat = '%.2f'%latitude
obs.lon = '%.2f'%longitude
obs.elev = elevation_m
obs.date = simulated_dt
node.warn('Simulated Time: %s'%simulated_dt.strftime('%Y-%m-%d %H:%M:%S UTC'))
node.warn('Next rising: %s'%str(obs.next_rising(ephem.Sun())))
node.warn('Next setting: %s'%str(obs.next_setting(ephem.Sun())))
lights = obs.next_setting(ephem.Sun()) < obs.next_rising(ephem.Sun())
if lights:
node.warn('Sun is up!')
else:
node.warn('Sun is down!')
return {'payload':lights}
I’m using a DIY box that runs node red on a pi (great write up by @8k_feet here) :
I wrote a script to simulate a sun cycle at 40N. Right now, it’s just checking every 15m to see if the sun is up or down. I’ll probably reduce this to a 1-5min interval later.
Fortunately, node red has a python function box I can use. Strangely, the python3 function was still using the pi’s python2 version, despite having both. I had to scratch my ass on that one for a while before I figured it out.
Today is August 2nd, and the sun is now set.