27

My laptop is Lenovo T400, and OS is Ubuntu 12.04.

I have not been able to adjust the thresholds for battery starting charging and stopping charging. I observed that its current starting charging threshold is about 40%, and stopping charging threshold is about 60%. I forgot if it was me and which program I used to control the battery to stop charging at 60% and start charging at 40%.

I followed my previous post https://askubuntu.com/questions/58789/how-to-check-charged-percentage-of-battery-and-to-adjust-its-thresholds, but I don't find /sys/devices/platform/smapi. Also I have /proc/acpi/battery/BAT0/, but I have only three files alarm, info and state.

I want to adjust the thresholds. So I wonder how to do that?

Tim
  • 98,580
  • 191
  • 570
  • 977
  • Try `modprobe tp_smapi` as root, and then see if the files under `/sys/devices/platform/smapi` are there. – Renan Sep 18 '12 at 17:18
  • @Renan: the module is not found `FATAL: Module tp_smapi not found.`. – Tim Sep 18 '12 at 17:44
  • 1
    Install tp_smapi according to the instructions there: http://www.thinkwiki.org/wiki/Installing_Ubuntu_12.04_%28Precise_Pangolin%29_on_a_ThinkPad_X220 then try again. – Renan Sep 18 '12 at 17:46
  • @Renan: Is tp_smapi only for Lenovo laptops? Are battery charging management modules different for different brands of laptops? – Tim Sep 19 '12 at 01:54
  • Some Lenovo laptops have specific features which tp_smapi gives you access to. I don't know about other brands, but they probably have similar tools (I have a Dell laptop and I see that I have a `dell_laptop` and `dell_wmi` module, for example; I never explored it to see what it does) – Renan Sep 19 '12 at 02:17

6 Answers6

20

Newer Lenovo ThinkPads (such as my E540) are not compatible with tp_smapi-dkms. Fortunately I found that the TLP utility can use different modules -- such as the tp_smapi OR the thinkpad_acpi DKMS modules -- to communicate the thresholds to the battery. Other Lenovo laptops may communicate with the battery using the acpi_call kernel module.

Note: when kernel 5.17 is available to you, it will have a new kernel module called natacpi which eliminates the need for tp_smapi. Furthermore, recent versions of TLP support charging thresholds in a few additional manufacturers' hardware.

Nowadays TLP is available via standard Ubuntu or Debian repositories. (Though you may benefit from the latest version available using TLP website to install the packages.)

After installing TLP, set the battery charge thresholds using two lines in the configuration file /etc/default/tlp

START_CHARGE_THRESH_BAT0=65
STOP_CHARGE_THRESH_BAT0=80

This example tells TLP to set the battery thresholds to start charging at 65% and stop charging at 80%. I find that the thresholds persist correctly even when booting into a different OS that doesn't have TLP installed. (Though I presume if you booted into Windows or another OS that DOES have power management tools installed, that OS might overwrite the previously set charge thresholds.)

To TEMPORARILY bring the battery to a full charge, issue the following terminal command:

 $ sudo tlp fullcharge

The battery will then charge to its maximum capacity, and revert to the previous thresholds afterwards.

Note: If your laptop is not a "ThinkPad," TLP probably cannot set your battery charge levels. However, recent versions have added support for additional brands and models.

If your vendor supplies a power management utility for Windows, you can probably boot using some form of Windows to set the battery charge levels and then reboot into linux. In my experience, the battery charge threshold settings persist after system reboots.

Tommy Trussell
  • 360
  • 3
  • 7
  • This only works for ThinkPads, what about other models? – Akronix Nov 25 '18 at 18:20
  • @Akronix I believe TLP can be installed on several different kinds of laptop, and depending upon the hardware, firmware, and architecture, relies upon different libraries. I only recently became more aware of the different libraries because my relatively modern Lenovo uses TLP slightly differently than older ThinkPads. – Tommy Trussell Dec 03 '18 at 23:30
  • However, it does not work in my G-Series Lenovo – Akronix Jan 20 '19 at 12:27
  • @Akronix I had to look ... my ThinkPad is an E540. By following the menus at http://support.lenovo.com/ I determined that mine is known as an "Edge Series Thinkpad." I had to explore many sites before I got almost all of the hardware working as I wanted (I gave up on the fingerprint sensor, for example). – Tommy Trussell Jan 27 '19 at 21:46
  • Exactly, but your laptop is a ThinkPad. Mine is Lenovo but G series which are not part of the "Thinkpad" series and, as TLP website states clearly: "Please note: TLP runs on every laptop brand. Setting the battery charge thresholds is available for IBM/Lenovo ThinkPads only." – Akronix Jan 28 '19 at 22:55
  • @Akronix I know nothing about your system, but if it were me I would try it, in case there's some shared "blood" between your Lenovo model and a ThinkPad. TLP will suggest which of the two kernel modules apply: https://linrunner.de/en/tlp/docs/tlp-faq.html#kernmod – Tommy Trussell Jan 29 '19 at 03:05
  • I already tried to use the battery charge threshold in Lenovo G580 before I wrote my first comment and it didn't work. Anyway, thank you for your caring. – Akronix Jan 29 '19 at 15:01
  • @Akronix After doing a bit more reading I believe your best option to set the battery charge thresholds might be to boot into Windows and look for a Lenovo-supplied battery and power management utility. You might attempt to run that utility in linux using WINE but it's unlikely to run properly. – Tommy Trussell Jan 30 '19 at 00:08
  • I don't have Windows installed anymore, I could only try the Wine option then. – Akronix Jan 31 '19 at 11:01
  • 1
    @Akronix yeah, I have never booted Windows on mine. I probably still have the disks, but I've tried to stay "pure." Unfortunately Lenovo has apparently quietly quit supporting linux even on my model, even though I bought it BECAUSE it was "certified" for Ubuntu and Red Hat. – Tommy Trussell Jan 31 '19 at 15:12
  • Thanks for posting about the one-time command to trigger full charge, that's what I was looking for, couldn't find it anywhere. Unfortunately I now get `Error: ThinkPad battery features not available.`, but I'm still grateful! – NeilG Jun 16 '21 at 11:35
  • 1
    @NeilG it sounds like you don't have a compatible module installed. Since you don't say what model laptop you have, I'll warn you that very few laptops can use TLP's battery management features at all. Read all the answers here and on the TLP website, specifically https://linrunner.de/tlp/faq/battery.html – Tommy Trussell Jun 17 '21 at 13:55
  • @NeilG also check my answer again; I just updated two of the three links to the TLP information to reflect changes in the website – Tommy Trussell Jun 17 '21 at 14:09
  • Thanks @TommyTrussell, that's got to be it. I have a 2017 ThinkPad X1 Carbon. I see you are right `tlp-stat -b` reports `kernel module 'acpi_call' not installed)`. So I guess I could fix it, but the OS is so old and mangled installing is not so easy anymore. I need to upgrade or re-install the OS, but I'm now confident that will get this problem moving. Thanks. – NeilG Jun 18 '21 at 16:26
9

You need to install tp_smapi-dkms, just do

apt-get install tp_smapi-dkms

When finished, use lsmod | grep tp_smapi to check if module is loaded, to adjust the charge thresholds, do something like this

echo 40 > /sys/devices/platform/smapi/BAT0/start_charge_thresh
echo 60 > /sys/devices/platform/smapi/BAT0/stop_charge_thresh

Add these lines to /etc/rc.local to run them at boot.

This module works at least on X220.

daisy
  • 53,527
  • 78
  • 236
  • 383
  • For anybody getting permission denied even with sudo privileges, try `echo 60 | sudo tee /sys/devices/platform/smapi/BAT0/stop_charge_thresh`. – Andrey Kaipov Jan 21 '16 at 05:36
4

On my laptop (Yoga 260) I had to get acpi-call-dkms, which provides the acpi_call kernel module:

sudo apt install tlp acpi-call-dkms
sudo tlp setcharge 40 60 #set the start and stop thresholds to 40% and 60%

Output of sudo tlp stat -b:

--- TLP 1.1 --------------------------------------------

+++ ThinkPad Battery Features
tp-smapi   = inactive (unsupported hardware)
tpacpi-bat = active

+++ ThinkPad Battery Status: BAT0 (Main / Internal)
/sys/class/power_supply/BAT0/manufacturer                   = SMP
/sys/class/power_supply/BAT0/model_name                     = 00HW027
/sys/class/power_supply/BAT0/cycle_count                    = (not supported)
/sys/class/power_supply/BAT0/energy_full_design             =  44000 [mWh]
/sys/class/power_supply/BAT0/energy_full                    =  37970 [mWh]
/sys/class/power_supply/BAT0/energy_now                     =  18910 [mWh]
/sys/class/power_supply/BAT0/power_now                      =      0 [mW]
/sys/class/power_supply/BAT0/status                         = Unknown (threshold effective)

tpacpi-bat.BAT0.startThreshold                              =     40 [%]
tpacpi-bat.BAT0.stopThreshold                               =     60 [%]
tpacpi-bat.BAT0.forceDischarge                              =      0

Charge                                                      =   49.8 [%]
Capacity                                                    =   86.3 [%]
takhisis
  • 41
  • 1
  • Why 40 60? Does charging really stop at 60% ? Why is there `BAT0/status = Unknown` - seems strange. – hrvoj3e Jan 05 '20 at 13:23
  • @hrvoj3e I just chose 40 60 as an example for consistency with daisy's answer, but the reason you might want to stop charging at 60% is that it can extend the battery's life: https://superuser.com/questions/502328/how-does-limiting-a-laptop-batterys-full-charge-to-less-than-100-extend-its-ba The "Unknown" status is just what it says when it's neither charging nor discharging. I had discharged it down to 49.8% and then plugged the charger back in, and since it's still above the startThreshold it wouldn't start charging. – takhisis Jan 06 '20 at 22:54
  • Thanks for the info. My Yoga S740 won't work with acpi battery controls but I have setup a notifier in shell prompt as I spend a lot of time in terminal. Then, when I see that it's above/bellow a threshold I manually connect/disconnected the charger. – hrvoj3e Feb 16 '20 at 12:59
4

Sounds to me like your TLP settings were changed somehow and now you would like to change them back. The TLP ArchWiki is pretty good even if you don't use Arch: https://wiki.archlinux.org/index.php/TLP

To install TLP, open a terminal and enter:

sudo apt install tlp

There's also now a GUI for TLP which will make these settings easier to change. To install the UI tool we first need to add the repository:

sudo add-apt-repository ppa:linuxuprising/apps

Then install TLPUI via:

sudo apt install tlpui

Run TLPUI from the Applications menu and change the stop and start charge thresholds. These can be found at the very bottom under "ThinkPad Battery". Note that these options are available only for ThinkPads.

Change the START_CHARGE_THRESH_BAT0 to something reasonable like 75% and change the STOP_CHARGE_THRESH_BAT0 to something higher like 80 or 90% or even 100% if you like to fully charge your battery.

Reference: Improve Battery Life in Ubuntu 18.04 / Higher

AdminBee
  • 21,637
  • 21
  • 47
  • 71
  • Thanks AdminBee. How do you format in the grey like that? I couldn't find the appropriate format and the instructions didn't work for me. – Allan Smithee Jul 14 '20 at 07:18
0

For LG Gram laptops, there's a specific kernel driver, which seems to be active out of the box, at least in EndeavourOS, for particular features of LG Gram, see the kernel docs.

In particular, it also provides a "Battery care limit". Quoting from that page:

Writing 80/100 to /sys/devices/platform/lg-laptop/battery_care_limit sets the maximum capacity to charge the battery. Limiting the charge reduces battery capacity loss over time.

This value is reset to 100 when the kernel boots.

So, for example, you can manually set the limit to 80 with the following command:

echo '80' | sudo tee /sys/devices/platform/lg-laptop/battery_care_limit

I tested that on my LG Gram 16, and it seems to work perfectly: when plugging the AC with 85% charged, KDE states that it is charging, but the percentage stays at 85% (with "time to full" blocked at 1:41).

As stated in the quote above, this value will be reset when the kernel boots, so you may have to change the value again.

I guess that for a more automatic solution, tlp provides support for that as well.

AdminBee
  • 21,637
  • 21
  • 47
  • 71
0

On Thinkpad Yoga 370 with Fedora Linux 35 KDE the option is present in system settings by default enter image description here

Rafał Malinowski
  • 156
  • 1
  • 1
  • 7