How can I limit battery charging to 80% capacity?

228,901

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.

Solution 3

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.

Solution 4

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.

Solution 5

  1. Install TLP:
    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
    
  2. Open config file of TLP
    sudo gedit /etc/tlp.conf
    
  3. Find the lines regarding battery settings, remove the leading # for comment and maybe insert the value you want
    START_CHARGE_THRESH_BAT0=75
    STOP_CHARGE_THRESH_BAT0=80
    
  4. Restart tlp
    sudo tlp start
    
  5. Check the config status
    sudo tlp-stat -b
    
Share:
228,901
RusGraf
Author by

RusGraf

My goal here is usually to document.

Updated on September 18, 2022

Comments

  • RusGraf
    RusGraf over 1 year

    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?

    • cfi
      cfi over 12 years
      Can you confirm that aquaherd's answer works for you?
  • RusGraf
    RusGraf almost 13 years
    There is no such setting in the BIOS setup screen.
  • cfi
    cfi over 12 years
    Thanks for this info. It's a good start - hopefully at least for the original Q asker. Hardware vendors should offer more support for linux driver developers. It's a shame that so much time has to be wasted having to reverse engineer hardware protocols.
  • RusGraf
    RusGraf over 12 years
    Works just as described on my ThinkPad X60 running Ubuntu 11.10.
  • RusGraf
    RusGraf over 12 years
    I'll hold off on accepting this until cfi's bounty ends so as not to turn away people who might know a more general solution before they view this page. Also, @cfi, ping.
  • cfi
    cfi over 12 years
    Awarded the bounty as aquaherd took the time and at least successfully solved the original question.
  • Alex Malex
    Alex Malex over 11 years
    I did in Ubuntu sudo apt-get install tp-smapi-dkms. It installed. Then I'm doing echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh and it says bash: /sys/devices/platform/smapi/BAT0/start_charge_thresh: No such file or directory. Why?
  • Alex Malex
    Alex Malex over 11 years
    @ændrük, it doesn't work for me for some reason, although I did what aquaherd said. The files wasn't created. Why?
  • RusGraf
    RusGraf over 11 years
    @Alex I've added a few details above that the original instructions didn't explicitly mention. If you have trouble loading tp_smapi or if /sys/devices/platform/smapi still doesn't exist after loading it, I'd suggest opening a new question about it.
  • Alex Malex
    Alex Malex over 11 years
    @ændrük, alex@ubuntu:~$ sudo modprobe tp_smapi FATAL: Error inserting tp_smapi (/lib/modules/3.5.0-17-generic/updates/dkms/tp_smapi.ko): No such device. Did I miss something? I'm going to open a new question if I don't get the anwer.
  • don.joey
    don.joey over 11 years
    @Alex I have the same problem, did you open a question?
  • Alex Malex
    Alex Malex over 11 years
    @Private, not yet.
  • shravan
    shravan almost 10 years
    Does it work for HP laptops?
  • Elder Geek
    Elder Geek almost 10 years
    welcome to askubuntu! Your results with Mint don't appear to be Ubuntu related. Can you rephrase your answer in terms that are relevant to this site? Thank you!
  • eosphere
    eosphere over 9 years
    Hello Elder Geek, this is bios related therefore will work with any operating system in a dual boot configuration. This Toshiba bios configuration is not accessible by bios menu but only with the Power Saver Application that runs on Windows only.
  • ctrl-alt-delor
    ctrl-alt-delor over 8 years
    Same for me on linovo yoga 3 11inch.
  • Mika
    Mika over 8 years
    Setting the start_charge_thresh didn't work for me too. I read from some blog or forum that in my model T420 the api is broken. It is like a bug in the hardware. The stop_charge_thresh works just fine.
  • antivirtel
    antivirtel about 8 years
    I'm having the same issue, but on Ubuntu 14.04 LTS (latest updates) install process: paste2.org/NDdCEtyJ --- Loading module: $ sudo modprobe hdaps_ec modprobe: FATAL: Module hdaps_ec not found. --- $ sudo insmod /lib/modules/3.13.0-83-generic/updates/dkms/tp_smapi.ko insmod: ERROR: could not insert module /lib/modules/3.13.0-83-generic/updates/dkms/tp_smapi.ko: Unknown symbol in module
  • lisimba.gilkes
    lisimba.gilkes over 7 years
    These instructions have worked for me on a Thinkpad T400 running Ubuntu 14.04.
  • wadie
    wadie almost 7 years
    Would this work on ideapad ?
  • Luckyrings
    Luckyrings almost 7 years
    It needs a ThinkPad laptop to set these charging values with TLP. TLP supports other laptops too (e.g. Dell, HP) but does not support all features as written in FAQ on the page from linrunner. For configuration of the charging thresholds see: linrunner.de/en/tlp/docs/…
  • Kasun Siyambalapitiya
    Kasun Siyambalapitiya about 6 years
    where is the list of supported devices? I am unable find a section on their doc. By any chance do you know whether tlp is supported for Thinkpad X1 carbon as well
  • liori
    liori about 6 years
    @KasunSiyambalapitiya, as of now, tlp is only a frontend to the two tools it uses for this purpose, Tp smapi and tpacpi-bat. As long as your model is supported by at least one of them, it should work (or file a bug). Yours doesn't seem to be listed on either of their supported hardware pages, but a quick googling reveals that the latter might work.
  • Stefan Reich
    Stefan Reich almost 6 years
    Results with Mint are obviously Ubuntu-related.
  • axolotl
    axolotl about 4 years
    As of 2020, is this still valid?
  • karlsebal
    karlsebal over 3 years
    partly, tp_smapi is not working anymore, but there is a kernel module since 4.18 thinkpad_acpi which does the job.
  • Fred Schoen
    Fred Schoen over 3 years
    The instructions above are still valid after 6 years on my new Thinkpad E495 but meanwhile if secureboot is enabled, I can't just add a kernel module and the ./install.pl step fails with modprobe: ERROR: could not insert 'acpi_call': Operation not permitted. A workaround is to disable secure boot or to sign the modules manually; cf. e.g. askubuntu.com/questions/1114867
  • xuancong84
    xuancong84 over 3 years
    On my thinkpad, the config file is in /etc/default/tlp
  • w-sky
    w-sky almost 3 years
    "Battery charge thresholds, discharge and recalibration are currently only supported for IBM/Lenovo ThinkPads. Any other Lenovo laptop models including IdeaPads and all other laptop brands are not supported. TLP 1.3.1 does not support the kernel’s natacpi implementations for Asus and Huawei laptops because of differing sysfiles" Source: linrunner.de/tlp/usage/tlp.html I would like to see an implementation for ASUS laptops. Mine does include a charge control utility by Asus too but for Windows only.
  • w-sky
    w-sky almost 3 years
    Found a guide to use charge control on Asus laptops here: linuxuprising.com/2021/02/…
  • bmaupin
    bmaupin almost 3 years
    Amazing! This seems to work with other Dell models as well, such as the Latitude 5420. And it's open-source 😁 github.com/dell/libsmbios/blob/master/src/bin/…
  • tanius
    tanius over 2 years
    Good news (esp. for @w-sky): TLP ≥1.4 also can set battery charge limits for Asus, Huawei, LG, other Lenovo, and Samsung notebooks (source).
  • Jekson
    Jekson over 2 years
    My settings is START_CHARGE_THRESH_BAT0=60 STOP_CHARGE_THRESH_BAT0=81 When I plug in the charger, the level reaches 80% and stops. Everything is as expected. But how does the lower range work? With the charger on, the level is always constant at 80%.
  • Krzysztof Krasoń
    Krzysztof Krasoń over 2 years
    @karlsebal and with thinkapd_acpi, where can I find battery charging thresholds? I can't find it inside /sys/devices/platform/thinkpad_acpi/
  • Pablo Bianchi
    Pablo Bianchi over 2 years
  • karlsebal
    karlsebal over 2 years
    @KrzysztofKrasoń see unix.stackexchange.com/a/560047/188466 it is in /sys/class/power_supply/BAT0
  • Gabriel Staples
    Gabriel Staples over 2 years
    I don't have Windows on my Toshiba--only Ubuntu 20.04. I know this works when set up in Windows dual boot as you said (I have another computer where I've proven this), but I wonder if this would work if I ran the Toshiba program from Windows 10 in a VirtualBox virtual machine. Anybody know?
  • Gabriel Staples
    Gabriel Staples over 2 years
    Does this work on Thinkpads only? Would it work on a Toshiba Satellite?
  • Gabriel Staples
    Gabriel Staples over 2 years
    Unfortunately, not compatible with my Toshiba Satellite C55t-B5109. Running bat release 0.8.4: Cmd: ./bat --threshold Response: "This program is most likely not compatible with your system. See github.com/tshakalekholoane/bat#disclaimer for details."
  • Gabriel Staples
    Gabriel Staples over 2 years
    Program crashes on my Toshiba Satellite C55t-B5109 running Ubuntu 20.04. Last part of the stack trace: File "/usr/lib/python3/dist-packages/libsmbios_c/smbios_token.py"‌​, line 145, in __getitem__ raise IndexError(_("SMBIOS Token ID 0x%04x not found") % id ) IndexError: SMBIOS Token ID 0x0349 not found
  • Hosein Rahnama
    Hosein Rahnama about 2 years
    Is there a way to have two thresholds like start_charge_threshold and stop_charge_threshold? so that we can control when the charging starts and ends.
  • Hosein Rahnama
    Hosein Rahnama about 2 years
    I used this method for an ASUS-N580V, but this causes the battery to heat up abnormally, while this isn't the case when I used the ASUS Battery Health Charging on Windows.
  • AjayC
    AjayC about 2 years
    @HoseinRahnama : I have not faced any heating issue on Ubuntu. Mine is ASUS S430UA. Not aware of any technique/hack to set start threshold.
  • Hosein Rahnama
    Hosein Rahnama about 2 years
    Another issue that I have is that when I connect the charging cable and set the threshold to 60 and the battery is in 80 state, the operating system shows that the battery is not charging but the it does not drop to 60 as the time goes on. I am using Ubuntu 20.04 LTS.
  • Ron Michael
    Ron Michael about 2 years
    Works with Thinkpad L490 running Ubuntu 21.10 Just after the Step 3. run this command to enable the service after restart systemctl enable tlp.service
  • flyingdrifter
    flyingdrifter about 2 years
    your first link says "with this driver" is that included with the kernal or do you have to add it separately?
  • flyingdrifter
    flyingdrifter about 2 years
    more vendors have been added including LG! linrunner.de/tlp/settings/bc-vendors.html
  • lorenzo-bettini
    lorenzo-bettini about 2 years
    @flyingdrifter it's included in the kernel, but you should use at least version 5.15 because, in the previous kernels, I noticed that the value is not persisted in the file, even if you write it.