I'm using Ubuntu 17.10 with Gnome on an Asus laptop.
In the Power Settings interface, under the Power tab, there is an option at the bottom to set what to do in case the battery gets critically low.
However, when I click on the drop down to set that option, it only offers one option, which is "do nothing":
Currently, my laptop will run down to 0 battery power, or close to it, and then shut off with no warnings, no possibility of closing programs and shutting down gracefully.
I would like to have a warning when the battery is at 10% and hopefully some time to manually save and shut down programs before turning the computer off. How do I achieve this?
Edit: Here is the contents of my /etc/UPower/UPower.conf
file:
# Only the system vendor should modify this file, ordinary users
# should not have to change anything.
[UPower]
# Enable the Watts Up Pro device.
#
# The Watts Up Pro contains a generic FTDI USB device without a specific
# vendor and product ID. When we probe for WUP devices, we can cause
# the user to get a perplexing "Device or resource busy" error when
# attempting to use their non-WUP device.
#
# The generic FTDI device is known to also be used on:
#
# - Sparkfun FT232 breakout board
# - Parallax Propeller
#
# default=false
EnableWattsUpPro=false
# Don't poll the kernel for battery level changes.
#
# Some hardware will send us battery level changes through
# events, rather than us having to poll for it. This option
# allows disabling polling for hardware that sends out events.
#
# default=false
NoPollBatteries=false
# Do we ignore the lid state
#
# Some laptops are broken. The lid state is either inverted, or stuck
# on or off. We can't do much to fix these problems, but this is a way
# for users to make the laptop panel vanish, a state that might be used
# by a couple of user-space daemons. On Linux systems, see also
# logind.conf(5).
#
# default=false
IgnoreLid=false
# Policy for warnings and action based on battery levels
#
# Whether battery percentage based policy should be used. The default
# is to use the time left, change to true to use the percentage, which
# should work around broken firmwares. It is also more reliable than
# the time left (frantically saving all your files is going to use more
# battery than letting it rest for example).
# default=true
UsePercentageForPolicy=true
# When UsePercentageForPolicy is true, the levels at which UPower will
# consider the battery low, critical, or take action for the critical
# battery level.
#
# This will also be used for batteries which don't have time information
# such as that of peripherals.
#
# If any value is invalid, or not in descending order, the defaults
# will be used.
#
# Defaults:
# PercentageLow=10
# PercentageCritical=3
# PercentageAction=2
PercentageLow=10
PercentageCritical=3
PercentageAction=2
# When UsePercentageForPolicy is false, the time remaining at which UPower
# will consider the battery low, critical, or take action for the critical
# battery level.
#
# If any value is invalid, or not in descending order, the defaults
# will be used.
#
# Defaults:
# TimeLow=1200
# TimeCritical=300
# TimeAction=120
TimeLow=1200
TimeCritical=300
TimeAction=120
# The action to take when "TimeAction" or "PercentageAction" above has been
# reached for the batteries (UPS or laptop batteries) supplying the computer
#
# Possible values are:
# PowerOff
# Hibernate
# HybridSleep
#
# If HybridSleep isn't available, Hibernate will be used
# If Hibernate isn't available, PowerOff will be used
CriticalPowerAction=HybridSleep
Best Answer
Step 1: Check
gsettings
There are two options you can check in the terminal:
Then to change them use:
Note on my system they are just fine, so I changed them back to what they were in the first place for sake of example.
Step 2: Check
upower
Gnome power management utilizes
upower
to do the heavy lifting. To ensure it is running and collecting battery statistics as it should, use:First run this command when the laptop is plugged in. Then unplug the laptop and run the command after some time and ensure battery remaining time has reduced appropriately.
Last Step - Low level hibernation
This is the last step which would be taken after exhausting all other steps. This step doesn't require Ubuntu or Unity or Gnome or
gsettings
orupower
. It only requiressystemd
,udev
andcron
which are built into almost all Linux Distros with or without GUI (Desktop).From ArchLinux:
Hibernate on low battery level
If your battery sends events to
udev
whenever it (dis)charges by 1%, you can use thisudev
rule to automatically hibernate the system when battery level is critical, and thus prevent all unsaved work from being lost. Note: Not all batteries report discharge events. Test by runningudevadm monitor --property
while on battery and see if any events are reported. You should wait at least 1% drop. If no events are reported and/sys/class/power_supply/BAT0/alarm
is non-zero then the battery will likely trigger an event whenBAT0/energy_now
drops below the alarm value, and theudev
rule will work as long as the percentage math works out. Some laptops have an option for this disabled in BIOS by default.This rule will be repeated whenever the condition is set. As such, when resuming from hibernate when the battery is critical, the computer will hibernate directly. Some laptops do not boot beyond a certain battery level, so the rule could be adjusted accordingly.
Batteries can jump to a lower value instead of discharging continuously, therefore a
udev
string matching pattern for all capacities0
through5
is used.Other rules can be added to perform different actions depending on power supply status and/or capacity.
If your system has no or missing ACPI events, use
cron
with the following script:Testing events
One way to test
udev
rules is to have them create a file when they are run. For example:This creates a file at
/home/example/discharging
when the laptop charger is unplugged. You can test whether the rule worked by unplugging your laptop and looking for this file. For more advancedudev
rule testing, see Udev#Testing rules before loading.Summary
There are more steps to post between Step #2 and "Last Step" but these will be posted as OP reveals more details after testing. In the mean time the "Last Step" should reduce more half-way answers like simply reporting percentage remaining.