You are not logged in.


Hello.
On a laptop, the power supply manager enables to set-up an action when the energy in the battery reaches a certain level. For example, at 20% we can choose to: do nothing, ask for action, go to sleep, shutdown the laptop.
My question is: is there a way to set-up a two levels scenario (with battery only, no external power supply plugged-in) ? I would like something like:
– at 20% ask me what to do,
– at 15% shutdown the laptop.
Sometimes, I have to quit my office and I am not in front of my laptop any more. The idea is: if I am here I can choose, if not the laptop shuts down a little bit latter to avoid 0% battery level.
Thank you for your help !
Offline


xfce4-power-manager can only handle one event/action, not two like you're asking for. But you could use udev to trigger one of the events.
For example, set up xfce4-power-manager to shutdown at 15%. Then create the following udev rule:
# Rule for when switching to battery
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="20", RUN+="/usr/bin/systemd-run --machine=toz@.host --user notify-send 'Battery Level Notification' 'Capacity reached'"...make sure you change "toz" to your username.
Also make sure to reload udev rules:
sudo udevadm control --reloadDepending on the distro you are using, the udev rule could go into /etc/udev/rules.d.
At 20%, you should get a notification. At 15% the computer will shutdown.
Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline


Hello ToZ.
Thank you for your answer.
I am on xubuntu 24.04. I have created a 91-warning-low-battery.rules file inside my /usr/lib/udev/rules.d folder with the content you send me (I changed the user name).
Unfortunately it does not work, even after refreshing udev via sudo udevadm control --reload and sudo udevadm control --reload-rules.
If I run
/usr/bin/systemd-run --machine=mirassaqua@.host --user notify-send 'Warning: battery at low level' 'Battery at 40%'I get the notification for a very short delay (is there a way to change the display time for this specific notification by the way? I didn't found how to do it).
But the
SUBSYSTEM=="power_supply", ATTR{status}=="Discharging", ATTR{capacity}=="20", RUN+=…of the rules file does not seem to do the work. I don't know if the event is not taken into account or if its something else…
If you have an idea about it, I take!
Thank you.
Last edited by Mirassaqua (2025-10-28 10:04:43)
Offline


I get the notification for a very short delay (is there a way to change the display time for this specific notification by the way?
Try adding the -t property:
/usr/bin/systemd-run --machine=mirassaqua@.host --user notify-send -t 60000 'Warning: battery at low level' 'Battery at 40%'....and change the 60000 (milliseconds) to suit.
rules file does not seem to do the work.
What does the following return:
udevadm info -q property -a --path=/sys/class/power_supply/BAT0 | grep -E 'SUBSYSTEM=|{status|capacity}' | grep -v ATTRSAlso, run:
udevadm monitor...then plug/unplug the laptop and see what is displayed in the output regarding "power_supply".
Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline


Hello Toz.
The tip for the delay works fine and -t 0 enables to have a permanent notification which is very useful for my need. Thanks!
udevadm info -q property -a --path=/sys/class/power_supply/BAT0 | grep -E 'SUBSYSTEM=|{status|capacity}' | grep -v ATTRSreturns
SUBSYSTEM=="power_supply"
ATTR{capacity}=="35"
ATTR{status}=="Discharging"and
udevadm monitorreturns
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent
KERNEL[4872.126783] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV [4872.144188] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
KERNEL[4872.280420] change /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
UDEV [4872.280898] change /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
KERNEL[4876.901902] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
UDEV [4876.907404] change /devices/LNXSYSTM:00/LNXSYBUS:00/PNP0C0A:00/power_supply/BAT0 (power_supply)
KERNEL[4887.431644] change /devices/platform/ACPI0003:00/power_supply/AC (power_supply)
UDEV [4887.445599] change /devices/platform/ACPI0003:00/power_supply/AC (power_supply)when I plug and unplug the power supply.
It seems like it's the discharging event that is not taken into account…
Added later 09 min 13 s:
Another point: I have .rules files in the following locations:
– /etc/udev/rules.d – only few 70-snap.xxx.rules files
– /run/udev/rules.d – only one 90-netplan.rules file
– /snap/coreXX/YYYY/usr/lib/udev/rules.d – lots of .rules files
– /var/lib/flatpak/XXX/files/lib/udev/rules.d – a few .rules files
and
– /usr/lib/udev/rules.d
the one I used since there is numerous .rules files inside related to what seems to be many aspects of the system.
I have chosen the name 91-low-battery-warning.rules because 91- was not used…
Last edited by Mirassaqua (2025-10-28 12:26:43)
Offline


Have you let it fall down to 20% charge - when the notification should be issued? Also look into the journal for around the time the notification should be issued to see if there is an error.
Mark solved threads as [SOLVED] to make it easier for others to find solutions.
--- How To Ask For Help | FAQ | Developer Wiki | Community | Contribute ---
Offline


Hello ToZ.
To perform my tests, I adapt the level of critical battery inside the rules file. For example, if my battery is at 68%, I change
ATTR{capacity}=="66"and I execute
sudo udevadm control --reloadso that I have few time to wait.
I have looked at the journal. The "%" character issues an error at udevadm control --reload command. Something like
/etc/udev/rules.d/10-local.rules:2 Invalid value "/usr/bin/systemd-run --machine=mirassaqua@.host --user notify-send -t 0 'Warning: battery at low level' 'Battery at 66%'" for RUN (char 119: invalid substitution type), ignoring.I removed it and I have no issue any more at reload but still no notification… I tried to change the ordre of ATTR{capacity} and ATTR{status} with no more success.
I don't know if there is another way to test the rules… I continue to investigate on my side.
Thank you again.
Offline
[ Generated in 0.016 seconds, 10 queries executed - Memory usage: 595.11 KiB (Peak: 611.95 KiB) ]