charging_control

0

Описание

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%
10 месяцев назад
10 месяцев назад
10 месяцев назад
10 месяцев назад
README.md

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+
  • uv
    for managing Python dependencies
  • Compatible smart plug (e.g., TP-Link, Sonoff, etc.)
  • Linux (tested on Ubuntu 24.04)
  • systemd
    or
    cron
    support

🔧 Setup

1. Clone the Repository

2. Install Dependencies with
uv

3. Configure

Copy a sample configuration to the project root:

Edit

alice_settings.yaml
to match your device and environment.


🚀 Usage

Run Manually

Run Periodically via cron

Create a crontab record like this:

Run Periodically via systemd

  1. Create the service and timer units (see systemd example).
  2. 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

battery_charger_control.sh
script.


📂 Configuration

Place your device and API config in

config.yaml
. A sample is available in
config_sample/config_sample.yaml
.


🛠 Development Notes

  • Logging is written to
    ~/tmp/battery_control.out
    or as configured.
  • Ensure all paths in scripts use full absolute paths.
  • Scripts are written assuming execution via cron/systemd with minimal environment.

📜 License

MIT License


✍️ Author

Nikolai Gorlov – gorlov-n@yandex.ru