Power Management only has the option of “Do Nothing” for critically low battery in 17.10

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
9
down vote

favorite
2












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":



do nothing power option



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









share|improve this question























  • Check is this you ar looking for askubuntu.com/questions/92794/…
    – Aravind
    Mar 19 at 15:59














up vote
9
down vote

favorite
2












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":



do nothing power option



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









share|improve this question























  • Check is this you ar looking for askubuntu.com/questions/92794/…
    – Aravind
    Mar 19 at 15:59












up vote
9
down vote

favorite
2









up vote
9
down vote

favorite
2






2





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":



do nothing power option



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









share|improve this question















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":



do nothing power option



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






17.10 power-management






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 21 at 8:32

























asked Mar 14 at 11:26









Questioner

1,4532480146




1,4532480146











  • Check is this you ar looking for askubuntu.com/questions/92794/…
    – Aravind
    Mar 19 at 15:59
















  • Check is this you ar looking for askubuntu.com/questions/92794/…
    – Aravind
    Mar 19 at 15:59















Check is this you ar looking for askubuntu.com/questions/92794/…
– Aravind
Mar 19 at 15:59




Check is this you ar looking for askubuntu.com/questions/92794/…
– Aravind
Mar 19 at 15:59










2 Answers
2






active

oldest

votes

















up vote
5
down vote



accepted
+500










Step 1: Check gsettings



There are two options you can check in the terminal:



$ gsettings get org.gnome.settings-daemon.plugins.power critical-battery-action
'suspend'
$ gsettings get org.gnome.settings-daemon.plugins.power percentage-low
'10'


Then to change them use:



$ gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action suspend
$ gsettings set org.gnome.settings-daemon.plugins.power percentage-low 10


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:



$ upower -d 
Device: /org/freedesktop/UPower/devices/line_power_ACAD
native-path: ACAD
power supply: yes
updated: Sun 18 Mar 2018 02:28:25 PM MDT (135878 seconds ago)
has history: no
has statistics: no
line-power
warning-level: none
online: yes
icon-name: 'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT1
native-path: BAT1
vendor: COMPAL
model: PABAS0241231
serial: 41167
power supply: yes
updated: Tue 20 Mar 2018 04:12:10 AM MDT (53 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: charging
warning-level: none
energy: 48.2544 Wh
energy-empty: 0 Wh
energy-full: 93.3552 Wh
energy-full-design: 96.48 Wh
energy-rate: 0.0044914 W
voltage: 14.76 V
percentage: 51%
capacity: 96.7612%
technology: lithium-ion
icon-name: 'battery-good-charging-symbolic'

Device: /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0008
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:101A.0008
vendor: Logitech, Inc.
model: Performance MX
serial: E6CE4571
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
mouse
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 55%
icon-name: 'battery-good-symbolic'

Device: /org/freedesktop/UPower/devices/keyboard_0003o046Do2010x0009
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:2010.0009
vendor: Logitech, Inc.
model: K800
serial: 6DB54BFE
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 90%
icon-name: 'battery-full-symbolic'

Device: /org/freedesktop/UPower/devices/ups_hiddev3
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4:1.0/usbmisc/hiddev3
vendor: CPS
model: CP550HGa
serial: BFBB104#BI1.g
power supply: yes
updated: Tue 20 Mar 2018 04:12:51 AM MDT (12 seconds ago)
has history: yes
has statistics: yes
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
power supply: yes
updated: Tue 20 Mar 2018 04:10:14 AM MDT (169 seconds ago)
has history: no
has statistics: no
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Daemon:
daemon-version: 0.99.4
on-battery: no
lid-is-closed: no
lid-is-present: yes
critical-action: HybridSleep


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 or upower. It only requires systemd, udev and cron 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 this udev 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 running udevadm 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 when BAT0/energy_now drops below the alarm value, and the udev rule will work as long as the percentage math works out. Some laptops have an option for this disabled in BIOS by default.



$ cat /etc/udev/rules.d/99-lowbat.rules

# Suspend the system when battery level drops to 5% or lower
SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", ATTRcapacity=="[0-5]", RUN+="/usr/bin/systemctl hibernate"


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 capacities 0 through 5 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:



#!/bin/sh
acpi -b | awk -F'[,:%]' 'print $2, $3' |
read -r status capacity

if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi



Testing events



One way to test udev rules is to have them create a file when they are run. For example:



$ cat /etc/udev/rules.d/98-discharging.rules

SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", RUN+="/usr/bin/touch /home/example/discharging"


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 advanced udev 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.






share|improve this answer






















  • Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
    – Questioner
    Mar 20 at 6:32










  • @Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
    – WinEunuuchs2Unix
    Mar 20 at 10:23










  • Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
    – Questioner
    Mar 21 at 8:33










  • @Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
    – WinEunuuchs2Unix
    Mar 21 at 10:08










  • @Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
    – WinEunuuchs2Unix
    Mar 21 at 10:27


















up vote
3
down vote













Heres a friendly script I put together!



I've created a makeshift solution that checks if your laptop is on AC or Battery (DC) power...



Therefore, if it is on AC power it will exit and if not it will continue checking the remaining battery power every 15 seconds until it hits the defined variable low or rather percent...



Oh and if you want to continue working in the same terminal as you ran this script as simply run the script like so:



bash power-notify.sh &


Without further ado, here is the script:



#!/bin/bash
#Get battery percent
bat_percent=$(acpi | awk -F ", " 'print $2' | tr -d %)


#When to start showing warnings... Example: 10% --> low=10
low=10
#Alert message to show when low percent is reached
alert="Low battery, $bat_percent% left..."

#Check if notify-send is installed
notfiy_send_test=$(which notify-send)
if [ $? != 0 ]
then
echo "Please install notify-send..."
exit 1
fi

acpi_test=$(which acpi)
if [ $? != 0 ]
then
echo "Please install acpi..."
exit 1
fi


#Test if cord is plugged in
plugged=$(acpi -a | awk -F ": " 'print $2')

if [ $plugged == 'on-line' ]
then
echo "Your computer is connected to a power source..."
echo "Exiting..."
exit 0
fi

while :
do

if [ $bat_percent -lt $low ]
then
notify-send "$alert"
sleep 15
else
#Check every fifteen seconds to use less resources...
sleep 15
fi

done


This script can also be found on GitHub, here...






share|improve this answer




















  • A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
    – WinEunuuchs2Unix
    Mar 21 at 23:05










  • @WinEunuuchs2Unix just a simple script
    – NerdOfCode
    Mar 21 at 23:08










  • I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
    – WinEunuuchs2Unix
    Mar 22 at 0:05











  • My script definitely.
    – NerdOfCode
    Mar 22 at 1:12










  • No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
    – WinEunuuchs2Unix
    Mar 22 at 1:14










Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "89"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1014854%2fpower-management-only-has-the-option-of-do-nothing-for-critically-low-battery%23new-answer', 'question_page');

);

Post as a guest






























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
5
down vote



accepted
+500










Step 1: Check gsettings



There are two options you can check in the terminal:



$ gsettings get org.gnome.settings-daemon.plugins.power critical-battery-action
'suspend'
$ gsettings get org.gnome.settings-daemon.plugins.power percentage-low
'10'


Then to change them use:



$ gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action suspend
$ gsettings set org.gnome.settings-daemon.plugins.power percentage-low 10


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:



$ upower -d 
Device: /org/freedesktop/UPower/devices/line_power_ACAD
native-path: ACAD
power supply: yes
updated: Sun 18 Mar 2018 02:28:25 PM MDT (135878 seconds ago)
has history: no
has statistics: no
line-power
warning-level: none
online: yes
icon-name: 'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT1
native-path: BAT1
vendor: COMPAL
model: PABAS0241231
serial: 41167
power supply: yes
updated: Tue 20 Mar 2018 04:12:10 AM MDT (53 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: charging
warning-level: none
energy: 48.2544 Wh
energy-empty: 0 Wh
energy-full: 93.3552 Wh
energy-full-design: 96.48 Wh
energy-rate: 0.0044914 W
voltage: 14.76 V
percentage: 51%
capacity: 96.7612%
technology: lithium-ion
icon-name: 'battery-good-charging-symbolic'

Device: /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0008
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:101A.0008
vendor: Logitech, Inc.
model: Performance MX
serial: E6CE4571
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
mouse
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 55%
icon-name: 'battery-good-symbolic'

Device: /org/freedesktop/UPower/devices/keyboard_0003o046Do2010x0009
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:2010.0009
vendor: Logitech, Inc.
model: K800
serial: 6DB54BFE
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 90%
icon-name: 'battery-full-symbolic'

Device: /org/freedesktop/UPower/devices/ups_hiddev3
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4:1.0/usbmisc/hiddev3
vendor: CPS
model: CP550HGa
serial: BFBB104#BI1.g
power supply: yes
updated: Tue 20 Mar 2018 04:12:51 AM MDT (12 seconds ago)
has history: yes
has statistics: yes
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
power supply: yes
updated: Tue 20 Mar 2018 04:10:14 AM MDT (169 seconds ago)
has history: no
has statistics: no
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Daemon:
daemon-version: 0.99.4
on-battery: no
lid-is-closed: no
lid-is-present: yes
critical-action: HybridSleep


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 or upower. It only requires systemd, udev and cron 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 this udev 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 running udevadm 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 when BAT0/energy_now drops below the alarm value, and the udev rule will work as long as the percentage math works out. Some laptops have an option for this disabled in BIOS by default.



$ cat /etc/udev/rules.d/99-lowbat.rules

# Suspend the system when battery level drops to 5% or lower
SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", ATTRcapacity=="[0-5]", RUN+="/usr/bin/systemctl hibernate"


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 capacities 0 through 5 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:



#!/bin/sh
acpi -b | awk -F'[,:%]' 'print $2, $3' |
read -r status capacity

if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi



Testing events



One way to test udev rules is to have them create a file when they are run. For example:



$ cat /etc/udev/rules.d/98-discharging.rules

SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", RUN+="/usr/bin/touch /home/example/discharging"


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 advanced udev 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.






share|improve this answer






















  • Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
    – Questioner
    Mar 20 at 6:32










  • @Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
    – WinEunuuchs2Unix
    Mar 20 at 10:23










  • Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
    – Questioner
    Mar 21 at 8:33










  • @Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
    – WinEunuuchs2Unix
    Mar 21 at 10:08










  • @Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
    – WinEunuuchs2Unix
    Mar 21 at 10:27















up vote
5
down vote



accepted
+500










Step 1: Check gsettings



There are two options you can check in the terminal:



$ gsettings get org.gnome.settings-daemon.plugins.power critical-battery-action
'suspend'
$ gsettings get org.gnome.settings-daemon.plugins.power percentage-low
'10'


Then to change them use:



$ gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action suspend
$ gsettings set org.gnome.settings-daemon.plugins.power percentage-low 10


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:



$ upower -d 
Device: /org/freedesktop/UPower/devices/line_power_ACAD
native-path: ACAD
power supply: yes
updated: Sun 18 Mar 2018 02:28:25 PM MDT (135878 seconds ago)
has history: no
has statistics: no
line-power
warning-level: none
online: yes
icon-name: 'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT1
native-path: BAT1
vendor: COMPAL
model: PABAS0241231
serial: 41167
power supply: yes
updated: Tue 20 Mar 2018 04:12:10 AM MDT (53 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: charging
warning-level: none
energy: 48.2544 Wh
energy-empty: 0 Wh
energy-full: 93.3552 Wh
energy-full-design: 96.48 Wh
energy-rate: 0.0044914 W
voltage: 14.76 V
percentage: 51%
capacity: 96.7612%
technology: lithium-ion
icon-name: 'battery-good-charging-symbolic'

Device: /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0008
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:101A.0008
vendor: Logitech, Inc.
model: Performance MX
serial: E6CE4571
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
mouse
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 55%
icon-name: 'battery-good-symbolic'

Device: /org/freedesktop/UPower/devices/keyboard_0003o046Do2010x0009
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:2010.0009
vendor: Logitech, Inc.
model: K800
serial: 6DB54BFE
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 90%
icon-name: 'battery-full-symbolic'

Device: /org/freedesktop/UPower/devices/ups_hiddev3
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4:1.0/usbmisc/hiddev3
vendor: CPS
model: CP550HGa
serial: BFBB104#BI1.g
power supply: yes
updated: Tue 20 Mar 2018 04:12:51 AM MDT (12 seconds ago)
has history: yes
has statistics: yes
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
power supply: yes
updated: Tue 20 Mar 2018 04:10:14 AM MDT (169 seconds ago)
has history: no
has statistics: no
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Daemon:
daemon-version: 0.99.4
on-battery: no
lid-is-closed: no
lid-is-present: yes
critical-action: HybridSleep


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 or upower. It only requires systemd, udev and cron 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 this udev 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 running udevadm 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 when BAT0/energy_now drops below the alarm value, and the udev rule will work as long as the percentage math works out. Some laptops have an option for this disabled in BIOS by default.



$ cat /etc/udev/rules.d/99-lowbat.rules

# Suspend the system when battery level drops to 5% or lower
SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", ATTRcapacity=="[0-5]", RUN+="/usr/bin/systemctl hibernate"


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 capacities 0 through 5 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:



#!/bin/sh
acpi -b | awk -F'[,:%]' 'print $2, $3' |
read -r status capacity

if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi



Testing events



One way to test udev rules is to have them create a file when they are run. For example:



$ cat /etc/udev/rules.d/98-discharging.rules

SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", RUN+="/usr/bin/touch /home/example/discharging"


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 advanced udev 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.






share|improve this answer






















  • Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
    – Questioner
    Mar 20 at 6:32










  • @Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
    – WinEunuuchs2Unix
    Mar 20 at 10:23










  • Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
    – Questioner
    Mar 21 at 8:33










  • @Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
    – WinEunuuchs2Unix
    Mar 21 at 10:08










  • @Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
    – WinEunuuchs2Unix
    Mar 21 at 10:27













up vote
5
down vote



accepted
+500







up vote
5
down vote



accepted
+500




+500




Step 1: Check gsettings



There are two options you can check in the terminal:



$ gsettings get org.gnome.settings-daemon.plugins.power critical-battery-action
'suspend'
$ gsettings get org.gnome.settings-daemon.plugins.power percentage-low
'10'


Then to change them use:



$ gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action suspend
$ gsettings set org.gnome.settings-daemon.plugins.power percentage-low 10


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:



$ upower -d 
Device: /org/freedesktop/UPower/devices/line_power_ACAD
native-path: ACAD
power supply: yes
updated: Sun 18 Mar 2018 02:28:25 PM MDT (135878 seconds ago)
has history: no
has statistics: no
line-power
warning-level: none
online: yes
icon-name: 'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT1
native-path: BAT1
vendor: COMPAL
model: PABAS0241231
serial: 41167
power supply: yes
updated: Tue 20 Mar 2018 04:12:10 AM MDT (53 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: charging
warning-level: none
energy: 48.2544 Wh
energy-empty: 0 Wh
energy-full: 93.3552 Wh
energy-full-design: 96.48 Wh
energy-rate: 0.0044914 W
voltage: 14.76 V
percentage: 51%
capacity: 96.7612%
technology: lithium-ion
icon-name: 'battery-good-charging-symbolic'

Device: /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0008
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:101A.0008
vendor: Logitech, Inc.
model: Performance MX
serial: E6CE4571
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
mouse
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 55%
icon-name: 'battery-good-symbolic'

Device: /org/freedesktop/UPower/devices/keyboard_0003o046Do2010x0009
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:2010.0009
vendor: Logitech, Inc.
model: K800
serial: 6DB54BFE
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 90%
icon-name: 'battery-full-symbolic'

Device: /org/freedesktop/UPower/devices/ups_hiddev3
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4:1.0/usbmisc/hiddev3
vendor: CPS
model: CP550HGa
serial: BFBB104#BI1.g
power supply: yes
updated: Tue 20 Mar 2018 04:12:51 AM MDT (12 seconds ago)
has history: yes
has statistics: yes
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
power supply: yes
updated: Tue 20 Mar 2018 04:10:14 AM MDT (169 seconds ago)
has history: no
has statistics: no
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Daemon:
daemon-version: 0.99.4
on-battery: no
lid-is-closed: no
lid-is-present: yes
critical-action: HybridSleep


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 or upower. It only requires systemd, udev and cron 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 this udev 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 running udevadm 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 when BAT0/energy_now drops below the alarm value, and the udev rule will work as long as the percentage math works out. Some laptops have an option for this disabled in BIOS by default.



$ cat /etc/udev/rules.d/99-lowbat.rules

# Suspend the system when battery level drops to 5% or lower
SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", ATTRcapacity=="[0-5]", RUN+="/usr/bin/systemctl hibernate"


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 capacities 0 through 5 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:



#!/bin/sh
acpi -b | awk -F'[,:%]' 'print $2, $3' |
read -r status capacity

if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi



Testing events



One way to test udev rules is to have them create a file when they are run. For example:



$ cat /etc/udev/rules.d/98-discharging.rules

SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", RUN+="/usr/bin/touch /home/example/discharging"


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 advanced udev 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.






share|improve this answer














Step 1: Check gsettings



There are two options you can check in the terminal:



$ gsettings get org.gnome.settings-daemon.plugins.power critical-battery-action
'suspend'
$ gsettings get org.gnome.settings-daemon.plugins.power percentage-low
'10'


Then to change them use:



$ gsettings set org.gnome.settings-daemon.plugins.power critical-battery-action suspend
$ gsettings set org.gnome.settings-daemon.plugins.power percentage-low 10


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:



$ upower -d 
Device: /org/freedesktop/UPower/devices/line_power_ACAD
native-path: ACAD
power supply: yes
updated: Sun 18 Mar 2018 02:28:25 PM MDT (135878 seconds ago)
has history: no
has statistics: no
line-power
warning-level: none
online: yes
icon-name: 'ac-adapter-symbolic'

Device: /org/freedesktop/UPower/devices/battery_BAT1
native-path: BAT1
vendor: COMPAL
model: PABAS0241231
serial: 41167
power supply: yes
updated: Tue 20 Mar 2018 04:12:10 AM MDT (53 seconds ago)
has history: yes
has statistics: yes
battery
present: yes
rechargeable: yes
state: charging
warning-level: none
energy: 48.2544 Wh
energy-empty: 0 Wh
energy-full: 93.3552 Wh
energy-full-design: 96.48 Wh
energy-rate: 0.0044914 W
voltage: 14.76 V
percentage: 51%
capacity: 96.7612%
technology: lithium-ion
icon-name: 'battery-good-charging-symbolic'

Device: /org/freedesktop/UPower/devices/mouse_0003o046Do101Ax0008
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:101A.0008
vendor: Logitech, Inc.
model: Performance MX
serial: E6CE4571
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
mouse
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 55%
icon-name: 'battery-good-symbolic'

Device: /org/freedesktop/UPower/devices/keyboard_0003o046Do2010x0009
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.2/0003:046D:C52B.0003/0003:046D:2010.0009
vendor: Logitech, Inc.
model: K800
serial: 6DB54BFE
power supply: no
updated: Tue 20 Mar 2018 04:12:09 AM MDT (54 seconds ago)
has history: yes
has statistics: no
keyboard
present: yes
rechargeable: yes
state: discharging
warning-level: none
percentage: 90%
icon-name: 'battery-full-symbolic'

Device: /org/freedesktop/UPower/devices/ups_hiddev3
native-path: /sys/devices/pci0000:00/0000:00:14.0/usb1/1-1/1-1.4/1-1.4.4/1-1.4.4:1.0/usbmisc/hiddev3
vendor: CPS
model: CP550HGa
serial: BFBB104#BI1.g
power supply: yes
updated: Tue 20 Mar 2018 04:12:51 AM MDT (12 seconds ago)
has history: yes
has statistics: yes
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Device: /org/freedesktop/UPower/devices/DisplayDevice
power supply: yes
updated: Tue 20 Mar 2018 04:10:14 AM MDT (169 seconds ago)
has history: no
has statistics: no
ups
present: yes
state: fully-charged
warning-level: none
time to empty: 37.5 minutes
percentage: 100%
icon-name: 'battery-full-charged-symbolic'

Daemon:
daemon-version: 0.99.4
on-battery: no
lid-is-closed: no
lid-is-present: yes
critical-action: HybridSleep


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 or upower. It only requires systemd, udev and cron 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 this udev 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 running udevadm 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 when BAT0/energy_now drops below the alarm value, and the udev rule will work as long as the percentage math works out. Some laptops have an option for this disabled in BIOS by default.



$ cat /etc/udev/rules.d/99-lowbat.rules

# Suspend the system when battery level drops to 5% or lower
SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", ATTRcapacity=="[0-5]", RUN+="/usr/bin/systemctl hibernate"


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 capacities 0 through 5 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:



#!/bin/sh
acpi -b | awk -F'[,:%]' 'print $2, $3' |
read -r status capacity

if [ "$status" = Discharging -a "$capacity" -lt 5 ]; then
logger "Critical battery threshold"
systemctl hibernate
fi



Testing events



One way to test udev rules is to have them create a file when they are run. For example:



$ cat /etc/udev/rules.d/98-discharging.rules

SUBSYSTEM=="power_supply", ATTRstatus=="Discharging", RUN+="/usr/bin/touch /home/example/discharging"


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 advanced udev 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.







share|improve this answer














share|improve this answer



share|improve this answer








edited Mar 22 at 0:03

























answered Mar 19 at 11:08









WinEunuuchs2Unix

36k759134




36k759134











  • Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
    – Questioner
    Mar 20 at 6:32










  • @Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
    – WinEunuuchs2Unix
    Mar 20 at 10:23










  • Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
    – Questioner
    Mar 21 at 8:33










  • @Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
    – WinEunuuchs2Unix
    Mar 21 at 10:08










  • @Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
    – WinEunuuchs2Unix
    Mar 21 at 10:27

















  • Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
    – Questioner
    Mar 20 at 6:32










  • @Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
    – WinEunuuchs2Unix
    Mar 20 at 10:23










  • Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
    – Questioner
    Mar 21 at 8:33










  • @Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
    – WinEunuuchs2Unix
    Mar 21 at 10:08










  • @Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
    – WinEunuuchs2Unix
    Mar 21 at 10:27
















Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
– Questioner
Mar 20 at 6:32




Thank you for this response. Unfortunately, it seems that my gsettings parameters were already set to suspend and 10, which would indicate that my system is not respecting those options.
– Questioner
Mar 20 at 6:32












@Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
– WinEunuuchs2Unix
Mar 20 at 10:23




@Questioner gsettings was the first (easy) step to check. I've added upower the next step to take.
– WinEunuuchs2Unix
Mar 20 at 10:23












Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
– Questioner
Mar 21 at 8:33




Thank you for the update. I will test the laptop as you suggest. In the meantime, I've added the contents of my /etc/UPower/UPower.conf file to my question.
– Questioner
Mar 21 at 8:33












@Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
– WinEunuuchs2Unix
Mar 21 at 10:08




@Questioner I ran clipboard-diff between your UPower.conf and the version installed on my system. They are identical.
– WinEunuuchs2Unix
Mar 21 at 10:08












@Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
– WinEunuuchs2Unix
Mar 21 at 10:27





@Questioner Couple questions: 1) Does gsettings get org.gnome.settings-daemon.plugins.power active return true? 2) Do you have a swap partition > amount of RAM?
– WinEunuuchs2Unix
Mar 21 at 10:27













up vote
3
down vote













Heres a friendly script I put together!



I've created a makeshift solution that checks if your laptop is on AC or Battery (DC) power...



Therefore, if it is on AC power it will exit and if not it will continue checking the remaining battery power every 15 seconds until it hits the defined variable low or rather percent...



Oh and if you want to continue working in the same terminal as you ran this script as simply run the script like so:



bash power-notify.sh &


Without further ado, here is the script:



#!/bin/bash
#Get battery percent
bat_percent=$(acpi | awk -F ", " 'print $2' | tr -d %)


#When to start showing warnings... Example: 10% --> low=10
low=10
#Alert message to show when low percent is reached
alert="Low battery, $bat_percent% left..."

#Check if notify-send is installed
notfiy_send_test=$(which notify-send)
if [ $? != 0 ]
then
echo "Please install notify-send..."
exit 1
fi

acpi_test=$(which acpi)
if [ $? != 0 ]
then
echo "Please install acpi..."
exit 1
fi


#Test if cord is plugged in
plugged=$(acpi -a | awk -F ": " 'print $2')

if [ $plugged == 'on-line' ]
then
echo "Your computer is connected to a power source..."
echo "Exiting..."
exit 0
fi

while :
do

if [ $bat_percent -lt $low ]
then
notify-send "$alert"
sleep 15
else
#Check every fifteen seconds to use less resources...
sleep 15
fi

done


This script can also be found on GitHub, here...






share|improve this answer




















  • A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
    – WinEunuuchs2Unix
    Mar 21 at 23:05










  • @WinEunuuchs2Unix just a simple script
    – NerdOfCode
    Mar 21 at 23:08










  • I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
    – WinEunuuchs2Unix
    Mar 22 at 0:05











  • My script definitely.
    – NerdOfCode
    Mar 22 at 1:12










  • No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
    – WinEunuuchs2Unix
    Mar 22 at 1:14














up vote
3
down vote













Heres a friendly script I put together!



I've created a makeshift solution that checks if your laptop is on AC or Battery (DC) power...



Therefore, if it is on AC power it will exit and if not it will continue checking the remaining battery power every 15 seconds until it hits the defined variable low or rather percent...



Oh and if you want to continue working in the same terminal as you ran this script as simply run the script like so:



bash power-notify.sh &


Without further ado, here is the script:



#!/bin/bash
#Get battery percent
bat_percent=$(acpi | awk -F ", " 'print $2' | tr -d %)


#When to start showing warnings... Example: 10% --> low=10
low=10
#Alert message to show when low percent is reached
alert="Low battery, $bat_percent% left..."

#Check if notify-send is installed
notfiy_send_test=$(which notify-send)
if [ $? != 0 ]
then
echo "Please install notify-send..."
exit 1
fi

acpi_test=$(which acpi)
if [ $? != 0 ]
then
echo "Please install acpi..."
exit 1
fi


#Test if cord is plugged in
plugged=$(acpi -a | awk -F ": " 'print $2')

if [ $plugged == 'on-line' ]
then
echo "Your computer is connected to a power source..."
echo "Exiting..."
exit 0
fi

while :
do

if [ $bat_percent -lt $low ]
then
notify-send "$alert"
sleep 15
else
#Check every fifteen seconds to use less resources...
sleep 15
fi

done


This script can also be found on GitHub, here...






share|improve this answer




















  • A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
    – WinEunuuchs2Unix
    Mar 21 at 23:05










  • @WinEunuuchs2Unix just a simple script
    – NerdOfCode
    Mar 21 at 23:08










  • I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
    – WinEunuuchs2Unix
    Mar 22 at 0:05











  • My script definitely.
    – NerdOfCode
    Mar 22 at 1:12










  • No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
    – WinEunuuchs2Unix
    Mar 22 at 1:14












up vote
3
down vote










up vote
3
down vote









Heres a friendly script I put together!



I've created a makeshift solution that checks if your laptop is on AC or Battery (DC) power...



Therefore, if it is on AC power it will exit and if not it will continue checking the remaining battery power every 15 seconds until it hits the defined variable low or rather percent...



Oh and if you want to continue working in the same terminal as you ran this script as simply run the script like so:



bash power-notify.sh &


Without further ado, here is the script:



#!/bin/bash
#Get battery percent
bat_percent=$(acpi | awk -F ", " 'print $2' | tr -d %)


#When to start showing warnings... Example: 10% --> low=10
low=10
#Alert message to show when low percent is reached
alert="Low battery, $bat_percent% left..."

#Check if notify-send is installed
notfiy_send_test=$(which notify-send)
if [ $? != 0 ]
then
echo "Please install notify-send..."
exit 1
fi

acpi_test=$(which acpi)
if [ $? != 0 ]
then
echo "Please install acpi..."
exit 1
fi


#Test if cord is plugged in
plugged=$(acpi -a | awk -F ": " 'print $2')

if [ $plugged == 'on-line' ]
then
echo "Your computer is connected to a power source..."
echo "Exiting..."
exit 0
fi

while :
do

if [ $bat_percent -lt $low ]
then
notify-send "$alert"
sleep 15
else
#Check every fifteen seconds to use less resources...
sleep 15
fi

done


This script can also be found on GitHub, here...






share|improve this answer












Heres a friendly script I put together!



I've created a makeshift solution that checks if your laptop is on AC or Battery (DC) power...



Therefore, if it is on AC power it will exit and if not it will continue checking the remaining battery power every 15 seconds until it hits the defined variable low or rather percent...



Oh and if you want to continue working in the same terminal as you ran this script as simply run the script like so:



bash power-notify.sh &


Without further ado, here is the script:



#!/bin/bash
#Get battery percent
bat_percent=$(acpi | awk -F ", " 'print $2' | tr -d %)


#When to start showing warnings... Example: 10% --> low=10
low=10
#Alert message to show when low percent is reached
alert="Low battery, $bat_percent% left..."

#Check if notify-send is installed
notfiy_send_test=$(which notify-send)
if [ $? != 0 ]
then
echo "Please install notify-send..."
exit 1
fi

acpi_test=$(which acpi)
if [ $? != 0 ]
then
echo "Please install acpi..."
exit 1
fi


#Test if cord is plugged in
plugged=$(acpi -a | awk -F ": " 'print $2')

if [ $plugged == 'on-line' ]
then
echo "Your computer is connected to a power source..."
echo "Exiting..."
exit 0
fi

while :
do

if [ $bat_percent -lt $low ]
then
notify-send "$alert"
sleep 15
else
#Check every fifteen seconds to use less resources...
sleep 15
fi

done


This script can also be found on GitHub, here...







share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 21 at 20:46









NerdOfCode

1,032223




1,032223











  • A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
    – WinEunuuchs2Unix
    Mar 21 at 23:05










  • @WinEunuuchs2Unix just a simple script
    – NerdOfCode
    Mar 21 at 23:08










  • I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
    – WinEunuuchs2Unix
    Mar 22 at 0:05











  • My script definitely.
    – NerdOfCode
    Mar 22 at 1:12










  • No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
    – WinEunuuchs2Unix
    Mar 22 at 1:14
















  • A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
    – WinEunuuchs2Unix
    Mar 21 at 23:05










  • @WinEunuuchs2Unix just a simple script
    – NerdOfCode
    Mar 21 at 23:08










  • I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
    – WinEunuuchs2Unix
    Mar 22 at 0:05











  • My script definitely.
    – NerdOfCode
    Mar 22 at 1:12










  • No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
    – WinEunuuchs2Unix
    Mar 22 at 1:14















A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
– WinEunuuchs2Unix
Mar 21 at 23:05




A working system is supposed to give warnings already at given percentages and then hybrid-sleep at 2%. I think that's what the OP is looking for. Your script could be improved by calling hibernate at 2%. Also a warning bubble every 15 seconds is extreme IMO. A message bubble t 9%, 8%, 7%... 3% would be more practical I think. Also a system alert sound would help people not looking at their laptop at the time. This script has some of the components I recommended: askubuntu.com/questions/837078/…
– WinEunuuchs2Unix
Mar 21 at 23:05












@WinEunuuchs2Unix just a simple script
– NerdOfCode
Mar 21 at 23:08




@WinEunuuchs2Unix just a simple script
– NerdOfCode
Mar 21 at 23:08












I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
– WinEunuuchs2Unix
Mar 22 at 0:05





I guess both your script and my script I linked in the last comment can be considered simple by professionals. I'm not sure which script you are calling "simple" though?
– WinEunuuchs2Unix
Mar 22 at 0:05













My script definitely.
– NerdOfCode
Mar 22 at 1:12




My script definitely.
– NerdOfCode
Mar 22 at 1:12












No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
– WinEunuuchs2Unix
Mar 22 at 1:14




No it's a good script and does what you want it to do. All great scripts start out as good scripts and you can improve it over days, weeks or decades. Linux has been around for a long time and will be around for a lot longer.
– WinEunuuchs2Unix
Mar 22 at 1:14

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1014854%2fpower-management-only-has-the-option-of-do-nothing-for-critically-low-battery%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

pylint3 and pip3 broken

Missing snmpget and snmpwalk

How to enroll fingerprints to Ubuntu 17.10 with VFS491