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+
requests
GET
with Wolfram|Alpha
bs4
to parse the result fromrequests
lxml
forbs4
to parsepyyaml
for managing configurationpendulum
for time calculationspython-crontab
for hooking intocrontab
- other requirements
- Create an account with Wolfram|Alpha Developers.
- Request an AppID. Store this value into
appid
in 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 youroffset
sswitch_off
: script called atshutdown
time
failsafe
: (optional, but strongly recommended) failsafe in case the Wolfram|Alpha APIs can't be reached; treated like sunset timehour
minute
sunset
remove
: (default:true
) whether auto-remove should removeswitch_on
jobsoffset
: offset in time relative to sunset; can be negative (before sunset) or positive (after sunset)hours
minutes
run
: (required for running this project automatically)hour
minute
remove
: (required forremove
scripts)hour
minute
shutdown
: (optional, but recommended) when to callswitch_off
scriptenabled
: (default:false
) whether to useswitch_off
remove
: (default:false
) whether auto-remove should removeswitch_off
jobshour
minute
env
: (required forrun
andremove
) 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.