Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to suspend when Ubuntu is at critically low power. The only option in Ubuntu 11.10 power setting is to shutdown or hibernate. I run my battery all the way down till it suspends then i plug it in. It gets annoying when my computer hibernates at critically low power.

Thanks in advance for the help

share|improve this question
1  
have you checked the power management??? I'm pretty sure there is an option for that! –  Vineet Menon Nov 3 '11 at 6:28
    
Yes I did unless Ubuntu power setting isn't the power manager. –  Ryan Nov 3 '11 at 13:47
1  
Is it just me or does everyone see images of food stuff in that link? ^ –  Mahesh Dec 2 '12 at 9:39
    
Nope that screen shot appears to be food stuffs. –  coteyr Dec 3 '12 at 17:12
    
I really hope this gets answered. Find this to be most annoying. –  coteyr Dec 4 '12 at 19:58

4 Answers 4

Not sure why power settings only offers hibernate or shutdown.
You can change the option to suspend using dconf-editor:
Browse to org->gnome->settings-daemon->plugins->power, and change the value of critical-battery-action to "suspend".

share|improve this answer
    
Doesn't seem to have any effect on my machine. :\ –  Tomislav Nakic-Alfirevic Jun 20 '12 at 21:11
    
This doesn't seem to do a thing on my machine. –  coteyr Nov 29 '12 at 2:38
    
I have confirmed that this DOES NOT WORK. It shows a message about suspending, then powers off the computer via shutdown. –  coteyr Nov 30 '12 at 20:40

Just a hunch, but I believe that at critically low power, the system doesn't have enough power to even sustain suspend mode - yes, the suspend mode, though is low on power consumption, draws power to keep data on the RAM. So, even if the system suspends, it will immediately power off. This is probably why jpd's solution didn't work.

Why I believe so? I've noticed that after the system powers off due to critically low power it is impossible (at least on my laptop) to turn it on without plugging it in. So critically low power must mean 'cannot carry on' and not 'just 5 minutes left' or something like that.

I think what you want is for the system to suspend when about 10 minutes of battery is left. I don't know how to attack that problem, but I believe Unity notifies you about this. In my case this notification is sufficient.

share|improve this answer
    
I checked this, and it doesn't seem right. The command executed is to shutdown not suspend. A suspend is not even attempted. –  coteyr Dec 2 '12 at 17:44

On my machine the current state of the battery can be read-off from /proc/acpi/battery/BAT1/state

Sample content of this file:

present:                 yes
capacity state:          ok
charging state:          charging
present rate:            749 mA
remaining capacity:      530 mAh
present voltage:         11200 mV

You can locate the appropriate file on your machine and use this to suspend when battery is in critically low power. The following python script will do it for you:

#!/usr/bin/python
import os
import time

battery_state_file = "/proc/acpi/battery/BAT1/state"
critically_low_power = 500
suspend_command = "sudo pm-suspend"

while True:
    time.sleep(1)
    f = open(battery_state_file)
    content = f.read().split('\n')
    f.close()
    if content[2].split()[2] == "discharging":
        if int(content[4].split()[2]) < 500:
            os.system(suspend_command)

Save this to a file (say) suspendscript, make it executable, add suspendscript & to .xsessionrc in your home folder, logout and log back in.

You have to set battery_state_file and critically_low_power appropriately. If remaining capacity drops below 'critically_low_power' mAh, the system will suspend. Optional: You can, if you want, use "present rate" and "remaining capacity" to find "expected time left" (= "remaining cap."/"present rate" hours) and suspend if time left drops below a certain threshold.

Notes:

  1. This code will have to be modified if the content of the statefile is not in the same format as the sample content given above.
  2. sudo pm-suspend requires the sudoer to give his password. You have to make pm-suspend sudoable without password. See how: Specific sudo commands without password . Alternatively, you can change suspend_command to simply pm-suspend and add sudo suspendscript & to .xsessionrc and make suspendscript sudoable without password.
  3. If you use this script, you have to set 'critically low power action' to 'do nothing' in gnome-power-manager settings.
share|improve this answer
    
@coteyr Did this work for you? –  S Prasanth Dec 13 '12 at 14:20

See my comment on Touchpad stopped working on an Acer AspireOne D255E - I think your problem is with the pm-utils package, too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.