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:
How can I do this in Ubuntu?
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It only takes a minute to sign up.Sign up to join this community
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
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
/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):
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.
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
git clone https://github.com/teleshoes/tpacpi-bat.git cd tpacpi-bat/ ./install.pl sudo ./tpacpi-bat -s ST 1 15 # load internal battery when below 15% sudo ./tpacpi-bat -s SP 1 95 # stop charging at 95% sudo ./tpacpi-bat -g ST 2 # when is external battery loaded?
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.
sudo add-apt-repository ppa:linrunner/tlp sudo apt update sudo apt install tlp ################ check what package needed for battery: sudo tlp-stat -b ################ if acpi_call is recommended sudo apt install acpi-call-dkms ################ if smapi is recommended sudo apt install tp-smapi-dkms
sudo gedit /etc/tlp.conf
sudo tlp start
sudo tlp-stat -b
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
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.
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
$ ./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 --threshold 60
Very often (almost always) this is an option in the BIOS that Windows can change remotely. It's very difficult to remote change this in Linux. My suggestion? When starting up your computer, smash the function keys, specifically F1, F2, F3, F6, F8, F10, and F12. One of these (maybe another) will put you into the bios menu. It says which key on startup, but it doesn't usually stay up long enough.
Look for power settings (only arrow keys here, no mouse). Find batter saver or batter optimizer or something along those lines. Change that to enabled, and then save and restart. This should do it.
Linux tends to freak out when the battery doesn't charge past 80%, but it will just ruin your expected charge times. Nothing to worry about here.
Still need help? Comment your question! Did I help? +1 me :)
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:
sudo smbios-battery-ctl --set-custom-charge-interval 75 80 sudo smbios-battery-ctl --set-charging-mode=custom
This will start charging when the battery falls below 75%, and stop charging when it reaches 80%.
To change the setting back:
sudo smbios-battery-ctl --set-charging-mode=adaptive