Newer ASUS laptops support limiting battery power, which helps to extend battery life. This article describes how to set the battery charging threshold for ASUS laptops on Linux.
Battery life is affected by age, high temperature, number of charging cycles and full charging time. The battery charge threshold can reduce the time to fully charge (100%), thereby improving the health/life of the battery.
ASUS laptop supports setting the charging threshold Start from Linux 5.4. Assuming it is the first battery, the kernel WMI method of setting the charging threshold does not provide a method for specifying the battery.
BAT0).However, for some newer ASUS laptops, it is not called the main battery
BATT (E.g. Zenbook UM431DA) and
BAT1 (For example, ASUS TUF Gaming FX706II). [Edit] There is also BATC.
Therefore, although ASUS laptops support limited battery charging starting from Linux 5.4, this is only applicable to laptops with the following features:
BAT0.For Asus laptop use
BATT As the main battery name, you need Kernel 5.7,and
BAT1 you need to 5.8 kernel (In the instructions below, you will know exactly how to check the battery name). [Edit] For ASUS laptops that use the BATC battery name, you need to use Linux 5.9 Or higher.
In addition, not all ASUS laptops support setting the battery charging threshold, so depending on your ASUS laptop model, this setting may not work for you. I cannot find a list of supported devices.
It is worth mentioning that the kernel WMI method of setting the battery charging threshold for ASUS laptops can only set the termination value (
charge_control_end_threshold) (It is also not possible to set the start threshold). Similarly, when AC power is connected, if the battery power is higher than the charge stop threshold, it will not be discharged to the stop threshold.
There is another caveat. When my ASUS ZenBook 14 UX433FAC is running on Ubuntu 20.04 with GNOME Shell, if the battery charge is restricted when the battery level is equal to or greater than the charging threshold, and then the laptop is connected to AC power, the battery indicator on the top panel The device will change from the remaining time until the battery is discharged, and the remaining time until the battery is fully charged. This happens even if the battery is not charged. After a while (so when you connect the laptop to AC power, this does not happen immediately), the battery indicator should change to “not charged”.
In addition to Asus, there are also some Lenovo and Huawei (the latter received Linux 5.5) The laptop also supports limiting battery charging. But since I only have an ASUS laptop and cannot test it on other devices, this guide only applies to ASUS. Lenovo has provided support for this for a long time, and TLP also supports setting this built-in function (only for IBM/Lenovo ThinkPads). By the way, this is the GUI of TLP, which can be easily configured without you using it.
You might also like: auto-cpufreq is a CPU speed and power optimizer for Linux
1. Find out the name of your ASUS laptop battery.
Let’s start by determining the battery name of the ASUS laptop. This can be done by using the following command:
This command should output the following:
In this example (from my ASUS laptop), the name of the battery is
BAT0, But as I mentioned above, for you,
BATT, This is the only battery name supported by the ASUS laptop kernel.
2. Create a systemd service to set the threshold at which the battery will stop charging at boot time.
Before creating a systemd service, please check if your laptop actually has
/sys/class/power_supply/BAT* (Without it, it will not work properly):
If this command returns to the path
charge_control_end_threshold, Your ASUS laptop supports limiting battery charging. If the command returns an error, indicating that there is no such file or directory, then your laptop does not support setting the charging threshold.
If your ASUS laptop has this file, we can continue.Create a file we call
You can open this file with the following default console text editor:
sudo editor /etc/systemd/system/battery-charge-threshold.service
Or use Gedit or whatever graphical editor you want to use (for example, for Gedit, open this file as root:
In this file, you need to paste the following:
[Unit]Description=Set the battery charge thresholdAfter=multi-user.targetStartLimitBurst=0
[Service]Type=oneshotRestart=on-failureExecStart=/bin/bash -c 'echo CHARGE_STOP_THRESHOLD > /sys/class/power_supply/BATTERY_NAME/charge_control_end_threshold'
BATTERY_NAME Name with battery (
CHARGE_STOP_THRESHOLD The battery charge stop threshold you want to use (between 1 and 100).note I read A user cannot set the charging threshold to any value, but can only set it to 60, 80, and 100.
According to my reading, in order to make the laptop connected to AC power most of the time, in order to achieve the best battery life, please set the battery charge stop threshold to about 50 or 60. If the battery is used frequently, set the battery charge stop threshold to. About 90
3. Enable and start the battery charging threshold system service.
Now, enable and start the newly created battery charging threshold systemd service:
sudo systemctl enable battery-charge-threshold.servicesudo systemctl start battery-charge-threshold.service
Using systemd 220, you can directly use the enable and start services
systemctl enable --now, But I prefer to use 2 commands in case some readers use the old systemd version.
If you want to change the threshold level at which the battery stops charging, you need to edit
/etc/systemd/system/battery-charge-threshold.service File and then from
ExecStart Line (after
echo) Is set to the new value you want to use, and then use the following command to reload systemd (because the file content has changed) and restart the systemd service:
sudo systemctl daemon-reloadsudo systemctl restart battery-charge-threshold.service
4. Verify that the battery charge stop threshold is working properly.
If your ASUS laptop supports this feature, you should now set the battery charging limit to the value you used in step 2.
You can check by charging the laptop to the set threshold
battery-charge-threshold.serviceAnd then use the following command:
BATTERY_NAME With the name of the battery, as described in step 1.
If the battery charge stop threshold is working properly, the command should display the following output:
If it says “Discharging”, please make sure that your ASUS laptop is actually powered by AC power and not on battery power.However, if it says “charging”, then… then your laptop is charging and exceeds the charging stop threshold, so this does not apply to you because your ASUS laptop does not support it (if you have
charge_control_end_threshold As mentioned in step 2), the Linux version you are using is too old to restrict battery charging on ASUS laptops, or due to human error 😁️.
Extra: If you don’t use systemd, you can also use cron and run
sudo crontab -e Then paste the following line (this is a single line, please three-click the line to select the entire line):
@reboot echo CHARGE_STOP_THRESHOLD > /sys/class/power_supply/BATTERY_NAME/charge_control_end_threshold
CHARGE_STOP_THRESHOLD And the battery charge stop threshold you want to use and
BATTERY_NAME The battery name is shown in step 1.
Why use system services or cron jobs? According to u/esrevartb’s suggestion, I adapted these instructions from it, “It seems that the udev rule does not work because the battery sysfs path has not been initialized when the rule is applied, or because the specific charge_control_end_threshold attribute cannot be set to modify this way”.
[[Edit] I noticed that too Scripts and system services Easily set battery charging limits for ASUS laptops on Linux.With it, it’s easier to change the battery limit (all you have to do is run
Related to laptop battery: Bwall is an animated battery wallpaper on Linux (Bash script)
by r/linux hardware (Thank you / esrevartb)