Prolong Laptop Battery Life in Linux by Limiting Charging Levels

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%.

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 😍
Let’s see them one by one.
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.

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.

That’s KDE for you. Always caring for its kusers.
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 ThinkPad Battery Threshold for this purpose. Although it mentions ThinkPad everywhere, you don’t need to own a Lenovo ThinkPad to use it.
From what I see, the command it runs should work for most, if not all, laptops from different manufacturers.
I have a detailed tutorial on using GNOME Extensions, so I won’t repeat the steps.
Use the Extension Manager tool to install ThinkPad Battery Threshold extension.
Once the extension is enabled, you can find it in the system tray. On the first run, it shows red exclamation mark because it is not enabled yet.

If you click on the Threshold settings, you will be presented with configuration options.

Once you have set the desired values, click on apply. Next, you’ll have to click Enable thresholds. When you hit that, it will ask for your password.
At this screen, you can have a partial hint about the command it is going to run it.

Using command line to set battery charging thresholds
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.
/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 💻