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 ?
To stop charging at 60%, I use
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
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/
.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
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.
Basically, running
will print out the current threshold.
To set a new threshold, say 60%, run
To persist the current threshold between restarts, run
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,respectively.
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:
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.
Downgrade to BIOS version 302. Your laptop model might be different so choose according to your laptop model. Unzip the BIOS file.
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
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.
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
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
)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.