mfreeborn / heliocron

A command line application written in Rust capable of delaying execution of other programs for time periods relative to sunrise and sunset.
Apache License 2.0
241 stars 11 forks source link

Run script every 5 minutes between sunrise and sunset #70

Open gls21 opened 1 year ago

gls21 commented 1 year ago

Is it possible to use heliocron to run a script every x amount of minutes between sunrise and sunset, as opposed to using it to trigger a single event relative to sunrise/set?

bgro82 commented 1 year ago

I'd probably try to do this with cron calling a script every x minutes and the script using heliocron to evaluate if the current time is between sunrise and sunset. For example I use something like the below in Python to collect the day state from Heliocron into a string:

def daylight_state(lat, lon):
    result = subprocess.run(["/home/pi/heliocron", "-l", str(lat), "-o", str(lon), "poll", "--json"],
                            capture_output=True)
    data = json.loads(result.stdout)
    return data["day_part"]