5

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?

6
  • 1
    Which distribution are you using? Jan 14, 2014 at 5:35
  • We can't help unless we know your distribution and your desktop environment. Does acpi print the battery state on your system?
    – terdon
    Jan 14, 2014 at 12:43
  • Sorry for the delay, I am using Ubuntu, Thank you. yes, acpi print the battery state in my system.
    – user9744
    Jan 14, 2014 at 18:41
  • 1
    battery_level=acpi -b | grep -P -o '[0-9]+(?=%)' if [ $battery_level -eq 100 ] then notify-send "Battery low" "Battery level is ${battery_level}%!" fi
    – user9744
    Jan 14, 2014 at 18:47
  • I have added the above script run as cronjob which making the script execute every minute, like :* * * * * battery_full.sh, Is it work?
    – user9744
    Jan 14, 2014 at 18:50

5 Answers 5

6

I have written a small script that will do that:

screenshot


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:

  • Open Dash
  • Search for Startup Applications
  • Double-click the icon
  • Click Add and fill in as follows:

    startup application batteryfull

1
  • 1
    thanks, it's helpful for me,, and nice sound for get attention.. :D
    – Budi Mulyo
    Aug 9, 2019 at 3:18
3

If you're using KDE SC as desktop environment, just do this:

  • Open System Settings
  • Go to Application and System Notifications (Section: Common Appearance and Behavior)
  • If not already selected, choose Manage Notifications from the list on the left side
  • Select Power Management System from the Event source drop-down menu
  • Click on the list entry Charge Complete
  • Select any kind of notification/sound: Power Management System Notification Settings
  • Click Apply
2

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)

1
  • 1
    The location of the 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.
    – terdon
    Jan 14, 2014 at 12:42
0

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%.

enter image description here

0

This Works in KDE 5

KDE alert

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .