How to set battery charge thresholds on Linux

Some notebooks firmware allow setting start and stop battery charge thresholds. This feature can be really useful to increase the battery lifespan: if we use the notebook attached to the AC most of the time, we may want to set a low charge values, to avoid charging and keeping the battery at its maximum capacity; if we are using the notebook on the go, instead, we probably want to set higher threshold values to maximize runtime hours.

In this tutorial we learn how to set battery charge thresholds on Linux: from the command line, and from the most used Desktop environments.

In this tutorial you will learn:

  • How to set battery charge thresholds from the command line
  • How to set battery charge thresholds from KDE Plasma desktop
  • How to set battery charge thresholds from GNOME desktop
how to set battery charge thresholds on linux
How to set battery charge thresholds on Linux – Original image by WangXiNa on Freepik
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Distribution agnostic
Software None
Other Root privileges
Conventions # – requires given linux-commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux-commands to be executed as a regular non-privileged user

Optimizing for battery lifespan vs for runtime

Notebooks with support for the battery charge thresholds functionality, typically come with a setup which allows achieving a full battery charge by default. We may want to change default values depending on our machine usage. If we use our notebook connected to its power adapter most of the time, for example, we may want to avoid keeping the battery charged at its full potential, in order to maximize its lifespan. For this use case, a good idea would be to keep the charge-start threshold around 40% (the battery will start charging only when the charge level drops under that value), and set the charge-stop threshold around 50%.



If, on the other hand, we typically use the notebook on the go, we probably want to maximize its runtime on battery, therefore we may want to set the start threshold around 80-85%, and the stop threshold around 90-95 or even 100% (it is usually a good idea to avoid charging the battery completely).

Setting battery charge thresholds from the command line

The universal, desktop-independent way to set battery charge thresholds on notebooks that support this feature, is by directly writing the appropriate value to files exposed as an interface by the Linux kernel under the /sys pseudo-filesystem. Supposing our battery to be named BAT0, the files we should write charge thresholds values would be: /sys/class/power_supply/BAT0/charge_start_threshold: and /sys/class/power_supply/BAT0/charge_stop_threshold. As the files name suggest, they control, respectively, the start and stop threshold values. The values we write to these files, are persistent and preserved even if we boot into another operating system.



Suppose we want to set a conservative range: we want the battery to start charging when the charge level drops under 40%, and stop when it reaches 50%. We would run:

$ echo 40 | sudo tee /sys/class/power_supply/BAT0/charge_start_threshold
$ echo 50 | sudo tee /sys/class/power_supply/BAT0/charge_stop_threshold

Some notebooks come with more than one battery. Since the Linux kernel names batteries progressively, a second one would be named “BAT1”. To set the same thresholds on all available batteries at once, we would shell filename expansion (“globbing”), and run:

$ echo 40 | sudo tee /sys/class/power_supply/BAT*/charge_start_threshold
$ echo 50 | sudo tee /sys/class/power_supply/BAT*/charge_stop_threshold

Setting battery charge thresholds from KDE Plasma desktop

KDE plasma is a highly customizable desktop environment which includes a native graphical interface to change battery charge thresholds on notebooks whose firmware support this feature. All we have to do to navigate to “Power Management -> Advanced Power Settings” in KDE system settings. If the notebook firmware exposes the functionality, we should find a widget to set batteries thresholds:

setting battery charge thresholds from kde plasma desktop
Setting battery charge thresholds from KDE Plasma desktop

Once we entered the values we want to use, we simply click on the “Apply” button, to make them effective.

Setting battery charge thresholds from GNOME

Being GNOME a minimalistic and simplicity-oriented desktop environment, it doesn’t expose advanced settings to the user by default, and doesn’t provide a native graphical tool to set battery charge thresholds. GNOME basic functionalities, however, can be expanded via the “extensions” system. GNOME shell extensions are hosted on the GNOME shell extensions website. In this case, we want to look for the one called: “Thinkpad Battery Threshold“. To install extensions directly from the website, we must make sure we installed the extension for the browser we are using, as suggested from the message on the site:

thinkpad battery threshold extension page
In order to install extensions from the GNOME extensions website, we must install the dedicated browser extension first



Once the browser extension is installed, we can download, install and activate/deactivate the extension by clicking on the On/Off switch:

installing the "thinkpad Battery threshold" extension
Installing the “Thinkpad Battery Threshold” extension

Once the “Thinkpad Battery Threshold” extension is active, its icon should appear in the GNOME shell top panel. We can access its settings and customize battery charge thresholds by clicking on the “Thresholds” button, and then on “Threshold settings”:

opening the extension settings interface
Opening the extension settings interface



In the extension settings tool, we just click on the “Thresholds” tab. From there, we can change thresholds for each available battery individually (unfortunately, there is no option to set the same thresholds for all batteries at once, at the moment). To apply the changes, we click on the “Apply” button, and we provide our password for privilege escalation:

thinkpad battery threshold extension settings
“Thinkpad Battery Threshold” extension settings

Closing thoughts

In this tutorial we learned how to set battery charging thresholds for notebooks which support this functionality on Linux. We saw how to set charging thresholds from the command line, and from the most commonly used desktop environments.



Comments and Discussions
Linux Forum