I recently got a new laptop, (well — not new, but new to me), a HP ZBook 15 G5. After installing Arch Linux and the i3 wm I spend some time setting up power management, suspend on idle, and figuring out the state of the battery.
Table of contents
Power management
On my other laptops; I’ve used Powertop, without digging too deep into the details of what actually happens. But this time I set up TLD instead.
TLP is a feature-rich command line utility for Linux, saving laptop battery power without the need to delve deeper into technical details.
TLP’s default settings are already optimized for battery life and implement Powertop’s recommendations out of the box. So you may just install and forget it.
Nevertheless TLP is highly customizable to fulfil your specific requirements.
— From the project page
I just installed the tlp
package, enabled and started tlp.service
🪄
Suspend
I wanted to be able to manually suspend, and suspend automatically if the machine is left idle.
systemd
For automatic suspend I tried using systemd’s logind.conf
, there are some settings in /etc/systemd/logind.conf
that enables suspend on idle:
[Login]
IdleAction=suspend-then-hibernate
IdleActionSec=30min
However; this caused my laptop to suspend every 30 minutes — even when I was using it. It seems that i3 doesn’t support “idle hint control”, so systemd thinks the system is always idle.
So that clearly wasn’t going to work…
More information in the manual for Login manager configuration files:
man 5 logind.conf
xautolock
I’m already using xautolock to lock the screen when idle, reading the manual I noticed the -killtime
and -killer
arguments. In short; it allows a “kill” command to be executes n minutes after the locker.
I updated the xautolock definition in my i3/config
to include -killtime
, -killer
, and -detectsleep
:
exec --no-startup-id xautolock -time 10 -locker "i3lock -c 000000 -n" -killtime 10 -killer "systemctl suspend" -corners +00- -detectsleep
With this; my screen gets locked after 10 minutes, and the machine is suspended after another 10 minutes — works like a charm 🙂 And since it always gets locked before being suspended; a password is needed to resume.
Manual
I also want the option of suspending manually, this can of course easily be done in the terminal — but I wanted an option together with my other power options in i3. So I modified the exit mode configuration in i3/config
:
mode "Exit | Reboot | Sleep | Poweroff" {
bindsym e exit
bindsym r exec systemctl reboot
bindsym s exec systemctl suspend; mode "default"
bindsym p exec systemctl poweroff
# back to normal: Enter or Escape
bindsym Return mode "default"
bindsym Escape mode "default"
}
bindsym $mod+Shift+e mode "Exit | Reboot | Sleep | Poweroff"
mode "default"
after systemctl suspend
is to close the menu, otherwise it will still be open when resuming.
Suspending this way had one problem… The machine doesn’t lock — no password is required when resuming. This is because xautolock or i3lock isn’t part of the mix. But we can change that by making a systemd service:
sudo vim /etc/systemd/system/lock.service
[Unit]
Description=Lock
Before=sleep.target
[Service]
User=thomas
Environment=DISPLAY=:0
ExecStart=/usr/bin/i3lock -c 000000 --nofork
[Install]
WantedBy=suspend.target
WantedBy=sleep.target
sudo systemctl daemon-reload
sudo systemctl enable lock
Now; before the system gets suspended — i3lock is executed and locks the machine 👍
Hibernate?
I did experiment with systemd’s sleep.conf
, to hibernate after being suspended for a while. But this seemed to completely lock up the machine.
The parameters are found in /etc/systemd/sleep.conf
:
[Sleep]
#HibernateDelaySec=
#SuspendEstimationSec=60min
I’ve tried manually hibernating with systemctl hibernate
— the machine turns off, but a disk check is forced when starting back up. So I’m not sure how successful the hibernation was…
system.journal corrupted or uncleanly shut down, renaming and replacing.
user-1000.journal corrupted or uncleanly shut down, renaming and replacing.
Maybe you’ll have better luck 🙂
More information in the manual for Suspend and hibernation configuration file:
man 5 sleep.conf.d
Monitor off
The laptop monitor also turns off after 10 minutes, but this is controlled by X. I didn’t realize at first that the monitor powering off, and the screen getting locked happening at the same time was coincidental — both timers are set to 10 minutes:
xset q
DPMS (Display Power Management Signaling):
Standby: 600 Suspend: 600 Off: 600
DPMS is Enabled
Monitor is On
Battery state
Laptop batteries gets worn out, even faster if always fully charged. To see the status of the battery I used TLP:
sudo tlp-stat --battery
+++ Battery Status: BAT0
/sys/class/power_supply/BAT0/manufacturer = Hewlett-Packard
/sys/class/power_supply/BAT0/model_name = Primary
/sys/class/power_supply/BAT0/cycle_count = 21
/sys/class/power_supply/BAT0/charge_full_design = 5844 [mAh]
/sys/class/power_supply/BAT0/charge_full = 4315 [mAh]
/sys/class/power_supply/BAT0/charge_now = 1629 [mAh]
/sys/class/power_supply/BAT0/current_now = (not available)
/sys/class/power_supply/BAT0/status = Discharging
/sys/class/power_supply/BAT0/charge_control_start_threshold = (not available)
/sys/class/power_supply/BAT0/charge_control_end_threshold = (not available)
Charge = 37.8 [%]
Capacity = 73.8 [%]
It shows that the battery charge capacity has dropped from 5844 to 4315 mAh, leaving it with 73.8% capacity remaining. That’s ¼ of the original battery capacity gone.
Even though I’m mostly using this laptop at home — I am considering replacing the battery.
Update 2024-02-06: After reading this blog post — I checked to see if I could set the battery charge thresholds. But as you can see from the battery state above; /sys/class/power_supply/BAT0/charge_control_{start,end}_threshold
is not available on this laptop. Configuring a threshold with TLD did absolutely noting.
I found some settings a Battery Health Manager setting in BIOS — it was already set Maximize my battery health.
The Maximize My Battery Health setting discharges the battery to an 80% charge level and limits the maximum state-of-charge on the notebook battery to 80% of the maximum state-of-charge for the battery, which has been proven to optimize battery health and helps mitigate battery swelling due to high state-of-charge. The notebook battery remains at a maximum state-of-charge of 80% until you change the setting. — HP Battery Health Manager
The laptop doesn’t stop charging at 80%, at least according to the reported battery charge. But I haven’t played around with the setting to see if it changes anything. Maybe some other time 🙂
USB-C charging
I noticed there was a lightning icon next to the USB-C ports on the laptop, and some quick Googling confirmed that it can be charged with USB-C PD (power delivery). But there are a few limitations:
- ZBook 15 models come with 150 or 200 W chargers, USB-C PD is only 100 W.
- Under heavy use 100 W may not be enough, and the performance and battery charge rate may be impacted.
- ZBook 15 models needs at least a USB-C charger capable of delivering 90 W.
Source: HP ZBook Mobile Workstations - USB-C Power Consumer Support And Considerations
We already had a Ugreen Nexode 200W USB C GaN Charger — I tested and confirmed it was capable of charging the laptop 👍
I ordered another 200 W charger, and placed it on the desk where I typically use the laptop. It’s so nice to be able to charge our phones and laptop with the same charger.
I mostly use the machine for light tasks and have not noticed any performance or charging rate limitations.
Last commit 2024-11-24, with message: Add a few more tags, minor adjustments to title and summary of touchpad post.