How tohealthy your Laptop battery

Mark Pearson (Lenovo) : “For battery charging thresholds I recently dug into that a bit and got the following guidance from the battery team:
– If you often discharge your battery to near eempty (< 20%) then start charging at 95% and stop at 100%
– If you frequently use the battery but don’t fully discharge. Usage between 50% and 100% then start charging at 75% and stop at 80%
– If you always use an AC adapter and rarely use battery start charging at 45% and stop at 50%” (refer to https://pointieststick.com/2020/06/08/lenovo-thinkpad-x1-yoga-impressions-bugs-workaro…ut-the-future/)

I use the third case, but a presupposition will be by Mark Pearson, that 2 thresholds will be used to start charging at 45% and stop at 50%.
My system a Vivibook only does support one threshold :

Charging stops when the battery level reaches or exceeds this threshold.

STOP_CHARGE_THRESH_BAT0=50

and not :

Charging starts once the battery level is below this threshold.

START_CHARGE_THRESH_BAT0=45

Also it must be known, if the battery is not in use (AC adapter always plugged), the battery itself will be discharged by “Self-discharging”
(refer to What is the self-discharge rate of a lithium-ion battery? | EL-CELL ).

Furthermore I did install tlp Vers. 1.9 to get /etc/tlp.conf where all values can be set by predefined Constants (e.g.: STOP_CHARGE_THRESH_BAT0).

sudo add-apt-repository ppa:linrunner/tlp
sudo apt update
sudo apt install tlp tlp-pd tlp-rdw

I wrote a script to simulate the upper and lower threshold /home/richard/.local/bin/Toggle_45_50MaxLoad.sh :

#!/bin/bash

declare -i SetLowThresHold=1

Konfiguration

#LogFile=“/home/richard/battery_log.txt”
BatteryDir=“/sys/class/power_supply/BAT0”

get values

Capacity=$(cat ${BatteryDir}/capacity)
#Status=$(cat ${BatteryDir}/status)
#Time=$(date “+%Y-%m-%d %H:%M:%S”)

echo $Capacity
#echo $Status
#echo $Time

if [ “$Capacity” -le 45 ]
then
SetLowThresHold=0
fi

while true; do

if [ “$SetLowThresHold” -eq 1 ]
then
#set lower threshold
sudo sed -ie ‘s/^#*STOP_CHARGE_THRESH_BAT0=.*/STOP_CHARGE_THRESH_BAT0=44/’ /etc/tlp.conf
#new value will be read
sudo tlp start
while [ “$SetLowThresHold” -eq 1 ]; do
#write to log
Capacity=$(cat ${BatteryDir}/capacity)
#Status=$(cat ${BatteryDir}/status)
#Time=$(date “+%Y-%m-%d %H:%M:%S”)
#echo “${Time} - Battery Level: ${Capacity}% - Status: ${Status}” >> ${LogFile}
#echo $Capacity
if [ “$Capacity” -le 45 ]
then
SetLowThresHold=0
fi
sleep 20
done
#echo $SetLowThresHold
else
#set higher threshold
sudo sed -ie ‘s/^#*STOP_CHARGE_THRESH_BAT0=.*/STOP_CHARGE_THRESH_BAT0=51/’ /etc/tlp.conf
#new value will be read
sudo tlp start
while [ “$SetLowThresHold” -eq 0 ]; do
#write to log
Capacity=$(cat ${BatteryDir}/capacity)
#Status=$(cat ${BatteryDir}/status)
#Time=$(date “+%Y-%m-%d %H:%M:%S”)
#echo “${Time} - Battery Level: ${Capacity}% - Status: ${Status}” >> ${LogFile}
#echo $Capacity
if [ “$Capacity” -ge 50 ]
then
SetLowThresHold=1
fi
sleep 20
done
#echo $SetLowThresHold
fi
done

It must be installed as service with root rights Accu_Threshold_45_50.service in /etc/systemd/system :

[Unit]
Description=Toggle 45% to 50% For Accu
After=network.target

[Service]
ExecStart=/bin/bash /home/richard/.local/bin/Toggle_45_50MaxLoad.sh
Restart=always
User=root

[Install]
WantedBy=multi-user.target

After all the service must be started, checked and can be stopped if 100% capacity will be whished :

systemctl enable Accu_Threshold_45_50
systemctl is-enabled Accu_Threshold_45_50
systemctl disable Accu_Threshold_45_50
systemctl is-enabled Accu_Threshold_45_50

The script itself does only every 20sec a question, therefore no CPU load.

I am impressed by KDE (Wayland I use), only to give back something.

(Beneath, this answer deleted by AskUbuntu : https://askubuntu.com/questions/1567630/laptop-battery-percentage-stays-at-80-even-after-powering-off)