Computer/how to set up ASUS battery charge threshold (Limit) on Linux

From Mamin LAB
Jump to navigation Jump to search

How to access ASUS Battery related information and changing the battery charge threshold (limit) on Linux[edit | edit source]


Main_Page > Computer > Setting up ASUS battery charge threshold (Limit) on Linux



You can search the battery name on Linux system.

$ ls /sys/class/power_supply/
(Example)  AC0  BAT0  hid-0018:04F3:2555.0001-battery

You can see "BAT0" on this example (My laptop with Ubuntu 20.04 - Kernel 5.8.0).
This is the battery name on Linux system.

It needs to be used above Linux version 5.4 if you see the BAT0.

It needs to be used above Linux version 5.7 if you see the BATT.

It needs to be used above Linux version 5.8 if you see the BAT1.

It needs to be used above Linux version 5.9 if you see the BATC.

Now you can see what kinds of information you can get from "BAT0" folder.

$ ls /sys/class/power_supply/BAT0/
alarm                         cycle_count         energy_now    power          status      uevent
capacity                      device              hwmon2        power_now      subsystem   voltage_min_design
capacity_level                energy_full         manufacturer  present        technology  voltage_now
charge_control_end_threshold  energy_full_design  model_name    serial_number  type

You can see the battery related information from here. Each file has different information.
If you want to see the battery charge status, then you can see inside the file.

$ cat /sys/class/power_supply/BAT0/status
Charging
(or) Discharging
(or) Not charging

You can check the battery capacity.

$ cat /sys/class/power_supply/BAT0/capacity
66

This means the battery capacity is now 66%.

And you can check the battery charge threshold (limit).

$ cat /sys/class/power_supply/BAT0/charge_control_end_threshold
100

This means the threshold is 100 percent.

If you want to setup battery charge threshold (limit) as 60%, just you can type below command with Administrator privilege.
(Some ASUS laptops can support the value only 60%, 80%, 100%. My laptop UX461F can support another values. Such as 70%...)

$ sudo bash  (Enter Administrator privilege.)
# echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold

That's it!
It's easy to control the battery charge threshold, isn't it? :)


How to set the battery charge threshold on Linux after rebooting automatically[edit | edit source]

If you want to set the charge_control_end_threshold after rebooting, then you can setup a systemd file.

# vi /etc/systemd/system/battery-charge-threshold.service

Below exmaple is for 60% threshold. you can change the value from "60" to your desired value (percentage).

[Unit]
Description=Set the battery charge threshold
After=multi-user.target
StartLimitBurst=0

[Service]
Type=oneshot
Restart=on-failure

ExecStart=/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target

Now you can enable the battery charge threshold under service level.

# systemctl enable battery-charge-threshold.service
Created symlink /etc/systemd/system/multi-user.target.wants/battery-charge-threshold.service → /etc/systemd/system/battery-charge-threshold.service.

If you want to change the threshold, then you can reload the file after modifying the file "battery-charge-threshold.service".

# systemctl daemon-reload
# systemctl restart battery-charge-threshold.service

If you don't reload the file with command "systemctl daemon-reload", then you may get the below error message.

Warning: The unit file, source configuration file or drop-ins of battery-charge-threshold.service changed on disk. Run 'systemctl daemon-reload' to reload units.

That's it!
Now we don't need to be worried about the battery will be worn out by 100% charging situation on Linux. :)
Enjoy your Linux life!