Automated scripts at local sunset
This project checks local sunset time using Wolfram|Alpha and runs scripts of your choice This project aims to automate sunset checking; scripts are intended to be used in conjunction with the check. In particular, you can add scripts to fire around sunset and a fixed point after. For example, you could create external scripts that control an IOT device (smart plug, lightbulb): turn on near sunset and turn off after.
After installing dependencies and following setup, run process.py.
This code is designed around the following:
- Python 3.7+
requestsGETwith Wolfram|Alpha
bs4to parse the result fromrequestslxmlforbs4to parsepyyamlfor managing configurationpendulumfor time calculationspython-crontabfor hooking intocrontab- other requirements
- Create an account with Wolfram|Alpha Developers.
- Request an AppID. Store this value into
appidin the configuration file. - Configure the other fields in the configuration file as desired.
- (Optional) Run crontabber.py to register cron jobs with both the process.py and the remove.py scripts. Requires all fields to be filled out.
scripts: (required)root: where your scripts liveswitch_on: script called around sunset relative to youroffsetsswitch_off: script called atshutdowntime
failsafe: (optional, but strongly recommended) failsafe in case the Wolfram|Alpha APIs can't be reached; treated like sunset timehourminute
sunsetremove: (default:true) whether auto-remove should removeswitch_onjobsoffset: offset in time relative to sunset; can be negative (before sunset) or positive (after sunset)hoursminutes
run: (required for running this project automatically)hourminute
remove: (required forremovescripts)hourminute
shutdown: (optional, but recommended) when to callswitch_offscriptenabled: (default:false) whether to useswitch_offremove: (default:false) whether auto-remove should removeswitch_offjobshourminute
env: (required forrunandremove) where the environment is for the projectroot: (required) where the project root is
scripts (and scripts["root"] and scripts["switch_on"]) and root are required. This project will not function properly without them. (scripts["switch_off"] is optional.)
run, remove, and shutdown, hour and minute represent when that section will run, at hour:minute local time. Compare this with hours and minutes in section sunset["offset"]; these values instead are relative values from sunset.
env is missing, both the optional run and remove cron jobs cannot be registered.
run, remove, and shutdown, their child values must also be defined or their respective scripts won't run at all. For shutdown, scripts["switch_off"] must also be defined.
This project is not affiliated with or endorsed by Wolfram|Alpha. See LICENSE for more detail.