- Checking some Power Supply parameters
- Automatically set the threshold on boot
- Creating a udev rule
- Persist after hibernation
I have been using Kubuntu-22.04 on my ASUS Vivobook S15 510un for a while now. While the UX has been good enough till now, there is one problem that I have lazily accepted for a while, i.e, the battery charging threshold.
I generally set the battery charging threshold to 80% but this value is not preserved across reboot. Every time the machine is rebooted, the value is set back to 100% This was something I accepted as a quirk, and every time the system was rebooted, I would manually set the value back to 80% from the default 100%
As you should have guessed till now, this is an irritating issue, and sooner or later, I would have tried to resolve this in some way or another. And, that’s what I have done.
After searching for a couple of hours, modifying my query term to the issue at hand, I finally found the correct article on the Arch Wiki.
Checking some Power Supply parameters
Kernel 5.4 brought the ability to set the battery charge threshold for some Asus laptops, by modifying the
charge_control_end_threshold variable exposed under
By default this value is set to
100 and reset on every power cycle.
$ cat /sys/class/power_supply/BAT0/status Charging $ cat /sys/class/power_supply/BAT0/capacity 74 $ cat /sys/class/power_supply/BAT0/charge_control_end_threshold 80
Automatically set the threshold on boot
In order to automatically change the threshold on boot, let’s create a
sudo touch /etc/systemd/system/battery-charge-threshold.service
[Unit] Description=Set the battery charge threshold After=multi-user.target StartLimitBurst=0 [Service] Type=oneshot Restart=on-failure ExecStart=/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold' [Install] WantedBy=multi-user.target
Then, enable the service:
systemctl enable battery-charge-threshold.service
Creating a udev rule
charge_control_end_threshold class does not exist initially, lets create a udev rule for
asus-nb-wmi kernel module to set the battery’s charge threshold:
sudo vim /etc/udev/rules.d/asus-battery-charge-threshold.rules
ACTION=="add", KERNEL=="asus-nb-wmi", RUN+="/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT?/charge_control_end_threshold'"
Persist after hibernation
By default, the threshold settings persist across hibernation, so there is not need of any additional configuration here.
This was a nifty and fun way to spend a Sunday morning, and the result is very satisfactory.