Getting a warning when battery power gets low.

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.

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)

Similar Messages

  • Iphone 4 auto shut off when battery 20% and lower.

    My Iphone 4 auto shut off when battery 20% and lower. The phone is only 1.5 years old. Can I know why this happen?

    Most commom reason for this is faulty battery. You could try Restore with iTunes on computer, at end when prompted, Set Up iPhone as New. If still problem and you have AppleCare, take to Apple for resolution. If no coverage, make Genius reservation and take to Apple Store for quick free battery diagnostic testing.

  • Computer turns off without warning on battery power

    Starting a few weeks ago I've found that my Macbook Pro has been turning off without warning while on battery power. The first time this happened it was after about an hour of use and now it happens within a half hour or less. If I try turning it back on it shuts off before OS X is fully loaded. According to CoconutBattery my battery's health is at 97%, so the battery isn't losing overall charge capability. When I'm on battery power it says I have 2-3 hours of battery life left. Sometimes I notice this will drop between 1-2 hours after 20-30 min of use (if it'll stay on that long) but it never drops and gives me a warning of low battery. It just shuts off without warning. If I press the button on the battery after this happens I do get 4 out of 5 lights. This never used to be a problem. My computer is 14 months old. I've replaced the battery once about 8 months ago (under warranty) because my original battery was losing capacity very quickly. Because 14 months have passed I can't simply get a new battery under warranty. According to Cocoanut Battery and the Finder my battery should last near it's full capacity. I can't figure out why it's randomly shutting off. I have had all the latest updates including the recent battery patch. Any help would be greatly appreciated. I will award "solved" for a solution and "helpful" for posts that contribute to the solution. thanks!
    Message was edited by: Vegabondsx
    Message was edited by: Vegabondsx

    Because 14 months have passed I can't simply get a new battery under warranty.
    Actually (and fortunately), that's incorrect. Apple extended the warranty for all Core Duo notebook batteries to *2 years* from date of purchase. Details are here:
    http://www.apple.com/support/macbook_macbookpro/batteryupdate/
    Your full charge capacity is fine (as you noted). But one of the symptoms listed on the linked page is +"Battery exhibits low charge capacity/runtime when using a fully charged battery with a battery cycle count (as shown in System Profiler) of less than 300."+ The word runtime in there applies, so I would call Apple or make a Genius Bar appointment and head into a store. (I did the latter, they replaced mine - free of charge - 15 months after purchase, no AppleCare, and no hassles).
    Hope this helps...

  • Iphone 5 random shutdown when battery is not low?

    Recently My iphone5 keeps shutting down itself randomly when it still has enough battery. It could happen when battery is 50%, or 60%. The lower battery, more frequently does shutting down happen. It is the latest ios7 version. And I tried to enter DFU mode and restored my iphone. But the problem is still unsolved. I want to know if it is a hardware problem, or something wrong with iOS system. And what further steps I should take. I don't think restoring it again in DFU mode would help.

    There are other conditions that cause the iPhone to shut down - not only a low battery.
    Examples:
    Operating the iPhone in a temperature that is too hot.
    Operating the iPhone in a temperature that is too cold.
    Storing the iPhone in a temperature that is too hot.
    Storing the iPhone in a temperature that is too cold.

  • HP Pavilion g6 Notebook - Sudden shutdowns without warning when battery is low

    My notebook is only ten months old. Within the last week, it started shutting down unexpectedly when the battery was low (but not at a critical level). If I try to restart it, there won't be a response until I plug in the adaptor cord. Usually there will be around 20% of my battery left when my computer is booted up after such a shutdown, so I don't think it's because of my battery being low. (Besides, when I've accidentally used my laptop until it has to hibernate, the light next to the port for the adapter cord usually blinks to tell me it's the battery.)
    Initially I thought it was a problem with overheating, so I cleaned my vents and bought an external laptop cooler when it first shut down unexpectedly two weeks ago. However, the shutdowns have become more frequent since then. I've run the Memory Diagnostic Tool, the HP Battery Check, and updated my BIOS. No problems have come up; in fact, everything seems to be running perfectly. I also ran AVG and Malwarebytes Anti-Malware. No problems there either.
    What could be the problem? Thanks for any help!
    Product name: HP Pavilion g6 Notebook PC
    Product number: A1J18AV
    Windows 7 Home Premium 64-bit Service Pack 1

    Mines started doing exactly the same! Its just 12 months old though and hardly ever gives me a low battery warning. Then it will turn off without shutting down the proper way. When I plug in and turn back on, the battery says its at 20-25%
    Is there actually a solution to this and whats causing it?..because if it's the battery then **bleep**..they don't last long.

  • Low battery warning when battery full

    This only happened to me this one time, but I have my iphone plugged in and the battery icon says it is fully charged, but I received a "low battery" warning.
    Any thoughts as to why this may have happened?
    Thanks!

    What version of firmware are you on? There were battery gauge problems in 3.1.2 that 3.1.3 is supposed to fix. Meanwhile, you can try running the battery down until the phone shuts off, then plug in to the wall charger for 4 hours. Do this twice. if it still doesn't work right you may have a bad battery; take it to Apple.

  • IBook G4 1.42 GHz shut down when battery storage is lower than 60%

    Hello everybody.
    My iBook G4 has been used for 10 month and updated to OSX 10.4.6. Three days ago, it shut down immediately without any warning. After this experience, I checked the battery information at two situation:
    Battery is charged:
    Battery Installed: Yes
    First low level warning: No
    Full Charge Capacity (mAh): 2946
    Remaining Capacity (mAh): 2935
    Amperage (mA): 0
    Voltage (mV): 16615
    Cycle Count: 189
    Battery is about 60% storage:
    Battery Installed: Yes
    First low level warning: No
    Full Charge Capacity (mAh): 2946
    Remaining Capacity (mAh): 1764
    Amperage (mA): -1825
    Voltage (mV): 15438
    Cycle Count: 189
    I am sure that the voltage and remaining capacity of the battery before the sudden shutting down are reasonable, just like what you can see above, and the LED indicator on the battery sitll indicates 3 green light.
    I have already reset the PRAM ,NVRAM, and PMU successfully, but the sudden shutting down still exists. If the AC power is plugged, everything will be ok.
    Can someone resolve my problem? Please forgive my poor English. Thanks a lot.
    iBook G4 1.42GHz   Mac OS X (10.4.6)   1.5 GB ram

    Try another battery. Since you have calibrated your battery weekly, it may need to be replaced. (Apple recommends monthly calibration.)
    The typical lifespan of a lithium-ion battery is two to three years. Some last a bit longer, but some don't last that long, either.
    It may just be that your battery needs to be replaced.
    From that Apple page on batteries:
    A properly maintained Apple notebook battery is designed to retain up to 80% of its original capacity after 300 full charge and discharge cycles.
    Click on the Apple icon in the top left corner of the display. When the information box pops up, click on "More Info…" The System Profiler will appear. Click on the Hardware disclosure triangle (if necessary). Click on Power. See how many cycles your battery has used to determine if your battery may be eligible for replacement under warranty. If it has less than 80% of its original capacity with 300 or fewer charge cycles used, you may have a case for asking for a replacement battery without cost to you.
    Good luck.

  • MacBook shuts down instead of sleeping when battery low

    Like many people, I had the infamous MacBook sudden shutdown problem where my MacBook (original model) would suddenly shut down wihtout warning regardless of if it was running off battery or AC adapter. I took the MacBook into the Apple store, they did their magic, and two weeks later an updated MacBook was shipped to me, free of the problem. I also applied the firmware update when it came out.
    Now I have a new problem...it's that the MacBook doesn't seem to want to sleep when the battery gets low. Instead, it will suddenly shut down without warning. In the past, I seem to recall that it would give alerts saying that my power was low, and eventually force itself to sleep. However, now the battery can be as high as 15-20% and the MacBook will shut down. This never happens when the battery is not on the low side, so I'm wondering if this is a problem with the MacBook guaging how much power it has left. Sometimes, I notice that when I plug it in and reboot, the battery says it is at 0%, even though it clearly was not prior to the shutdown (though that didn't happen just now when it shut down - when I rebooted after connecting the AC adapter, it was at 15%).
    I tried resettting the SMC firmware, which seems to help transietly, but the problem recurs. 90% of the time I use my computer plugged in, so that's why I've not noticed it much

    The same thing happened to me last night -- the Macbook shut down because of low battery instead of sleeping, and it gave no warning messages at all as the battery power got low.
    I never had the sudden shutdown problems, though.
    I also checked the battery capacity with CoconutBattery, and it reported that the Max Battery Capacity was 4105 mAh, which is only 78% of the battery's original max capacity. Today, CoconutBattery reports that the battery's max capacity is 5035 mAh (96% of original capacity), which is more reasonable for a laptop less than a year old.
    Perhaps resetting PRAM or the Power Management Unit could solve this problem.
    Any experts out there with a solution?
    MacBook   Mac OS X (10.4.8)  

  • Battery power consumption has gone mad...!

    I have an iphone 5 IOS 7.0.4
    Suddenly the battery consumption has gone crazy.  The phone feels warm and and 100% of power is used over 4hours with phone in standby. 
    The power lasts if I turn off mobile data.  I have no apps running and location services icon is not showing?
    I did find that I have used up all of my icloud storage .. I have resolved this issue now..
    There seems to be a hidden process that is using power..  I do not know how to track this down... any suggestions please?

    Hi and welcome to the community! Since you're new please be sure that you have checked out our Discussion guidelines.
    Sorry to hear that you're having issues with battery performance.
    I recommend that you first check what's using battery. Charge the battery full and then use the phone as you normally do. When battery level is low, go to Settings -> Power management -> Battery usage. What does it say here? By tapping the apps/functions in the list you can also se how long they have been active.
     - Official Sony Xperia Support Staff
    If you're new to our forums make sure that you have read our Discussion guidelines.
    If you want to get in touch with the local support team for your country please visit our contact page.

  • No sleep but shut down when battery drained

    Hi there,
    just bought a new battery for my MacBook - what happens now is that when I get the battery drained alert (10 min) my Mac quits just about 2 minutes thereafter. Unfortunately it doesn't go to sleep so I have to reboot it after connecting it to power...
    Any thoughts? Thanks!

    macbig, you haven't read much about recent Apple notebooks, have you? All portables since the first white MacBook has had a 'Safe Sleep' mode, which is supposed to activate automatically when battery power drops below a certain level. Active memory is saved to disk, and the computer shuts down all power draining activities. It is then essentially completely off. The difference between this and a standard shut down is that when the power button is next pressed (with a power supply connected), the system resumes after a short wait, with everything still open, just as it was left. This is very similar to a Windows PC's hibernation mode.
    What the original poster here is describing is the problem I am having which brought me here. The safe sleep mode fails to activate, whether the system is active or sleeping. It instead just shuts down hard, as an older model would. In my case, this behavior has been intermittent since my original purchase a year ago. I have calibrated my battery, reset the power management unit, and all the other recommended fixes. My battery is in excellent condition, and in my case, this shutdown doesn't occur until the indicated level is actually at 0%. Nevertheless, it is a feature which is supposed to work, but doesn't. I'm hoping someone else here has experienced this and found a cure.

  • What does it mean when I get this message:  "Battery is critically low"

    I am suddenly getting a message "the battery is critically low" - am I in danger here?????

    You're in danger of the Mac shutting down, that's all. Recharge your battery when you get a chance.
    If you believe the message is spurious an SMC reset is justified. Read all the steps:
    Before Resetting the SMC
    Try each of the following steps in this order before you reset the SMC. Test the issue after completing each troubleshooting step to determine if the issue still occurs.
    Press Command + Option + Escape to force quit any application that is not responding.
    Put your Mac to sleep by choosing the Apple () menu from the upper-left menu bar and then choosing Sleep. Wake the computer after it has gone to sleep.
    Restart your Mac by choosing the Apple () menu from the upper-left menu bar and then choosing Restart.
    Shut down your Mac by choosing the Apple () menu from the upper-left menu bar and then choosing Shut Down.
    Resetting the SMC on Mac portables with a battery you can remove
    Shut down the computer.
    Disconnect the MagSafe power adapter from the computer, if it's connected.
    Remove the battery (to remove the battery - click here: MacBook or MacBook Pro).
    Press and hold the power button for 5 seconds.
    Release the power button.
    Reconnect the battery and MagSafe power adapter.
    Press the power button to turn on the computer.
    Still having problems? Replace steps 6 and 7 with the following:
    Reconnect just the MagSafe power adapter.
    Press the power button to turn on the computer,
    Then reconnect the battery.

  • My iPad battery getting low quickly when im playing games. What should i do ?

    My iPad battery getting low quickly when im playing games. What should i do ?

    The quickest way (and really the only way) to charge your iPad is with the included 10W or 12W (5W on Mini) USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (2.5W, most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    How to Save and Prolong the battery life of your new ipad
    https://discussions.apple.com/thread/4480944?tstart=0
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
    iPhone, iPod, Using the iPad Charger
    http://support.apple.com/kb/HT4327
    Install and use Battery Doctor HD
    http://itunes.apple.com/tw/app/battery-doctor-hd/id459702901?mt=8
    To Extend a Device’s Battery Life, Get to Know It Better
    http://tinyurl.com/b67c7xz
    iPad Battery Replacement
    http://www.apple.com/batteries/replacements.html
    In rare instances when using the Camera Connection Kit, you may notice that iPad does not charge after using the Camera Connection Kit. Disconnecting and reconnecting the iPad from the charger will resolve this issue.
     Cheers, Tom

  • My phone seems to delete contacts and info when the battery gets low, is there a solution to this issue?!

    After the most recent update, I've noticed a couple MAJOR changes! 1) The battery life can barely make it through half the day. I have to keep charging it no matter how little I use it. I've even turned off apps running in the background, it didn't make much difference. And 2) When the battery gets really low, at the 10% mark, it deletes contacts and settings. I've lost so many contacts all of the sudden and I constantly have to restore my iPhone. It's so frustrating! And when the battery gets low, it also deletes my e-mail account to receive e-mails on the phone. I'm tired of having to constantly reset my phone carry a charger with me, it's not reliable any longer and I'm not sure why. Help??

    Here is some information on the applecare +:
    http://www.apple.com/support/products/iphone.html
    It appears that you have to buy the applecare within 30 days of buying your phone - you said that your phone warranty is almost over, so when did you buy it??? That could be the explanation for the error.

  • My Mac Mini was not sending a signal to the monitor. I powered down using the power button and now it will not start. When i power up I get a strange 2 tone sound, like a warning alarm. The fan starts, and the light comes on, but no screen

    My Mac Mini was not sending a signal to the monitor. I powered down using the power button and now it will not start. When i power up I get a strange 2 tone sound, like a warning alarm. The fan starts, and the light comes on, but no screen.
    I have tried with a wired USB keyboard and mouse using a single screen. Powered up with option pressed. No change.
    Reset SMC  no change

    Run the Apple hardware test to see what it tells you. Run the extended test when prompted, which can take awhile.

  • For some reason when I plug my phone up to charge it just keeps showing me the apple logo and then it goes away shows the battery sign is low and that its charging. So I'm wondering why it wont turn on would I have t get a new one, and would it be free

    For some reason when I plug my phone up to charge it just keeps showing me the apple logo and then it goes away shows the battery sign is low and that its charging. So I'm wondering why it wont turn on would I have t get a new one, and would it be free

    If you've tried the basic troubleshooting steps (restart, reset, restore from backup, restore as new), and you've tried charging from a wall socket and these all fail, then you have a hardware problem.
    If your unit is still in warranty, you will be eligible for a replacement with a refurbished unit free of charge.  If you are out of your warranty period, you will be eligible for an out of warranty exchange which will cost the equivalent of 200 US dollars.

Maybe you are looking for

  • MSI Live Update will no longer work after recent update

    Recently, MSI Live Update upgraded itself and now errors when a scan is attempted.  I can start the application, and the scan appears to occur but does not complete.  The error is pretty generic:  Microsoft Visual C++ Runtime Library Runtime Error! P

  • ACS 5.2 Authentication Issue with Local & Global ADs

    Hi I am facing authentication issue with ACS 5.2. Below is AAA flow (EAP-TLS), - Wireless Users >> Cisco WLC >> ADs <-- everything OK - Wireless Users >> Cisco WLC >> ACS 5.2 >> ADs <-- problem Last time I tested with ACS, it worked but didn't do mig

  • Sender file  FCC

    Hi all, iam doing file to idoc format I have file which is in idoc format  . file  3  segements  contol reacord ,header , item . EDI_DC40                           2   WMMBID02                                                    WMMBXY                

  • SCCM Design Looking for Opinions/Tips

    Hello out there I'm in the middle of designing our SCCM 2012 R2 layout and was wondering if I could get some Opinions/Tips on anything before we implement. Primary Site Site System Server 1 Roles: Asset Intell Endpoint Windows Intune Site Database (L

  • Preferences in Mavericks

    Found this article by Richard Taylor quite interesting and thought  others might as well.  Russ