Warn when battery is low

2020-08-30 218 words 2 mins read

I am very lazy to look at battery status and want to be warned when the battery is low. This means that even if I am away from the laptop, I can be warned that laptop is about to poweroff due to battery low. So, what kind of alerts I can have, many -

  1. zenity message box
  2. email
  3. sms with twillio
  4. Telegram message and possibility is endless.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22

LOW=35 ## This si the lowest percentage at which I want the alerts.
## Parse the acpi statue and decide if alert needs to be sent
per=$(/usr/bin/acpi -b | awk '{print $4}'|sed 's/%.*//') 

# source ~/bin/cron-scripts/sendsms.sh
if [[ $(/usr/bin/acpi |grep -c "Full\|Charging") > 0 ]]
then
    #This is when the AC is connected.
    exit 0
fi


if [[ ! -z $per && $per < $LOW ]]
then
    # sendsms "Battery is at $per%"
    export sub="Battery is at $per%"
    echo "Battery is running out : $per"|/usr/sbin/sendmail -t
    display_msg.sh "ACPI Warn" "Battery is at $per%"
    echo "ACPI Warn" "Battery is at $per%" | /home/amitag/bin/twilio-sms +919535210501
    zenity --warning --text="Battery is at $per%"
fi

Put this script somewhere and schedule in cron for every minute and enjoy.

Hope this is useful for you.

Related Articles:


author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it