A Python microservice that automatically controls an outdoor fridge based on ambient temperature. It turns the fridge ON when it's warm enough to need cooling, and turns it OFF when it's too cold; protecting both the appliance and the food inside.
I keep a fridge on my terrace for weekly meal prep, but standard fridges aren't designed to operate in temperatures below
This service connects to a Tapo smart plug (P110) and monitors outdoor temperature via the OpenWeatherMap API. When the temperature rises above a safe threshold, it turns the fridge on. When it drops back below the threshold, it turns the fridge off. The fridge runs only when needed, reducing the risk of damage even though I’m operating it under suboptimal conditions (around
-
Temperature above threshold (default:
$≥5 \degree \text{C}$ ) → plug turns on, fridge runs -
Temperature below threshold - delta (default:
$≤3 \degree \text{C}$ ) → plug turns off, fridge stops -
Temperature in between (
$3–5 \degree \text{C}$ by default) → idle, no change (prevents rapid switching)
A configurable hysteresis (TEMPERATURE_DELTA) avoids rapid on/off cycling when the temperature hovers near the threshold.
- Python 3.13
- A Tapo P110 smart plug (or compatible Tapo device)
- An OpenWeatherMap API key (free tier available)
-
Clone the repository:
git clone https://github.com/AleksaMCode/fridge-smart-plug-power-controller.gits cd fridge-smart-plug-power-controller -
Create a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate pip install -r requirements.txt -
Copy the settings template and configure:
cp settings.template settings.py
Edit
settings.pywith your credentials and preferences.
Edit settings.py with your own values:
| Variable | Description |
|---|---|
TAPO_EMAIL |
Your Tapo account email |
TAPO_PASSWORD |
Your Tapo account password |
TAPO_PLUG_IP |
Local static IP address of the smart plug |
OWM_API_KEY |
Your OpenWeatherMap API key |
OWM_LOCATION |
Location string for weather (e.g. "Paris, FR") |
TEMPERATURE_THRESHOLD |
Temperature ( |
TEMPERATURE_DELTA |
Hysteresis in |
CONTROLLER_TIMEOUT |
Seconds between temperature checks (default: |
Run the controller:
python controller.pyOr use the provided script:
./start_controller.shThe service runs continuously, checking the weather every logs/fsppc-info.log and to the console.
To run the controller automatically when the system boots, add a cron job using @reboot:
-
Make the script executable (if not already):
chmod +x start_controller.sh
-
Open the crontab for the user that will run the controller:
crontab -e
-
Add this line (replace
/path/to/fridge-smart-plug-power-controllerwith your actual project path):@reboot cd /path/to/fridge-smart-plug-power-controller && ./start_controller.sh >> logs/cron.log 2>&1 &The controller must be started from the project directory so the virtual environment and
settings.pyare found. The trailing&runs it in the background so cron does not block. Output is appended tologs/cron.logfor debugging.
Note
The controller will start once at boot and keep running. If you prefer automatic restarts on failure, consider a systemd service or process manager like supervisord instead.