DSL Ideas and Suggestions :: Simple low battery alert

Here's a simple low battery popup alert, saves that annoying feeling when the screen on my laptop suddenly goes black and anything in /home/dsl is lost.

If memory serves I wrote it this way because I found torsmo's battery monitoring in dsl didn't work properly on my friend's Sony Vaio VGN315S using dsl-2.1b.

I have a feeling lua can generate a system beep running from the background, if so that 'beep' line could be replaced with something in lua.

Code Sample


# Simple battery script called from torsmo

# modprobe battery needs to be done somewhere 1st
# installing beep is one way to make a noise from the background

MAXCAP=$(awk '/^last full capacity:/ {print $4}' /proc/acpi/battery/BAT0/info)

REMAINING=$(awk '/^remaining capacity:/ {print $3}' /proc/acpi/battery/BAT0/state)

CHARGING=$(awk '/^charging state:/ {print $3}' /proc/acpi/battery/BAT0/state)

(( TEST = REMAINING * 5 ))

if [ $CHARGING = discharging ]; then


if [ $TEST -le $MAXCAP ]; then
beep -l 400 -r 2
popup.lua "LOW BATTERY ALERT! Charge remaining = $REMAINING mAh Less than 20 per cent full.   Recharge now!"
echo "AC"

In ~/.torsmorc I have:

Code Sample
${color #ddd}Battery:  $color ${execi 60 ~/.battery_script}

The above assumes it's being run on a single battery laptop, but a more complicated script could examine /proc/acpi/battery to list batteries and then report on each (i suppose)

I tried out your script - in the original .torsmorc file there is already a line:
Code Sample
${color #ddd}Battery:  $color ${battery}

Do you mean to modify it to read as follows?
Code Sample
${color #ddd}Battery:  $color ${battery} ${execi 60 ~/.battery_sh}

The battery has not run down to 20% yet so I could not verify this works...

Thanks for providing the motivation to look at the .torsmorc file, I added the following line immediately after the battery line to show the cpu temperature:
Code Sample
${color #ddd}Temp:  $color ${acpitemp}degC

You could add to your script to call "exitcheck.sh shutdown" when the battery charge drops to 5% - This being said, on my machine the battery will last for at least 30 minutes when it shows less than 5 minutes life remaining
Code Sample
cat /proc/acpi/battery/BAT0/info

present:                 yes
design capacity:         42000 mWh
last full capacity:      20740 mWh
battery technology:      rechargeable
design voltage:          11100 mV
design capacity warning: 4200 mWh
design capacity low:     1272 mWh
capacity granularity 1:  420 mWh
capacity granularity 2:  420 mWh
model number:            DELL 0006T0
serial number:           404
battery type:            LION
OEM info:                Sanyo

Is there any way to change "last full capacity"?

From Google, there are a number of good (and complex - for me at least) scripts to catch all manner of acpi events using acpid and act on them. For example, from the above, I believe your script could be called on "design capacity warning: 4200 mWh" being met and shutdown called on "design capacity low: 1272 mWh" being met.

In a similar manner, cpufreqd (in 2.6.x) is using acpi events to make decisions like:

If the battery capacity is > 75% then run then run the cpu at full speed no matter what
If 25% < battery capacity < 75% then increase the cpu speed on only on demand
If battery capacity < 25% then run the cpu at minimum speed no matter what.

I believe a whole DSL library of acpi/acpid actions could be built on battery, fan, lid, powerbutton, temp, etc events - food for scripting thought...


Do you mean to modify it to read as follows?


I think last full capcity shows the battery's last maximum charge.  Batteries degrade with use/abuse so this probably drops during the life of the battery,  That's my guess anyway.  Should be in a man/doc page somewhere.

Lot of interesting ideas in your post Juanito.

original here.