18

I've recently switched from Windows to Ubuntu, and I was kind of frustrated when I found out that there was no way to set battery thresholds on Linux. On Windows, I can choose to limit charge to 60% (the laptop stops charging at 60% and resumes charge at 58%, in order to preserve battery life). I tried setting up the same procedure with tlp, but it only works on Lenovo ThinkPads. My computer is an ASUS VivoBook S14, I am running a dual boot Windows 10 - Ubuntu 16.04.

I wanted to know if there was any piece of software that could control the battery charge ? Or maybe a way to use tlp in order to set battery thresholds ?

2
  • In Windows 10 I set battery threshold a couple months ago on my Dell based laptop. I see in Ubuntu 16.04.3 LTS it is frozen at 66% threshold ever since. Feb 16, 2018 at 13:20
  • 1
    This post can be helpful too. Feb 8, 2022 at 10:08

5 Answers 5

17

To stop charging at 60%, I use

echo 60 | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

Currently my battery is at 63%, so it is not charging (the power led is white). If I run the above command with 70 instead of 60, then it starts charging again (the power led becomes red).

This setting is lost when I reboot the computer. To make it persistent, I have added

@reboot root echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold

to my /etc/crontab.

My laptop is an Asus Zenbook running under Ubuntu 20.04 LTS, but maybe this can work for other brands/distributions as well - explore what you have under /sys/class/power_supply/.

4
  • Thank you! This worked great on my UX430. Trying to get the most our of my dying battery until I get a replacement.
    – elclanrs
    May 18, 2020 at 7:02
  • Worked on an Asus Zenbook UX431
    – nabla
    Sep 30, 2020 at 14:30
  • Works for ASUS Vivobook S14 as well. Thanks! Nov 22, 2020 at 15:48
  • 1
    How do you make sure this cron runs after asus-wmi? Seems more reliable a service aproach (related). BTW, if even with root you get Permission denied you might need to use the udev way. Nov 16, 2021 at 5:30
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.

1
  • TL;DR: git clone [email protected]:tshakalekholoane/bat.git && cd bat && yes | sudo apt install golang-go && go build ./cmd/bat/ && ./bat --threshold 98 It has a nice error message if the code thinks your system isn't supported: This program is most likely not compatible with your system. See https://github.com/tshakalekholoane/bat#disclaimer for details.
    – a.t.
    Aug 3, 2022 at 15:50
3

I owned an Asus X405UQ which came with this Battery Health Charging app that controls the charging threshold. But since I only use Windows 10 for gaming, I've setup my working environment and install Ubuntu 18.04 dual booting on Windows 10. I plug my laptop whenever there is an AC power available and it stays plugged in when I'm working. I use the battery only if I work while on long trips, so I searched for a similar app for Linux. I've learned that the driver to make this work is vendor specific and that Asus has no driver support for Linux like Thinkpads does with TLP. (next time I'll be buying Thinkpads instead).

But I found out that booting to Windows and setting the charge threshold to i.e. 60% before rebooting to Ubuntu 18.04 (without powering off or shutting down) will persist the charge threshold. Even thought I disconnect the power adapter and allowed it to drain the battery, plugging it in again charges it up to 59% or 79% depending on the preset threshold (it is always 1 percent short than the indicated threshold level). It will only revert to original state (charges up to 100%) if I power off my laptop, unplug the adapter, power it on and boot to Ubuntu directly without going first to Windows or if I set it to 100% using the battery app in Windows.

I was happy with this setup since it is better than to have no threshold control at all. However, my laptop went back to the store for repair (intermittent wifi connection on 5GHz band) and when I received it (restored to original factory default, Ubuntu erased) and installed again Ubuntu 18.04 that feature no longer persist.

I've tried updating Ubuntu Kernels but to no avail. When I tried upgrading the BIOS, I've found out that the one installed version 305 at the time of this writing does not yet exist on Asus support page (some forums says Microsoft update is responsible for this) and the most recent was just 304. I've tried downloading WinFlash from Asus site but downgrading BIOS with the /nodate trick doesn't work.

The solution that worked for me:

  1. Download Asus WinFlash 3.0.1 and install it. Do not use the latest version 3.2.5 or above as it no longer allows the /nodate option. I guess the most recent BIOS update addresses some of the spectre vulnerability and they do not want you to downgrade BIOS version but my battery life is much more important for me.

  2. Downgrade to BIOS version 302. Your laptop model might be different so choose according to your laptop model. Unzip the BIOS file.

  3. Type "WinFlash" on the start menu. Right click on the WinFlash icon and select "Open file location". This will open a Windows Explorer showing the start menu shortcuts. Right click on the WinFlash shortcut and select properties. On the leftmost end of the target path, after the double quotes, add a blank space then type in "/nodate" without the quotes. End result will look like this: "C:\Program Files (x86)\ASUS\WinFlash\WinFlash.exe" /nodate

  4. Run WinFlash using that modified shortcut and select the downloaded BIOS file. The Update button should not be grayed out anymore. Click Update and afterwards, it will ask you to reboot so it can flash the BIOS. Make sure you are plugged-in or your battery level is high.

  5. The laptop will enter the BIOS screen and you will see a progress indicator. My laptop restarted twice during the process. I allowed it to boot to Windows first then I restarted it and enter my BIOS settings to disable secure boot (to allow my Ubuntu 18.04 to boot). At this point, if you had your threshold level lower than the battery current charge level, you should notice the led power indicator on your laptop turning white instead of amber indicating that the battery is not charging anymore. This should persist even though you had restarted your laptop before booting to Ubuntu

0

Here is my answer (a short python script). This works well on my ROG STRIX G731GU.

Dont forget to run the code as admin. (sudo python3 filename.py)

0

tlp now works on (selected?) ASUS models:

https://linrunner.de/tlp/news.html#how-can-i-use-battery-care-with-my-laptop

"TLP includes battery charge thresholds for Lenovo (and IBM) ThinkPads from the very beginning. That remained so for a long time. Recently - with version 1.4 and 1.5 - numerous vendors have been added: ASUS, Huawei, LG, Lenovo (non-ThinkPad series), Samsung and Sony."

I've used this on a recent Asus Vivobook model (M3401QA) with Debian 11 and the debian-backports version of tlp, and the tlp setcharge command works to set the battery charge limit but not the start point. So you can get the threshold you want to stop charging but not the start/lower threshold.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .