GNOME is probably the most used desktop environment on Linux; its latest iteration (codename “Bengaluru”), ships with many performance improvements and some new features, as the ability to limit the battery charge straight from the “control center”, in order to preserve its health and increase its lifespan. By default, when this feature is active, a battery will start charging only when under 75% of its capacity, and will stop charging when it reaches 80%. In this tutorial, we learn how to replace those values with custom ones.
In This Tutorial, You Will Learn:
- How to set custom battery charging threshold values for GNOME “preserve battery” feature

Software Requirements and Linux Command Line Conventions
| Category | Requirements, Conventions or Software Version Used |
|---|---|
| System | Distribution-agnostic |
| Software | GNOME >= 48 |
| Other | Root permissions |
| Conventions | # – requires given linux-commands to be executed with root privileges either directly as a root user or by using sudo$ – requires given linux-commands to be executed as a regular non-privileged user |
Introduction
We already talked about how to set battery charge thresholds on Linux; in that article, we discussed how to limit a battery charge in order to increase its lifespan, either from the command line, from the KDE Plasma desktop environment, and from GNOME, using a third party extension. All the methods we explored in the tutorial, set threshold values by writing directly to the appropriate files under the /sys pseudo-file system: this is a “low level” method which requires no dependencies.
The latest version of GNOME implemented a “battery preserving” switch natively, which, instead, sets battery charging limits using methods provided by UPower, over D-Bus. On systems which supports this feature, when the switch is enabled, a battery will start charging when its charge drops under 75% of its capacity, and will stop when it reaches 80%. These values cannot be changed from settings app; we can, however, use custom values by creating a dedicated hwdb file. Let’s see how.
What is hwdb?
Hwdb is a binary database used to store a series of key-value pairs associated to devices; it is primarily queried by Udev, the userspace system which allows administrators to associate actions to events related to hardware devices generated by the Linux kernel. Keys in the hwdb database, are specified in the “modalias” format, which is a format use to represent information exposed by the Linux kernel in string form.
Hwdb files provided by the system are stored under
/usr/lib/udev/hwdb.d directory, while the administrator can provide custom files under /etc/udev/hwdb.d. All hwdb files are processed in lexical order, independently of the directory they are stored in; if a file under /etc/udev/hwdb.d has the same name as one under /usr/lib/udev/hwdb.d, it replaces it completely.
What is UPower?
UPower is a system service which retrieves information about power sources available on the system, and exposes them over the D-Bus “system” message bus. Since version 1.90, on supported systems, UPower supports limiting battery charge. When the package is installed, it provides a hwdb file, /usr/lib/udev/hwdb.d/60-upower-battery.hwdb, in which the “start” and “stop” threshold values are defined, for all batteries. The file contains the following lines:
battery:*:*:dmi:*
CHARGE_LIMIT=75,80
Activating the “battery-preserving” threshold from GNOME control center
The recently released GNOME 48, provides a convenient way to enable the “battery-preserving” threshold supported by UPower, straight from the “power” section of the control center:

This feature is very handy, but what if we want to change the “battery preserving” threshold values to something other than the defaults? I, for, instance, run my notebook on AC most of the time, and I like to keep the battery charge between 40% and 50%, as suggested on by Lenovo:
For maximum lifespan when rarely using the battery, set Custom charge thresholds to start charging at 40% capacity and stop at 50%
To use custom threshold values, all we have to do, is to create a new hwdb file.
Specifying custom threshold values
We create a custom hwdb file under /etc/udev/hwdb.d directory. We can either decide to use a name which is lexically sorted after the original file, or, replace it completely. For the sake of this tutorial, we will adopt the former solution, and create the /etc/udev/hwdb.d/61-battery-local.hwdb file, with the following content:
battery:*:*:dmi:*
CHARGE_LIMIT=40,50
Once we save the file, to load the new rule, we must update the hwdb binary database. We can do this, by using systemd-hwdb:
$ sudo systemd-hwdb update
We also need to use udevadm to trigger kernel events:
$ sudo udevadm trigger -v
Finally, we want to restart the upower service:
$ sudo systemctl daemon-reload && sudo systemctl restart upower
Now, when we activate the battery-preserving threshold from the gnome control center, our custom threshold values should be applied. To verify it, we can query the /sys pseudo filesystem:
$ cat /sys/class/power_supply/BAT0/charge_{start,stop}_threshold
The command above prints the start and stop values currently enabled:
40
50
Bonus: activating the threshold using dbus-send
When we activate or deactivate the battery-preserving threshold from GNOME control center, under the hood, the org.freedesktop.UPower.Device.EnableChargeThreshold method, exposed over D-bus is used. We can call this method directly from the command line, using, a tool like dbus-send. The method accepts a boolean value, which reflects the threshold status. To activate the threshold for the first battery (BAT0), for example, we would run:
$ dbus-send --print-reply --system --dest=org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.UPower.Device.EnableChargeThreshold boolean:true
We invoke the utility with the
--print-reply option, so it blocks and waits for a response to the message sent. We also use the --system option, since the method is exposed over the “system” message bus. With --dest, we specify the name of the connection to receive the message, then, we pass the object path (/org/freedesktop/UPower/devices/battery_BAT0), the method we want to call (org.freedesktop.UPower.Device.EnableChargeThreshold), and the argument we want to pass to it (boolean true, in this case).
Conclusions
In this tutorial, we learned how the preserve-battery feature, introduced in the latest version of GNOME, is implemented under the hood. By default, when this feature is activated, a battery stops charging when it reaches 80% of its capacity, and starts charging again when it drops under 75%. We saw how to replace those values with our own, by creating a dedicated hwdb file.