This program is designed to control Tapo devices (plugs and bulbs) based on weather conditions obtained from OpenWeatherMap API. It allows you to automate the behavior of the Tapo devices based on cloudiness data retrieved for a specific location.
- Python 3.7 or higher
- Required Python packages:
PyP100
,requests
,python-dotenv
,astral
,schedule
-
Clone or download the repository to your local machine.
-
Install the required Python packages using pip:
pip install PyP100 requests python-dotenv astral schedule
- Set up the configuration file:
- Rename the file
config_example.env
folder toconfig.env
. - Modify the relevant elements in
config.env
with your own values (API keys, coordinates, Tapo devices, etc.).
To run the program, navigate to the main folder and execute the scheduler.py
file:
python scheduler.py
The behavior of the Tapo devices (turning on or off) is determined based on the cloudiness data obtained from OpenWeatherMap API. If the cloudiness percentage exceeds the specified breakpoint in the config.env
file, the devices will be turned on. Otherwise, they will be turned off.
The scheduler.py
file is responsible for scheduling the execution of the Tapo device control based on the specified coordinates and sunset time. Here's how it works:
-
The program retrieves the sunset time for the specified coordinates using the
set_sunset_time()
function. -
The script determines the range of hours during which it needs to be executed based on the current time and the sunset time using the
get_target_range()
function. -
It schedules the execution of the
start_control()
function to run 1 minute before every hour within the target range using theschedule_action()
function. -
The script enters a loop that continuously checks the current hour and executes the pending scheduled events using the
schedule.run_pending()
function. -
The program waits until the next hour using the
wait_until_next_hour()
function. -
Steps 4 and 5 are repeated until the current hour exceeds the last hour within the target range.
-
Finally, the program waits until 1:00 AM and repeats the entire process starting from step 1.
- To customize the behavior of the program, modify the values in the configuration file (
config.env
).
- If you encounter any issues or errors, please refer to the program's log file
app.log
for detailed error messages and troubleshooting information.
- The PyP100 library by fishbigger is used for controlling Tapo devices.
This program is licensed under the Apache 2.0 License.