charging_control
Описание
This project is a Linux-based battery management utility designed to extend laptop battery lifespan by automatically switching a smart plug on or off based on battery level.
Языки
- Python85,3%
- Shell14,7%
Smart Battery Charging Controller
This project is a Linux-based battery management utility designed to extend laptop battery lifespan by automatically switching a smart plug on or off based on battery level.
It includes:
- A Bash script to monitor battery status.
- A Python application to control a smart plug (via API).
- YAML configuration files for settings.
- A sample configuration directory.
📦 Project Structure
project-root/
├── battery_charger_control.sh # Main Bash script run by cron/systemd
├── SmartHouse.py # Python script to control smart device
├── config.py # Loading configuration Python module
├── alice_settings.yaml # Main configuration file
├── config_sample/ # Sample configuration files
│ └── alice_settings.yaml
├── .venv/ # Python virtual environment (created locally)
├── requirements.txt # Dependency definitions (managed by uv pip)
└── README.md
⚙️ Requirements
- Python 3.8+
for managing Python dependenciesuv- Compatible smart plug (e.g., TP-Link, Sonoff, etc.)
- Linux (tested on Ubuntu 24.04)
orsystemdsupportcron
🔧 Setup
1. Clone the Repository
2. Install Dependencies with uv
3. Configure
Copy a sample configuration to the project root:
Edit to match your device and environment.
🚀 Usage
Run Manually
Run Periodically via cron
Create a crontab record like this:
Run Periodically via systemd
- Create the service and timer units (see systemd example).
- Enable the timer:
To pause battery_control
Use a Conditional Inside the Script
Modify the script to exit early based on a flag file:
In battery_control.sh:
To pause:
To resume:
🔋 Battery Thresholds
Default behavior:
- Start charging when battery ≤ 40%
- Stop charging when battery ≥ 70% and status is Charging or Full
These can be customized in the script.
📂 Configuration
Place your device and API config in . A sample is available in .
🛠 Development Notes
- Logging is written to
or as configured.~/tmp/battery_control.out - Ensure all paths in scripts use full absolute paths.
- Scripts are written assuming execution via cron/systemd with minimal environment.
📜 License
✍️ Author
Nikolai Gorlov – gorlov-n@yandex.ru