One thing I’ve been impressed with since switching to Gnome on my laptop is battery life. It was not bad before I got around 10 hours from 80% to 20%.
I used TLP before, you can see my tweaks here: ThinkPad T14s Gen 3 AMD Linux User Review + Tweaks
For Gnome, I noticed that it had built in power management modes but when unplugging the laptop it stayed in “balanced” and if you manually switched it to “Power saver” when you
back in, it didn’t switch back to “Balanced” (or Performance for that matter). It would stay in “Power Saver” which does a good job at throttling the CPU/cooling, annoying when you don’t need it.
I’m sure Gnome devs avoided this because of potential bugs or compatibility with different hardware. They are generally very conservative with introducing features. This also makes Gnome very stable.
I could not find a Gnome extension which could solve this, so I wrote a small script to detect the change from AC to unplugged/battery:
└─$ cat /usr/local/bin/power.sh
#!/bin/bash
# Initialize the last known state to prevent repeat actions.
LAST_LEVEL=""
dbus-monitor --system "type='signal',path='/org/freedesktop/UPower/devices/battery_BAT0',member='PropertiesChanged'" | while read LINE; do
echo ${LINE} | grep battery_BAT0 | grep -q PropertiesChanged
if [ $? -eq 0 ]; then
BATT_STAT=$(dbus-send --print-reply=literal --system --dest=org.freedesktop.UPower /org/freedesktop/UPower/devices/battery_BAT0 org.freedesktop.DBus.Properties.Get string:org.freedesktop.UPower.Device string:State | awk '{ print $3; }')
# Determine the desired power management mode
if [ $BATT_STAT -eq 1 ] || [ $BATT_STAT -eq 4 ]; then
LEVEL="balanced" # Use balanced when on AC
elif [ $BATT_STAT -eq 5 ]; then
LEVEL="balanced" # Use balanced for other states if needed
else
LEVEL="power-saver" # Use power-saver when on battery
fi
# Apply changes only if the level has changed
if [ "$LEVEL" != "$LAST_LEVEL" ]; then
echo "Changing power level to ${LEVEL}"
gdbus call --system --dest net.hadess.PowerProfiles --object-path /net/hadess/PowerProfiles --method org.freedesktop.DBus.Properties.Set 'net.hadess.PowerProfiles' 'ActiveProfile' "<'${LEVEL}'>" > /dev/null
[[ $? -ne 0 ]] && echo "Could not change power level to ${LEVEL}!"
LAST_LEVEL="$LEVEL" # Update the last known state
fi
fi
done
So now when I unplug the laptop automatically goes into Power Saver mode, then reverts when plugged in:
The result, now I’m getting around 12 hours between that same range:
I still kept the tweak of charging to max of 80%. Also, it won’t charge unless below 50%, this helps reduce the amount of charging to non-charging back and forth. For example, if I’m at 55% and plugged in, it just remains at 55%. This can be manually bypassed with a command, but generally, I’m responsible with charging so when I have something coming up I always charge to 80% the night before.
Also see: