You are not logged in.

#1 2009-03-13 10:48:52

orjanp
Member
From: Tromsoe, Norway
Registered: 2004-07-03
Posts: 347

Getting a warning when battery power gets low.

MOD NOTE: This topic has a history of being necrobumped. If you are seeking a solution, please see this topic -- WorMzy

----------

Hello!

I would like to get a warning, like a window popping up, saying that my battery power is running low. How can this be done?

Is it possible to make my machine hibernate if I don't connect it to power if I don't react to the warning?

I'm using a Lenovo Thinkpad T400, with an updated Arch installation, running Fluxbox.

Last edited by WorMzy (2015-07-20 12:54:15)


Ørjan Pettersen

Offline

#2 2009-03-14 10:00:20

Barghest
Member
From: Hanau/Germany
Registered: 2008-01-03
Posts: 563

Re: Getting a warning when battery power gets low.

You may take a look at noteo (AUR).

IIRC you can also give a command to hibernate.

laptop-mode-tools for sure give the possibility to say that the laptop has to hibernate when a critical battery status is reached.

Barghest

Offline

#3 2009-04-15 15:12:13

orjanp
Member
From: Tromsoe, Norway
Registered: 2004-07-03
Posts: 347

Re: Getting a warning when battery power gets low.

Noteo did't work for me. I never got any warning. I think it is correctly configured.


Ørjan Pettersen

Offline

#4 2009-04-16 08:04:53

atasmrk
Member
Registered: 2007-05-07
Posts: 23

Re: Getting a warning when battery power gets low.

I use this script to alert me when battery is low

#!/bin/bash
#
 #low battery in %
LOW_BATTERY="10"
 #critical battery in % (execute action)
CRITICAL_BATTERY="5"
 #sleep time 4 script
SLEEP="60"
 #acpi battery name
BAT="BAT0"
 #action
ACTION="/sbin/poweroff"
 #display icon
ICON="/usr/share/icons/oxygen/48x48/devices/battery.png"
 #notify sound
PLAY="aplay /usr/local/bin/bears01.wav"

MAX_BATTERY=$(cat /proc/acpi/battery/BAT0/info | grep 'last full' | awk '{print$4}')
LOW_BATTERY=$(($LOW_BATTERY*$MAX_BATTERY/100))
CRITICAL_BATTERY=$(($CRITICAL_BATTERY*$MAX_BATTERY/100))

while [ true ]; do
    if [ -e "/proc/acpi/battery/$BAT/state" ]; then
        PRESENT=$(grep "present:" /proc/acpi/battery/$BAT/state | awk '{print $2}')
        if [ "$PRESENT" = "yes" ]; then
            
            STATE=$(grep "charging state" /proc/acpi/battery/$BAT/state | awk '{print $3}')
            CAPACITY=$(grep "remaining capacity" /proc/acpi/battery/$BAT/state | awk '{print $3}')

            if [ "$CAPACITY" -lt "$LOW_BATTERY" ] && [ "$STATE" = "discharging" ]; then
                $($PLAY)
                DISPLAY=:0.0 notify-send -u critical -t 5000 -i "$ICON" "Battery IS low. Plug or Pray." "remaining $CAPACITY mah, shutdown @ $CRITICAL_BATTERY mah"
            fi

            if [ "$CAPACITY" -lt "$CRITICAL_BATTERY" ] && [ "$STATE" = "discharging" ]; then
                $($ACTION)
            fi
        fi
    fi
    sleep $SLEEP
done

You have to install notification-daemon or you can look here http://bbs.archlinux.org/viewtopic.php?id=67565

Last edited by atasmrk (2009-04-16 08:09:22)

Offline

#5 2009-04-16 23:37:17

kremso
Member
Registered: 2008-06-17
Posts: 14

Re: Getting a warning when battery power gets low.

Try batterymonitor.

http://code.google.com/p/batterymon

The code in batterymon-hal branch issues low battery notifications (via libnotify) and lets you specify a command to run on critical battery level (eg. sudo pm-hibernate). It's not officially released yet, but give it a try.

Offline

#6 2009-05-01 10:39:34

orjanp
Member
From: Tromsoe, Norway
Registered: 2004-07-03
Posts: 347

Re: Getting a warning when battery power gets low.

Thanks.

Decided to use the script provided by atasmrk for now. Just made some modifications(removed the while loop) and ran it as a cronjob.


Ørjan Pettersen

Offline

#7 2009-05-01 12:02:27

stefanwilkens
Member
From: Enschede, the Netherlands
Registered: 2008-12-10
Posts: 624

Re: Getting a warning when battery power gets low.

I don't know if flux can load gnome applets, but you might have a look at it:
image.php?id=ubuntu_battery_life&image=ubuntu_battery_7


Arch i686 on Phenom X4 | GTX760

Offline

#8 2013-05-11 21:37:04

sanczol
Member
From: Warsaw, Poland
Registered: 2013-03-16
Posts: 7

Re: Getting a warning when battery power gets low.

Little optimization and mod to atasmrk script that works for me:

#!/bin/bash

# low battery in %
LOW_BATTERY="15"
# critical battery in % (execute action)
CRITICAL_BATTERY="10"
# action
ACTION="/sbin/poweroff"
# display icon
ICON="/opt/icons/battery-low-icon.png"
# path to battery /sys
BATTERY_PATH="/sys/class/power_supply/BAT1/"


if [ -e "$BATTERY_PATH" ]; then
    BATTERY_ON=$(cat $BATTERY_PATH/status)

    if [ "$BATTERY_ON" == "Discharging" ]; then
        CURRENT_BATTERY=$(cat $BATTERY_PATH/capacity)

        if [ "$CURRENT_BATTERY" -lt "$CRITICAL_BATTERY" ]; then
            $($ACTION)

        elif [ "$CURRENT_BATTERY" -lt "$LOW_BATTERY" ]; then
            notify-send -i "$ICON"  "Battery IS low - $CURRENT_BATTERY %."
        fi
    fi
fi

Laptop Samsung 900X4C-A03
Laptop Samsung RF711, Cpu: Quad core Intel Core i7-2630QM, Kernel: Current x86_64, RAM: 8GB
Drives: SAMSUNG_470_Seri 64.0GB, WDC_WD5000BEVT 500.1GB
Graphics: Intel Integrated Graphics Controller, NVIDIA Corporation GF108 [GeForce GT 540M] (Optimus)

Offline

#9 2013-05-11 22:38:44

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: Getting a warning when battery power gets low.

If you are using #!/bin/bash, you can use the bash `[[` test and you can save some cats:

 BATTERY_ON=$(<$BATTERY_PATH/status)

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB