Sample Header Ad - 728x90

ACPI trigger wakeup on low battery while suspended, in order to hibernate

1 vote
2 answers
928 views
I want to hibernate on low battery:
SUBSYSTEM=="power_supply", \
    ATTR{status}=="Discharging", \
    ATTR{capacity}=="[0-5]", \
    RUN+="/usr/bin/systemctl hibernate", \
This works well if the system is awake. If suspended however, it doesn't hibernate until I wake it, then instead of allowing me to unlock it immediately hibernates. How can I make this event either work while suspended, or trigger a wakeup (and then hibernate) itself, without me opening the lid? --- I have tried adding:
ATTR{power/wakeup}="enabled"
without success. Indeed there is no wakeup currently in /sys/class/power_supply/BAT1/power/ - actually though /sys/class/power_supply/BAT1/device/power/wakeup exists and is already enabled. I gather I can't make the udev rule run while suspended, I need to trigger it to wake on low battery separately (then the udev rule can run and hibernate). This seems already implemented in [drivers/acpi/battery.c](https://github.com/torvalds/linux/blob/22da5264abf497a10a4ed629f07f4ba28a7ed5eb/drivers/acpi/battery.c#L994-L1001) :
/*
	 * Wakeup the system if battery is critical low
	 * or lower than the alarm level
	 */
	if ((battery->state & ACPI_BATTERY_STATE_CRITICAL) ||
	    (test_bit(ACPI_BATTERY_ALARM_PRESENT, &battery->flags) &&
	     (battery->capacity_now alarm)))
		acpi_pm_wakeup_event(&battery->device->dev);
But that has not worked for me, I don't know if 'critical low' is another textual capacity level, I've only seen as low as 'Low', but it was at the time lower than the /sys/class/power_supply/BAT1/alarm. --- NB: I am aware of hybrid-sleep, but that is not what I want, firstly since I would like to conserve _some_ battery; but also so that I can use suspend-then-hibernate such that it hibernates on either low battery _or_ time delay.
Asked by OJFord (2073 rep)
Apr 24, 2022, 01:09 PM
Last activity: Mar 23, 2025, 05:02 PM