I am using a Linux distribution, I didn't get any notification even after the battery is full.
Is there any custom script to run battery charge status and output a sound notification when the battery is fully charged?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityI have written a small script that will do that:
Script:
#!/usr/bin/env bash
while true
do
export DISPLAY=:0.0
battery_percent=$(acpi -b | grep -P -o '[0-9]+(?=%)')
if on_ac_power; then
if [ "$battery_percent" -gt 95 ]; then
notify-send -i "$PWD/batteryfull.png" "Battery full." "Level: ${battery_percent}% "
fi
fi
sleep 300 # (5 minutes)
done
Installation:
Run:
sudo apt-get install acpi
git clone https://github.com/hg8/battery-full-notification.git
cd battery-full-notification/
chmod +x batteryfull.sh
Copy the script to ~/bin
folder:
cp batteryfull.* ~/bin
Or copy it to /usr/local/bin
if you want it to be available for all users on your computer:
cp batteryfull.* /usr/local/bin
Then add batteryfull.sh
script as a startup application by:
If you're using KDE SC as desktop environment, just do this:
You can write a custom script that checks /proc/acpi/battery/BAT0/state
and
gives you the feedback on the line charging state:
changing to charged
.
On newer systems you should use /sys/class/power_supply/BAT0/status
if available.
You only would need to check every minute or so, but since you want to know what the previous state was (so it won't beep every minute while it is full), you need to keep the previous state in a file to compare if you start the checking program from crontab, or run a long time process that checks every minute and keeps the previous state internally.
If you have multiple battery bays, you should have multiple entries under /proc/acpi/battery
(but not under /sys/class/power_supply/BAT*
) . If one of those entries has no state
, the battery is not inserted (you can also check the file info
for the value present)
state
file is not the same on all systems. I don't have a /proc/acpi/battery/BAT0/stat
file on my LMDE for example.
In case you are using KDE
/ Manjaro KDE like me. It can be configured in system settings. I enabled to start charging at 20%
(search for the depth of discharge
to know the reason why it is ideal to charge some batteries at 20%
) and stop charging at 80%
.
This Works in KDE 5
Installation:
Run:
sudo apt-get install acpi
git clone https://github.com/jruedaq/battery-full-notification-KDE5.git
cd battery-full-notification-KDE5/
chmod +x install
./install
acpi
print the battery state on your system?acpi -b | grep -P -o '[0-9]+(?=%)'
if [ $battery_level -eq 100 ] then notify-send "Battery low" "Battery level is ${battery_level}%!" fi