I just learned that some Lenovo laptops include a utility that offers to limit battery charging capacity to within 0–80% in order to slow the attenuation of the battery lifespan:
and write the desired charging thresholds to virtual files in /sys/devices/platform/smapi:
echo 40 | sudo tee /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 80 | sudo tee /sys/devices/platform/smapi/BAT0/stop_charge_thresh
Then it will stop charging once it reached 80% and only start charging when it drops below 40%.
Toshiba and others might have a similar kernel module that exposes firmware functionality to the /sys or /proc space, but it is very unlikely for patent issues. For the same reasons, an application that could handle this would be either Thinkpad- specific or only address a few select vendors.
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.
One of the parameters it controls is maintaining battery charging limits. As pointed by @tanius in the comments (please upvote them!), while TLP used to only work on Thinkpads, the newest version has support for devices from multiple vendors, and given the nature of the project—if the appropriate drivers for other devices will become available, it is likely these will get integrated into this project too. So if you're reading this comment in few years, check the documentation, maybe your device is now supported.
I have a Asus laptop and the approach which I have found from internet is as follows. This approach may already be a part of some of the apps mentioned above but putting it here for information.
Create a service file named battery_charge_threshold.service like this.
After doing this, charge threshold of 80% (as per service file) will persist between reboots. It will also stop charging the battery if the current level is above 80%.
Hope this helps. I have been using it for almost 1.5 years without any issue.
Did you check to see whether there is a BIOS setting on your laptop for this? My laptop had a Windows Application as well as a "Battery Life Extender" setting in the BIOS for this exact feature.
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,
On my Dell XPS, I installed the smbios-utils package using sudo apt install smbios-utils. This package provides a command called smbios-battery-ctl. It looks like battery level based charge control has been available since Ubuntu 20.04. Full details are in the manpage, but for a basic 80% setting, I think this will work:
There is a hardware hack I just discovered for Dell laptops:
Dell chargers use 3 pins, one for (+), one for (-) and one for Dell Charger Identification Communication (a 1-Wire protocol). This communication line is usually the one in the center of connector, the needle like pin.
If you cut this communication line, laptop will continue running from AC but the battery won't be charged anymore.
Locate the communication line, cut it, place a switch in between. Charge your laptop's battery as much as you want and then turn off that switch. Your laptop will use AC but your battery will stay put at the charge you left it.
The charging thresholds are, very unfortunately, firmware and vendor specific.
The Lenovo ThinkPad user is luckily provided with a solution outlined on ThinkWiki.
It basically says that you would have to install and load the
tp_smapi
kernel module:and write the desired charging thresholds to virtual files in
/sys/devices/platform/smapi
:Then it will stop charging once it reached 80% and only start charging when it drops below 40%.
Toshiba and others might have a similar kernel module that exposes firmware functionality to the
/sys
or/proc
space, but it is very unlikely for patent issues. For the same reasons, an application that could handle this would be either Thinkpad- specific or only address a few select vendors.There's a somewhat nicer application now available to Ubuntu (and other distributions):
One of the parameters it controls is maintaining battery charging limits. As pointed by @tanius in the comments (please upvote them!), while TLP used to only work on Thinkpads, the newest version has support for devices from multiple vendors, and given the nature of the project—if the appropriate drivers for other devices will become available, it is likely these will get integrated into this project too. So if you're reading this comment in few years, check the documentation, maybe your device is now supported.
Ubuntu packages are available in the official repository.
The accepted answer does not work on my new Lenovo T440s. Apparently the firmware changed. Following http://www.thinkwiki.org/wiki/Tpacpi-bat, I did
For reference, I did this on debian testing but I'm sure it works in ubuntu just as well.
On my Toshiba R830 running Windows 8.1, I installed the Toshiba Power Saver application in order to limit the battery charge to 80%
When I boot on Linux (Ubuntu, Mint, etc), the maximum charge is still limited to 80%.
Therefore, the Toshiba Power Saver seems to store its configuration into the bios.
The only drawback is that if I want to travel with a fully charged battery, I have to reboot on Windows and change the Power Saver configuration.
I have a Asus laptop and the approach which I have found from internet is as follows. This approach may already be a part of some of the apps mentioned above but putting it here for information.
battery_charge_threshold.service
like this./etc/systemd/system
After doing this, charge threshold of 80% (as per service file) will persist between reboots. It will also stop charging the battery if the current level is above 80%. Hope this helps. I have been using it for almost 1.5 years without any issue.
Did you check to see whether there is a BIOS setting on your laptop for this? My laptop had a Windows Application as well as a "Battery Life Extender" setting in the BIOS for this exact feature.
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.
On my Dell XPS, I installed the
smbios-utils
package usingsudo apt install smbios-utils
. This package provides a command calledsmbios-battery-ctl
. It looks like battery level based charge control has been available since Ubuntu 20.04. Full details are in the manpage, but for a basic 80% setting, I think this will work:This will start charging when the battery falls below 75%, and stop charging when it reaches 80%.
To change the setting back:
There is a hardware hack I just discovered for Dell laptops:
Dell chargers use 3 pins, one for (+), one for (-) and one for Dell Charger Identification Communication (a 1-Wire protocol). This communication line is usually the one in the center of connector, the needle like pin.
If you cut this communication line, laptop will continue running from AC but the battery won't be charged anymore.
Locate the communication line, cut it, place a switch in between. Charge your laptop's battery as much as you want and then turn off that switch. Your laptop will use AC but your battery will stay put at the charge you left it.
See this answer for recommended charge levels for various scenarios: https://superuser.com/a/664583/187576
Edit
Apperently a disadvantage of this approach is that the laptop degrades its performance if no identified charger found.
This might not be an issue for normal usage, however, if you need your CPU power for like 3D design, the performance is degraded noticeably.