Limiting battery wear on laptops used mostly on AC power

Original forum link
https://forum.qubes-os.org/t/21683
Original poster
Barto
Created at
2023-10-24 19:51:22
Posts count
22
Likes count
14

I used this with good results on Dell and (s)Thinkpad laptops, used mostly on mains power: limiting the battery charge to something lower than 80% will radically reduce the battery wear. You can change the threshold to "100" and run the script manually if you need a full charge "for the road".

Run sudo vi /etc/cron.daily/set_batt.sh in dom0 and paste the following:

#!/bin/bash
#
# Run daily from /etc/cron.daily (cron and/or anacron).
# Output directed to /dev/null in case you don't have the second battery.
#
CHARGE_START=54
CHARGE_END=60
(
for bnum in {0..1} ; do
    sleep "${bnum}"   # optimisation! :-)
    echo "${CHARGE_START}" > /sys/class/power_supply/BAT"${bnum}"/charge_control_start_threshold
    sleep 1
    echo "${CHARGE_END}" > /sys/class/power_supply/BAT"${bnum}"/charge_control_end_threshold
done
) >/dev/null 2>&1
#
The 1s delay is crucial! I had laptops crash without it.

You can check the current thresholds running, in dom0: cat /sys/class/power_supply/BAT*/charge_st*

Lenovo and Dell both recommend to keep the charge between 50% and 60% for laptops rarely used on battery, and 75%-85% for laptops used on battery 1-2 times per week. Just edit the variables.

Enjoy!