For laptops that are usually plugged into mains power, it’s a good idea to either remove the battery (if it’s removable), or limit the maximum charge. This extends the battery life, as keeping a battery fully charged all the time is not good for it. Many Windows laptops come with power saving tools to configure this, but the means of doing so are not very standardised and I haven’t seen any graphical Linux tools to manage it. (Perhaps newer versions of Gnome have the option, but it's not visible in XFCE’s power management settings.) It's possible to use SystemD to automatically set this option at boot, using a similar method to my recent post on automatically switching off Intel Turbo Boost.
By default, after reboot the charging limit is set to 100, or full charge. You can override the value at runtime with the commands:
sudo -E bash echo 80 > /sys/devices/platform/lg-laptop/battery_care_limit echo 80 > /sys/class/power_supply/CMB0/charge_control_end_threshold
Note that LG laptops only seem to support values of 80 or 100. I’m not sure whether other manufacturers support other values such as 50.
The changes won't persist between boots. To make them persist, I used SystemD’s tmpfiles feature, which can be used a little like the deprecated
/etc/rc.local. Simply create the file
/etc/tmpfiles.d/batterycarelimit.conf and put in the following contents:
# Path Mode UID GID Age Argument w /sys/devices/platform/lg-laptop/battery_care_limit - - - - 80 w /sys/class/power_supply/CMB0/charge_control_end_threshold - - - - 80
If you’re planning to take the laptop somewhere without mains power and want to fully charge the laptop before you go, you can do it by running
echo 100 > /sys/devices/platform/lg-laptop/battery_care_limit && echo 100 > /sys/class/power_supply/CMB0/charge_control_threshold. This will set the charge limit back to 100 for the current boot only.
More recent kernels seem to have standardised the battery charge limit setting to
__NAME__ is the battery device name (
CMB0 on my laptop). This sys device seems to be common to different laptop models, rather than LG-specific. It’s not clear whether both settings are required, or only one is necessary. I've left both in for the time being. Comments welcome if anyone has any references to clear up which setting(s) work with which kernel version(s).