You are not logged in.
Hello, I've set up hibernation successfully. Now I want to have systemd's suspend-then-hibernate power option to only hibernate the system after 5% of battery drop. I've read man systemd-sleep.conf, it explains that HibernateDelaySec= option is to determine how many minutes/hours you want the system to stay suspended, then hibernate. I was liking the way auto hibernation was working in Windows more, Windows would hibernate system only if 5% of battery drop happened. So if I left my laptop plugged into power and it has 100% battery, system would stay in suspend indefinetely as battery won't drop, until I plug out from power source, then if battery dropped to 95% Windows would sleep. That was a really good design but I couldn't find if this can be done with systemd's suspend-then-hibernate implementation, and looking for solutions if there's any.
Offline
It's not clear - do you want the system to hibernate when there is 5% of battery left, or when the battery percentage has dropped 5% from where it started? The former is supposed to be the default behavior of suspend-then-hibernate.
The latter is not exactly possible with systemctl. If you know how quickly your laptop drains during sleep (it's not hard to test; just leave it sleeping for a few hours and calculate the rate the charge has decreased), then you can set HibernateDelaySec. This won't be enough if you're suspending the laptop while plugged in and then unplugging it. It'd be better to just avoid doing that, but if you really want to force it to work, you should have the laptop wake up if it detects a switch from AC to battery power, and then you can sleep it again.
Offline
What DE are you using? In KDE (and I'd expect most other DEs) you can set it to:
default sleep mode while plugged in = suspend
default sleep mode while on battery = suspend-then-hibernate
then you can go into /etc/systemd/sleep.conf and configure HibernateDelaySec=6h or something.
Yes you'd need to figure out yourself how much time your device can sleep until you've discharged 5%, but I don't think it needs to be that exact, does it?
Edit: If your DE doesn't have those power settings but you can set a custom script for suspend, you can do something like this:
if ( upower -d | tr -d ' ' | grep 'on-battery:no' )
then systemctl sleep
else systemctl sleep-then-hibernate
fi
Last edited by fallingcats (2024-09-17 03:04:30)
Offline
That setting doesn't depend on the DE, it's in logind.conf.
Assuming a dynamic situation, the only possible solution is to frequently wake up, check the battery and trigger S3 or S4 accordingly.
You can rtcwake to sleep and wake after a set time. You'll still have to pre-estimate the discharge on S3
I'm frankly not sure whether windows does that dance at all - looking at some windows notebook, if goes to S3, ~2h later wakes up and then hibernates (but this is biased perception depending on how it's used and when I might see it doing this, so there may be different behaviors)
Offline