You are not logged in.

#1 2009-01-03 19:32:17

patrickthebold
Member
Registered: 2008-12-15
Posts: 55

Suspend on Low Battery?

Hi eveyone I'm new to Arch and I would like it to suspend or maybe shutdown when the battery gets low.  I looked around and I got confused by all the options.  Right now I have acpid installed.  I start hal in my rc.conf DEAMONS, which starts acpid.  I put two files in /etc/acpi/events that shutdown the computer if I hit the power button and suspend if I close the lid on my laptop.  It seems that I should be able to add an additional file that will suspend when the battery gets low, but I don't know what I should put in it. 

Any help would be appreciated.

Also I did search and someone suggested using laptop-tools to do this, but it seemed much more complicated to set up, but if it is worth it let me know. 

Oh and I have and aspire one, and am trying to avoid installing gnome/gnome power manager.

Offline

#2 2009-01-03 19:37:33

djnm
Member
From: USA
Registered: 2008-12-21
Posts: 78

Re: Suspend on Low Battery?

You could make a script that checks your battery level and, if its less than a certain level, suspend the computer.  Put that script in a 5 minute cron job and that could work.

Last edited by djnm (2009-01-03 19:37:47)


br0tat0chip in #archlinux and on freenode

Offline

#3 2009-01-03 19:43:21

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Suspend on Low Battery?

Personally I use laptop-mode-tools for this, since I use it anyways, but if you want a standalone script you can try this: http://en.gentoo-wiki.zugaina.org/index … ery_is_Low

Offline

#4 2009-01-03 20:48:45

firecat53
Member
From: Lake Stevens, WA, USA
Registered: 2007-05-14
Posts: 1,542
Website

Re: Suspend on Low Battery?

Laptop-mode tools works great .... configuration is in /etc/laptop-mode/conf.d/auto-hibernation.conf.

Good luck!
Scott

Offline

#5 2009-01-03 21:21:21

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: Suspend on Low Battery?

Not all batteries report events and have alarm support (while some report back but very rarely (or only on AC events) so it's not good enough for laptop-mode-tools hibernate module). First check your acpid logs and see if you have regular BAT reports... if not, the script from Gentoo wiki is good enough (btw the author of laptop-mode-tools said that in the future such script could be included in the package, for less fortunate folks).


You need to install an RTFM interface.

Offline

#6 2009-01-03 23:15:08

patrickthebold
Member
Registered: 2008-12-15
Posts: 55

Re: Suspend on Low Battery?

$ cat /var/log/acpid.log |grep -i bat
returns nothing
and
$ cat /proc/acpi/battery/BAT1/alarm
returns 
alarm:                   unsupported

I think this means I need to try the gentoo scripts/ write my own.

Oh and does laptop-mode-tools used acpid or does it replace acpid?  I have and SSD but it seems like it might still have some power saving features.  I will look into it.

Offline

#7 2009-01-04 03:36:22

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 834
Website

Re: Suspend on Low Battery?

Oh and does laptop-mode-tools used acpid or does it replace acpid?

Laptop-mode-tools is just a shell script that performs a bunch of actions when called. It comes with it's own scripts to use as acpid event handlers, but you can discard those and call laptop-mode-tools from your own handler(s) on AC/ADP events (/usr/sbin/laptop_mode auto), if you choose so.

Edit: Just to be clear, it should also be called on BAT events for auto-hibernate module (apparently useless on your system)

Last edited by anrxc (2009-01-04 03:44:01)


You need to install an RTFM interface.

Offline

#8 2009-01-04 05:04:12

steve___
Member
Registered: 2008-02-24
Posts: 452

Re: Suspend on Low Battery?

Here is the script I have cron'd, running every five minutes:

$ crontab -l |grep suspend
*/5 * * * * $HOME/bin/suspend.sh
$ cat suspend.sh 
#!/bin/bash

battery='-';
bat_dir="/proc/acpi/battery/BAT0";

if [ -d "$bat_dir" ]; then
        remaining="$(awk '/remaining capacity/ {print $3}' <${bat_dir}/state)"
        total="$(awk '/last full capacity/ {print $4}' <${bat_dir}/info)"
        battery_level="$((remaining *100 /total))"
        battery="${battery_level}"
fi

if (( "${battery}" <= 5 )); then
        /usr/sbin/pm-suspend
fi

echo "${battery}"

Offline

#9 2009-01-04 05:21:26

patrickthebold
Member
Registered: 2008-12-15
Posts: 55

Re: Suspend on Low Battery?

Thanks eveyone I got it working.  I decided on using a shell script.  I do have one more question.  Since I don't have a hard disk is there any power saving benefits from laptop-mode-tools?  I do have frequency scaling being handled (by hal I think).  I don't see how it would help, but anything to impove battery life is good.

Oh and I really like arch!

Offline

#10 2009-01-04 08:09:16

fwojciec
Member
Registered: 2007-05-20
Posts: 1,411

Re: Suspend on Low Battery?

See for yourself if it makes any difference -- just use powertop to monitor power use with and without laptop-mode-tools enabled.

Offline

#11 2010-12-29 21:51:22

xirtyllo
Member
Registered: 2009-02-15
Posts: 7

Re: Suspend on Low Battery?

I tried steve's suspend.sh script but when i try to execute it i get the following error:

/bin/suspend.sh: line 13: ((: - <= 5 : syntax error: operand expected (error token is "<= 5 ")

Anyone can help me to understand the reason?

I must add that I'm not using Arch linux, I'm using Salix 13.1 (based on Slackware 13.1)...

Offline

#12 2010-12-29 21:57:13

BaconPie
Member
Registered: 2010-08-11
Posts: 209

Re: Suspend on Low Battery?

xirtyllo wrote:

/bin/suspend.sh: line 13: ((: - <= 5 : syntax error: operand expected (error token is "<= 5 ")

The battery variable is not being set to anything other than a dash (-) and it's erroring on the comparison between the - and a number.

If I were you, I'd write my own script.

Offline

#13 2010-12-30 16:25:35

xirtyllo
Member
Registered: 2009-02-15
Posts: 7

Re: Suspend on Low Battery?

OK, i found the problem, my mistake!

In my case i had to change from  /proc/acpi/battery/BAT0 to /proc/acpi/battery/BAT1.

the script seems to work excellent now!

Offline

Board footer

Powered by FluxBB