Linux battery charge limit

How to adjust charging thresholds of laptop battery?

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?

Try modprobe tp_smapi as root, and then see if the files under /sys/devices/platform/smapi are there.

@Renan: Is tp_smapi only for Lenovo laptops? Are battery charging management modules different for different brands of laptops?

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)

6 Answers 6

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:

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

Читайте также:  Dota 2 play on linux

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.

Источник

How To Limit Battery Charging (Set A Charge Threshold) For ASUS Laptops On Linux

limit asus battery charging linux

Battery lifespan is affected by age, high temperatures, the number of charge cycles, and the amount of time at full charge. A battery charge threshold reduces the amount of time at full charge (100%), and thus improves battery health / life.

ASUS laptops support setting a charge threshold starting with Linux 5.4. The kernel WMI method to set the charge threshold does not provide a way to specify a battery, assuming it’s the first battery ( BAT0 ). However, for some newer ASUS laptops, the primary battery is not called BAT0 , but BATT (e.g. Zenbook UM431DA) and BAT1 (e.g. ASUS TUF Gaming FX706II). [Edit] And There’s also BATC.

So while ASUS laptops support limiting battery charging starting with Linux 5.4, that’s only for laptops having BAT0 . For ASUS laptops using BATT as the primary battery name, you’ll need kernel 5.7, while for BAT1 you’ll need the 5.8 kernel (in the instructions below you’ll see exactly how to check the battery name). [Edit] For ASUS laptops using BATC battery name, you’ll need to use Linux 5.9 or newer.

Also, not all ASUS laptops support setting a battery charge threshold so depending on your ASUS laptop model, this may or may not work for you; there’s no list of supported devices that I could find.

It’s important to mention that the kernel WMI method of setting the battery charge threshold for ASUS notebooks can only set the stop value ( charge_control_end_threshold ) (it can’t also set the start threshold). Also, with AC connected, if the battery level is higher than the charge stop threshold, it will not be discharged to the stop threshold.

And another note. With my ASUS ZenBook 14 UX433FAC running Ubuntu 20.04 with GNOME Shell, when limiting battery charging while the battery level is equal or greater than the charge threshold, and then connect the laptop to AC, the battery indicator from the top panel changes from the time remaining until the battery discharges to the time remaining until the battery is charged. This happens even though the battery is not charging. After a while (so this is not instant when you connect your laptop to AC), the battery indicator changes to say «Not charging», as it should.

Besides ASUS, some Lenovo and Huawei (with the latter getting support with Linux 5.5) laptops also have support for limiting battery charging. But since I only own an ASUS laptop and I can’t test it on other devices, this guide is for ASUS only. Lenovo has had support for this for quite a while, and TLP has support for setting this built-in (only for IBM/Lenovo ThinkPads). As a side note, here’s a GUI for TLP to easily configure it, in case you’re not using it already.

Читайте также:  Linux apt get update all

How to set a battery charge stop threshold for ASUS laptops on Linux

1. Find out your ASUS’ laptop battery name.

Let’s start by figuring out the battery name for your ASUS laptop. This can be done by using the following command:

This command should output something like this:

In this example (from my ASUS notebook), the name of the battery is BAT0 , but like I mentioned above, for you it may also be BAT1 or BATT , these being the only supported battery names by the kernel for ASUS laptops.

2. Create a systemd service to set the battery charge stop threshold on boot.

Before creating the systemd service, check if your laptop actually has charge_control_end_threshold in /sys/class/power_supply/BAT* (without it, this won’t work):

ls /sys/class/power_supply/BAT*/charge_control_end_threshold

If this command returns the path to charge_control_end_threshold , then your ASUS notebook supports limiting battery charging. If the command returns an error, saying there’s no such file or directory, then your laptop doesn’t support setting a charge threshold.

If your ASUS laptop has this file, we can continue. Create a file which we’ll call battery-charge-threshold.service in /etc/systemd/system .

You can open this file with your default console text editor using:

sudo editor /etc/systemd/system/battery-charge-threshold.service

Or use Gedit or whatever graphical editor you want to use (e.g. for Gedit to open this file as root: gedit admin:///etc/systemd/system/battery-charge-threshold.service )

In this file you’ll need to paste the following:

[Unit]
Description=Set the battery charge threshold
After=multi-user.target

StartLimitBurst=0

[Service]
Type=oneshot
Restart=on-failure

ExecStart=/bin/bash -c 'echo CHARGE_STOP_THRESHOLD > /sys/class/power_supply/BATTERY_NAME/charge_control_end_threshold'

[Install]
WantedBy=multi-user.target

Here, change BATTERY_NAME with the name of the battery ( BAT0 , BAT1 or BATT ), and CHARGE_STOP_THRESHOLD with the battery charge stop threshold you want to use (ranging between 1 and 100). Note that I’ve read that one user couldn’t set the charge threshold to any value, but only to 60, 80 and 100.

From what I’ve read, for best battery lifespan when the laptop is connected to AC most of the time, set the battery charge stop threshold at around 50 or 60. If the battery is used somewhat frequently, set the battery charge stop threshold at about 90.

3. Enable and start the battery-charge-threshold systemd service.

Now let’s enable and start the newly created battery-charge-threshold systemd service:

sudo systemctl enable battery-charge-threshold.service

sudo systemctl start battery-charge-threshold.service

With systemd 220, it’s possible to enable and start a service directly using systemctl enable —now , but I prefer to use 2 commands in case some readers use an older systemd version.

Читайте также:  Linux ssh authentication failed

If you want to change the battery charge stop threshold level, you’ll need to edit the /etc/systemd/system/battery-charge-threshold.service file, and change the number from the ExecStart line (after echo ) to the new value you want to use, then reload systemd (because the file contents have changed) and restart the systemd service using the following commands:

sudo systemctl daemon-reload

sudo systemctl restart battery-charge-threshold.service

4. Verify that the battery charge stop threshold is working.

If your ASUS laptop supports it, the battery charging limit should now be set to the value you’ve used in step 2.

You can check this by charging your laptop to the threshold set in battery-charge-threshold.service , and then use this command:

cat /sys/class/power_supply/BATTERY_NAME/status

Replace BATTERY_NAME with the name of the battery, as explained under step 1.

If the battery charge stop threshold is working, the command should show the following output:

If it says «Discharging», make sure your ASUS laptop is actually on AC power, and not running on battery. However, if it says «Charging», well. then your laptop is charging past the charge stop threshold, so this is not working for you, either because your ASUS laptop doesn’t support it (which is weird if you have charge_control_end_threshold as mentioned in step 2), you’re using a Linux version that’s too old for limiting battery charging on your ASUS notebook, or because of human error 😁️.

Extra: In case you don’t use systemd, you can also do this by using cron, by running sudo crontab -e and then pasting the following line (this is a single line, triple-click the line to select the whole line), although this is not reliable in all cases from what I’ve read (I’m not sure why):

@reboot echo CHARGE_STOP_THRESHOLD > /sys/class/power_supply/BATTERY_NAME/charge_control_end_threshold

Replacing CHARGE_STOP_THRESHOLD with the battery charge stop threshold you want to use and BATTERY_NAME with the battery name as seen in step 1.

Why use a systemd service or a cron job? According to u/esrevartb, from whom I’ve adapted these instructions, «it seems the udev rule isn’t working either because the battery sysfs path isn’t yet initialized when the rule gets applied, or because this specific charge_control_end_threshold attribute cannot be modified this way«.

[[Edit] To easily set a charge threshold for ASUS laptops (automatic setup of the systemd service and the ability to change the charge threshold using a command), as well as check the current charging threshold, see bat.

[[Edit 2]] TLP 1.4.0 has also added support for limiting battery charging on ASUS laptops.

Источник

Оцените статью
Adblock
detector