This website uses cookies to improve your experience. By using this site, we will assume that you're OK with it. Accept Read More
This article covers the different methods to check your battery health monthly to keep its charging cycle and usage optimized. For this purpose, you can use the "acpi" command. The acpi command shows battery status and other ACPI information in your Linux distribution. You might need to install acpi command in some Linux distributions. On Arch Linux and its derivatives: $ sudo pacman -S acpiTo install acpi on Debian, Ubuntu and its derivatives: $ sudo apt-get install acpiOn RHEL, CentOS, Fedora: Or, $ sudo dnf install acpiOnce acpi installed, run the following command: $ acpi -V
Linux OS in Laptops are good for Nix users, but it often drains the battery. Have tried many Linux operating systems, but long battery life is not evident like Windows. Recommended to avoid charging a battery for a longer duration which might affect the battery hence unplug the power cable when it reaches 100% charge limit. There is no default application to notify us, when the battery is fully charged or discharged. To receive the notification, we rely on the third-party application. Initially, preferred to use Battery Monitor application to receive notification, but this app was deprecated. To overcome the third party app usage, I have created a shell script to receive the notification. Laptop battery charging and discharging status can be identified using the following two commands. Using acpi command. $ acpi -bBattery 0: Discharging, 71%, 00:58:39 remaining Using upower command. $ upower -i /org/freedesktop/UPower/devices/battery_BAT0 | grep -w 'state|percentage' | awk '{print $2}'discharging64% Method-1: Receive an alert, when the battery level is above 95% or below 20%This shell script runs in the background on startup and checks the battery status every minute and then sends a notification when the battery level is charged above 95% or discharged less than 20%. The alert will not get turned off, until your battery is over 20% or less than 95% charged. $ sudo vi /opt/scripts/battery-status.sh #!/bin/bash while true do battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'` if [ $battery_level -ge 95 ]; then notify-send "Battery Full" "Level: ${battery_level}%" paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga elif [ $battery_level -le 20 ]; then notify-send --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%" paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga fi sleep 60 doneOnce the script is ready, set the executable permission. $ sudo chmod +x /opt/scripts/battery-status.shFinally, add the script to the bottom of the user profile file. For system-wide users, add the script on the /etc/profile file. This profile file will allows the system to kick the script when the system starts. $ vi ~/.profile sh /opt/scripts/battery-status.sh &Reboot your Linux system to verify the notification status. $ sudo rebootMethod-2: Receive notification, when the battery level is charged (above 95%) or discharged (below 20%)This script is similar to the above script, but it is in Sync with the AC adapter. If the AC adapter is plugged in and the battery is charged above 95%, it will trigger a notification with a sound, but the notification will not stop until the AC adapter is unplugged. If AC adapter is unplugged, notification will not appear again until the battery charge drops to 20%. $ sudo vi /opt/scripts/battery-status-1.sh #!/bin/bash while true do export DISPLAY=:0.0 battery_level=`acpi -b | grep -P -o '[0-9]+(?=%)'` if on_ac_power; then if [ $battery_level -ge 95 ]; then notify-send "Battery Full" "Level: ${battery_level}% " paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga fi else if [ $battery_level -le 20 ]; then notify-send --urgency=CRITICAL "Battery Low" "Level: ${battery_level}%" paplay /usr/share/sounds/freedesktop/stereo/suspend-error.oga fi fi sleep 60 doneOnce the script is ready, set the executable permission. $ sudo chmod +x /opt/scripts/battery-status-1.shFinally, add the script to the bottom of the user profile file. For system-wide users, add the script on the /etc/profile file. $ vi ~/.profile sh /opt/scripts/battery-status-1.sh &Restart your system to verify the notification status. $ sudo rebootConclusionThis article gives an idea of using our own script instead of using any third pary application to receive Battery status notification. Kindly support us by sharing this article, if found helpful! Ref: stackexchange
Using Linux, Devuan Release 4 chimaera (Debian derivative--non-systemd, parallel to Bullseye) I have a Thinkpad x220 laptop. The battery has plenty of power. I can keep the laptop on for a few hours, but I keep getting a pair of notifications popping up saying "Battery Low". I would like to know:
See image below:
|