DEV Community

Brisbane Web Developer
Brisbane Web Developer

Posted on

Set your laptop into energy save mode with KDE Plasma manually

Summary

  • KDE Plasma often does not detect when I unplug my X1 Extreme Gen 2 (X1E2) recently. I don't know why.

  • And I noticed Docker eats up all the battery by the time I wake up if I did not keep it plugged before going to bed.

  • So I created a shell script to turn things off so that I can run it manually when I unplugged the AC adapter.

Script

  • The important part is the last bit. That bit seems to make KDE Plasma see the state of AC (So the actual cause would be upower.service, not KDE Plasma).

  • Your situation would be different from mine so you can just copy everything at first and then add/remove/amend the lines to suit you.

/usr/local/bin/savebattery
==========
#!/bin/bash

#
# Lower the brightness on monitor
#
echo
echo 2909 > /sys/class/backlight/intel_backlight/brightness
echo -n "Brightness: "; cat /sys/class/backlight/intel_backlight/brightness
echo

#
# Stop and disable the services for Docker
#
systemctl stop docker.service
systemctl disable docker.service
echo
systemctl --no-pager status docker.service | egrep "Loaded:|Active:" | tr -d ' '

systemctl stop docker.socket
systemctl disable docker.socket
echo
systemctl --no-pager status docker.socket | egrep "Loaded:|Active:" | tr -d ' '

echo

#
# Stop and disable the services for Avahi
# - The solution may be "aptitude purge avahi-daemon", but I am disabling it
#   in case I actually need this somehow
#
systemctl stop avahi-daemon.service
systemctl disable avahi-daemon.service
echo
systemctl --no-pager status avahi-daemon.service | egrep "Loaded:|Active:" | tr -d ' '

systemctl stop avahi-daemon.socket
systemctl disable avahi-daemon.socket
echo
systemctl --no-pager status avahi-daemon.socket | egrep "Loaded:|Active:" | tr -d ' '

echo

#
# Disable the network interfaces
#
ip link set docker0 down
ip address | egrep "docker0:"

interface=$(ip address | egrep ": br-" | sed -E 's/^[0-9]: ([^\s:]+).+/\1/')
ip link set $interface down
ip address | egrep ": br-"

echo

#
# Make sure KDE Plasma see AC state properly
#
systemctl restart upower.service
Enter fullscreen mode Exit fullscreen mode

Top comments (0)