19

I have Asus Zenbook UX430UN and in windows it have some kind of battery health management program. And this program propose option called "Maximum Life-span" the idea is to hold battery on +- 60% of charge when in connected to the AC. So, how can I achieve similar result on Ubuntu?

N0rbert
  • 99,918

3 Answers3

16

Kernel 5.4 did bring the ability to set the battery percentage under which charging will trigger.

The change in asus-wmi added a charge_control_end_threshold in sysfs.

You can manually set the charge_control_end_threshold to 60 in /sys/class/power_supply/BAT0/charge_control_end_threshold as su to test if it works on your laptop. You should unplug your device and let the battery discharge a little and then plug your device, if system doesn't charge your battery when it's over 60% then you're good. but it will regenerate every time you reboot.

A simple udev rule can be made:

KERNEL=="BAT0", SUBSYSTEM=="power_supply", ATTR{charge_control_end_threshold}="80"

Within /etc/udev/rules.d.

Read the udev and Asus articles on Arch wiki for more info.

Pablo Bianchi
  • 15,657
mzeinali
  • 161
  • 1
    I confirm this works on an Asus Zenbook 15 UX534FAC from October 2019 using clonezilla-live-20200414-focal-amd64 and archlinux-2020.04.01-x86_64.iso: first battery was charging at 74% (checked with cat /sys/class/power_supply/BAT0/capacity), then I entered echo 60 | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold) and the charging stopped, as confirmed by cat /sys/class/power_supply/BAT0/status. Nice! – neitsab Apr 26 '20 at 16:51
  • 1
    This also worked on an ASUS Vivobook X507UF from August 2018 with Linux kernel v5.5.19 on Ubuntu 19.10 with BIOS version 304. – ManSamVampire May 02 '20 at 05:59
  • You can see this issue, more specifically this comment and my gist based on that. If you want to help the TLP team for supporting more devices. – mzeinali May 03 '20 at 08:53
  • 1
    this works on my M509D Asus notebook but you mean it resets to 100 each reboot unless I set the rule? – mLstudent33 Feb 06 '21 at 07:57
  • 1
    Lenovo Ideapad does not have this file and trying to create it with 'sudo` says permission denied. – mLstudent33 Feb 09 '21 at 01:44
4

TLP – Linux Advanced Power Management TLP brings you the benefits of advanced power management for Linux without the need to understand every technical detail. TLP comes with a default configuration already optimized for battery life, so you may just install and forget it. Nevertheless TLP is highly customizable to fulfil your specific requirements.

Taken from this topic How can I limit battery charging to 80% capacity? but here you can found about ThinkPad laptops too Ubuntu package can found here: Ubuntu Package

Sagi Weizmann
  • 741
  • 5
  • 9
  • 1
    Thx for answer, but I saw this post and my question is, will this work for Asus? Or if vendor already did some software for windows that do this, so laptop have hardware support for this feature and this TLP package could do the trick too? – stronk_kisik Jul 15 '18 at 10:12
  • Charge thresholds are for ThinkPads only (because of necessary kernel support). – linrunner Jul 16 '18 at 19:33
4

I wrote a command line application that does this.

The easiest way to get started is download the app from the releases page and run

$ ./bat --help

from the terminal in the directory where it is located which should show the help documentation.

If there's an error, it might have to do with permissions. The following command might solve the problem.

chmod +x ./bat

Basically, running

$ ./bat --threshold

will print out the current threshold.

To set a new threshold, say 60%, run

./bat --threshold 60

To persist the current threshold between restarts, run

sudo ./bat --persist

Note: Persisting uses systemd under the hood but this is bundled with most Linux distributions including Ubuntu.

Tip: Putting the app in a directory like /usr/local/bin/ that is in the $PATH will enable you to run it from anywhere and not just in the directory the app is in. Then the above commands become,

bat --help
bat --threshold 60
bat --persist

respectively.