Prolong Laptop Battery Life in Linux by Limiting Charging Levels

Prolong your laptop's battery life in long run by limiting the charging to 80%.
Warp Terminal

In case you didn't know it already, regularly charging the battery to 100% or fully discharging it puts your battery at stress and may lead to poor battery life in long run.

I am not making claims on my own. This is what the experts and even the computer manufactures tell you.

As you can see in the official Lenovo video above, continuous full charging and discharging accelerate the deterioration of battery health. They also tell you that the optimum battery charging range is 20-80%.

Optimum Battery Charge

Although Lenovo also tells you that battery these days are made to last longer than your computer. Not sure what's their idea of an average computer lifespan, I would prefer to keep the battery life healthy for a longer period and thus extract a good performance from my laptop as long as it lives.

I mean, it's all about following the best practices, right?

Now, you could manually plug and unplug the power cord but it won't work if you are connected to a docking station or use a modern monitor to power your laptop.

What can you do in that case? Well, to control the battery charging on Linux, you have a few options:

  • KDE Plasma has this as an in-built feature. That's why KDE is ❀️
  • GNOME has extensions for this. Typical GNOME thing.
  • There are command line tools to limit battery charging levels. Typical Linux thing 😍
🚧
Please note that not all devices support this feature. In some cases, you may also need to change power settings at the BIOS level. In simpler words, things may or may not work easily, depending on the laptop you are using.

Let's see them one by one.

πŸ“‹
Please verify which desktop environment you are using and then follow the appropriate method.

Limit laptop battery charging in KDE

If you are using KDE Plasma desktop environment, all you have to do is to open the Settings app and go to Power Management. In the Advanced Power Settings, you'll see the battery levels settings.

I like that KDE informs the users about reduced battery life due to overcharging. It even sets the charging levels at 50-90% by default.

Setting Battery charging limit in Linux distros with KDE Plasma

Of course, you can change the limit to something like 20-80. Although, I am not a fan of the lower 20% limit and I prefer 40-80% instead.

Set battery charging limit in KDE Plasma

That's KDE for you. Always caring for its kusers.

πŸ’‘
It is possible that the battery charging control feature may need to be enabled from the BIOS. Look for it under power management settings in BIOS.

Set battery charging limit in GNOME

Like most other things, GNOME users can achieve this by using a GNOME extension.

There is an extension called Battery Health Charging that is compatible with several laptop manufacturers, from Asus to LG and from Dell to Lenovo.

Still, not all models from these brands will be supported. So please refer to the compatibility info on its GitHub repo.

I have a detailed tutorial on using GNOME Extensions, so I won't repeat the steps.

Use the Extension Manager tool to install the Battery Health Charging extension.

As soon as it is installed, you should see a notification about enabling Polkit so that the extension can run with escalated privilege.

Escalated privilge for battery charging threshold on Linux

Once that is enabled, you can find the extension in the system tray. It has three modes:

  • Full capacity mode
  • Balanced mode
  • Maximum lifespan mode

All three modes can accept values between certain limits. You can set that from extension settings. And you can choose which mode you want to use from the system tray.

Configuring Battery Health Threshold extension on GNOME
Click to enlarge

There are some additional settings and you can explore them if you want.

Using command line to set battery charging thresholds

🚧
You must have basic knowledge of the Linux command line. That's because there are many moving parts and variables for this part.

Here's the thing. For most laptops, there should be file(s) to control battery charging in /sys/class/power_supply/BAT0/ directory but the file names are not standard. It could be charge_control_end_threshold or charge_stop_threshold or something similar.

Also, you may have more than one battery. For most laptops, it will be BAT0 that is the main battery but you need to make sure of that.

Install the upower CLI tool on your distribution and then use this command:

upower --enumerate

It will show all the power devices present on the system:

/org/freedesktop/UPower/devices/battery_BAT0
/org/freedesktop/UPower/devices/line_power_AC0
/org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o001
/org/freedesktop/UPower/devices/line_power_ucsi_source_psy_USBC000o002
/org/freedesktop/UPower/devices/headphones_dev_BC_87_FA_23_77_B2
/org/freedesktop/UPower/devices/DisplayDevice

You can find the battery name here.

The next step is to look for the related file in /sys/class/power_supply/BAT0/ directory.

If you find a file starting with charge, note down its name and then add the threshold value to it.

In my case, it is /sys/class/power_supply/BAT0/charge_control_end_threshold, so I set an upper threshold of 80 in this way:

echo 80 | sudo tee /sys/class/power_supply/BAT0/charge_control_end_threshold

You could also use nano editor to edit the file but using tee command is quicker here.

The problem is that these settings won't persist after reboot. You'll need to add some sort of mechanism so that it runs on each boot.

If you are using systemd, you can create a systemd service.

Create a new file /etc/systemd/system/battery-threshold.service:

sudo nano /etc/systemd/system/battery-threshold.service

And add the following lines to it if you are setting the threshold at 80 for BAT0:

[Unit]
Description=Set battery charging threshold
After=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

[Service]
Type=oneshot
ExecStart=/bin/bash -c 'echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold'

[Install]
WantedBy=multi-user.target suspend.target hibernate.target hybrid-sleep.target suspend-then-hibernate.target

Save the file and enable the service:

sudo systemctl enable battery-threshold.service

It should work now for setting battery charging limit automatically in each session. Thanks to this GitHub repo.

πŸ’‘
You can also use tlp for this purpose by editing the /etc/tlp.conf file.

Conclusion

See, if you were getting 10 hours of average battery life on a new laptop, it is normal to expect it to be around 7-8 hours after two years. But if you leave it at full charge all the time, it may come down to 6 hours instead of 7-8 hours. The numbers are for example purpose.

This 20-80% range is what the industry recommends these days. On my Samsung Galaxy smartphone, there is a "Battery protection" setting to stop charging the device after 80% of the charge.

I wish a healthy battery life for your laptop πŸ’»

About the author
Abhishek Prakash

Abhishek Prakash

Created It's FOSS 11 years ago to share my Linux adventures. Have a Master's degree in Engineering and years of IT industry experience. Huge fan of Agatha Christie detective mysteries πŸ•΅οΈβ€β™‚οΈ

Become a Better Linux User

With the FOSS Weekly Newsletter, you learn useful Linux tips, discover applications, explore new distros and stay updated with the latest from Linux world

itsfoss happy penguin

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to It's FOSS.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.