How can I limit battery charging to 80% capacity?

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:

screenshot

How can I do this in Ubuntu?


Solution 1:

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:

sudo apt-get install tp-smapi-dkms
sudo modprobe tp_smapi

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.

Solution 2:

There's a somewhat nicer application now available to Ubuntu (and other distributions):

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.

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.