This program maintains a log of battery percentage and notify user using text and voice notifications
This program will maintain a log of battery percentage and notify users using text and voice notifications.
In Ubuntu 20.04, I was not getting any low battery notifications. My laptop was shutting down suddenly without any alert. I tried to use many tweaks from the Internet though nothing worked perfectly. Annoyed with the problem, I have created Battery Alert, a simple lightweight and customizable application for measuring battery percentage after a specific time interval.
The application has the following features -
Go to your terminal and run it as simple as the following -
python3 battery_alert.py
You can also customize the default parameters by doing the following -
python3 battery_alert.py --sleep_time=300 --log_percentage=1 --alert_percentage=20 --notification_alert=True --sound_alert=True
All the parameters are shown above with default values. You can customize them as you want.
sleep_time : (Datatype = Integer). Interval (in seconds) to check for the battery percentage. E.g, sleep_time=300
means the application will be activated after every 300 seconds (5 minutes).
log_percentage : (Datatype = Integer). Writes an entry in the log file after every log_percentage difference in battery status. E.g, log_percentage=1
means the application will add an entry after every 1% of change in battery status.
alert_percentage : (Datatype : Integer). The application starts sending text and/or sound alerts after alert_percentage. E.g, alert_percentage = 20
means, the application will send text and/or sound notifications when your laptop’s battery has 20% of charge and it is not charging.
notification_alert : (Datatype : Boolean). Whether to enable or disable text notification. E.g, notification_alert = True
means, the text notification is enabled.
sound_alert : (Datatype : Boolean). Whether to enable or disable the sound notification. E.g, sound_alert = True
means, the sound notification is enabled.
When the program is executed, the current time and date will be added in the log file named battery_alert.log. This date and time are considered as base time. Then it adds a log entry after every log_percentage apart as discussed above. The log entry will have four comma-separated values-
battery percentage, Whether charging or not, Time between every entry, Total time from base time to the current entry
E.g, Here the base date and time is 25th September 2021 at 11:38 pm. The third entry describes after 10 minutes from base time and after 5 minutes from the previous entry, the battery percentage was 77% and it is not charging.
Clone the repository by
git clone https://github.com/duttaprasanta/battery_alert.git
You may also download the zip file.
Then extract it.
This app requires the below 3
For the installation of the above packages use the below command -
<package manager> install <package name>
For example for ubuntu it should be as follows-
sudo apt-get update
sudo apt-get install python3-pip
sudo apt-get install gcc
sudo apt-get install espeak
sudo apt-get install libdbus-glib-1-dev libdbus-1-dev
Then install the pip dependencies as follows-
pip install --upgrade pip
pip install -r requirements_linux.txt
pip install --upgrade pip
pip install -r requirements_windows.txt
If you face dependency conflicts, create a virtual environment and follow the above steps. You may also try the tested-dependencies - requirements_linux_legacy.txt/ requirements_windows_legacy.txt
First unplug the charger from your laptop. Then execute the below command -
python3 battery_alert.py --log_percentage=1 --alert_percentage=100 --sleep_time=0
You should see a text notification and hear a sound alert upon successful execution of the above command.
Create an entry in the Startup Application app
python3 <path to the parent folder of the app>/battery_alert.py
Run the following command:
python win_autostart.py
A file named battery_alert.vbs
will be generated. Now you paste the shortcut of that file inside the following folder
C:\Users\<WindowsUserName>\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Notes
- Replace
<WindowsUserName>
with your user name.- By default
AppData
file is hidden. To view that click onView
>Hidden items
on File Explorer.- If you want to change the default parameters of the program, you need to change that inside the generated file named
win_autostart.bat
also.
Project Website : https://duttaprasanta.github.io/battery_alert
Project Link : https://github.com/duttaprasanta/battery_alert
Email : prasanta7dutta@gmail.com
If you like this repository, kindly :star: it and follow me.