Linux: saving laptop’s battery energy

By | 11/19/2022
 

This time it became interesting to me – is it possible to somehow save the charge of the laptop battery? Not to say that it discharges quickly, it is enough for 5-6 hours of work, but it will not be too much, especially with the current power outages in Ukraine.

Found several utilities, and will write about them today.

Upower

The first one – upower:

[simterm]

$ sudo pacman -S upower

[/simterm]

First, you can call with an option --monitor-detail – will display information about the battery status in real-time:

[simterm]

$ $ sudo upower --monitor-detail
Monitoring activity from the power daemon. Press Ctrl+C to cancel.
[20:42:20.071]  device changed:     /org/freedesktop/UPower/devices/battery_BAT0
  native-path:          BAT0
  vendor:               SMP
  model:                LNV-5B10W13895
  serial:               2056
  power supply:         yes
  updated:              Fri Nov 18 20:42:20 2022 (0 seconds ago)
  has history:          yes
  has statistics:       yes
  battery
    present:             yes
    rechargeable:        yes
    state:               charging
    warning-level:       none
    energy:              36.7 Wh
    energy-empty:        0 Wh
    energy-full:         0 Wh
    energy-full-design:  0 Wh
    energy-rate:         15.538 W
    voltage:             12.391 V
    charge-cycles:       N/A
    time to full:        22.7 minutes
    percentage:          86%
    technology:          lithium-polymer
    icon-name:          'battery-full-charging-symbolic'
  History (charge):
    1668796940  86.000  charging
    1668796850  85.000  charging
  History (rate):
    1668796940  15.538  charging
    1668796910  15.784  charging
    1668796880  16.006  charging
    1668796850  16.253  charging

[/simterm]

Here, we can see the model of the laptop battery – LNV-5B10W13895, and its status – watt-hours (36.7 Wh) being used, and how much it consumes now (15.538 W), and at what power – 12.391 V.

You can calculate in ampere-hours:

[simterm]

>>> 37.31/12.3
3.03

[/simterm]

That is, there is now 3033 mAh of charge in the battery.

Also, we saw the battery device itself – /org/freedesktop/UPower/devices/battery_BAT0.

Get information about it without monitoring, only once – an option -i with the device – sudo upower -i /org/freedesktop/UPower/devices/battery_BAT0.

ACPI

Another similar utility – acpi, but also can display the temperature (and not only, see About ACPI):

[simterm]

$ sudo pacman -S acpi

[/simterm]

Get information about the battery:

[simterm]

$ acpi -i
Battery 0: Charging, 91%, 00:21:40 until charged
Battery 0: design capacity 3649 mAh, last full capacity 3431 mAh = 94%

[/simterm]

“design capacity 3649 mAh” – almost as calculated above, only there they took the current charge, which is now somewhere around 94% of the design capacity.

Batstat

The third useful thing – batstat. Simple, but it can be useful.

Download the repository, build it with make:

[simterm]

$ git clone https://github.com/Juve45/batstat.git
$ cd batstat
$ make
$ chmod +x batstat
$ sudo mv batstat /usr/local/bin/

[/simterm]

Run it:

Powertop

Powertop is able not only to display information about the battery, but also, firstly, to display information about processes that consume energy, and secondly, it can perform settings to save charge.

[simterm]

$ sudo pacman -S powertop

[/simterm]

Run under the root user

[simterm]

$ sudo powertop

[/simterm]

The Tunables tab displays information on settings that can optimize energy consumption.

Select a desired item, hit Enter – and the option switches:

Also, can produce an HTML report:

[simterm]

$ sudo powertop --html=powerreport.html

[/simterm]

And its result:

You can add a systemd service, which will perform automatic tuning at system startup.

Create a new file /etc/systemd/system/powertop.service:

[Unit]
Description=Powertop tunings

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/powertop --auto-tune

[Install]
WantedBy=multi-user.target

Activate it:

[simterm]

$ sudo systemctl start powertop.service
$ sudo systemctl enable powertop.service

[/simterm]

TLP

It’s just a monster. It is better to read more information here>>> and here>>>, and now about the main features.

Install:

[simterm]

$ sudo pacman -S tlp
$ sudo pacman -S tlp-rdw

[/simterm]

There is a graphical interface:

[simterm]

$ yay -S tlpui
$ sudo tlpui

[/simterm]

Under the hood, it already has all the settings that it does powertop, so the powertop.service better to disable.

Start the service:

[simterm]

$ sudo systemctl enable tlp.service

[/simterm]

And block (mask) services that may interfere tlp:

[simterm]

$ sudo systemctl mask systemd-rfkill.service
$ sudo systemctl mask systemd-rfkill.socket

[/simterm]

Configuration file – /etc/tlp.conf, and you can place your own configs under the /etc/tlp.d/ directory.

Вивести параметри, що є зараз:

[simterm]

$ sudo tlp-stat
--- TLP 1.5.0 --------------------------------------------

+++ Configured Settings:
defaults.conf L0004: TLP_ENABLE="1"
defaults.conf L0005: TLP_WARN_LEVEL="3"
defaults.conf L0006: TLP_PERSISTENT_DEFAULT="0"
defaults.conf L0007: DISK_IDLE_SECS_ON_AC="0"
...

[/simterm]

Brings up a bunch of hardware and optimization options, all customizable.

General advice

And let’s not forget about the most basic things.

First of all, this is, of course, the brightness of the screen – reduce it with the Fn +/-brightness buttons, or through a file, I have it in the /sys/class/backlight/amdgpu_bl0/brightness:

[simterm]

$ sudo bash -c  'echo -n 25 > /sys/class/backlight/amdgpu_bl0/brightness'

[/simterm]

Also, you can turn off unnecessary USB devices such as mouse/keyboard/external drive and Bluetooth and/or WiFi if connected by cable.