This repository contains a Python-based service that checks the battery level of your system and provides alerts when the battery is low.
- Monitors battery level periodically.
- Sends notifications using
battery(Linux). - Automatically runs in the background as a systemd service after system boot.
Ensure the following are installed on your system:
- Python 3
sudo apt install python3
- psutil (for notifications)
pip install psutil
git clone https://github.com/goushalk/battery-alert.git
cd battery-alertchmod +x battery_alert.py-
Create a systemd service file:
sudo nano /etc/systemd/system/battery_alert.service
-
Add the following content to the file:
[Unit] Description=Battery Checker Service After=network.target [Service] ExecStart=/usr/bin/python3 /path/to/your/battery_alert.py Environment="DISPLAY=:0" Environment="XAUTHORITY=/home/<your-username>/.Xauthority" WorkingDirectory=/path/to/your Restart=always User=<your-username> Group=<your-username> [Install] WantedBy=multi-user.target
Replace
/path/to/yourand<your-username>with the actual path and your username. -
Reload and start the service:
sudo systemctl daemon-reload sudo systemctl enable battery_alert.service sudo systemctl start battery_alert.service -
Check the service status:
sudo systemctl status battery_alert.service
The script will run in the background and send notifications whenever the battery level drops below a certain threshold. You can modify the threshold by editing the script.
- View logs:
journalctl -u battery_alert.service
- Test the script manually:
python3 battery_alert.py
Feel free to fork the repository and submit a pull request. Suggestions and improvements are welcome!
This project is licensed under the MIT License.
Created by Goushal, aka op11r.