WIKI: charge management for battery health

asked 2019-01-17 15:50:28 +0300

this post is marked as community wiki

This post is a wiki. Anyone with karma >75 is welcome to improve it.

updated 2019-01-17 18:34:27 +0300

rozgwi gravatar image

This would like to be a wiki for battery management.

I was studying the Battery management topic https://together.jolla.com/question/55764/charging-limitation-for-enhanced-battery-life-feature-request/ My goal is to preserve battery health by avoiding high temperatures while charging. In order to make things work I rewrote the charging_control.sh script redirecting the file paths:

# We need to take control over this, every time after reboot.
chmod 777 /sys/class/power_supply/battery_charging_enabled
# Set it to allow charging.
echo 1 > /sys/class/power_supply/battery_charging_enabled

# Set the variables.
present=$(cat /sys/class/power_supply/usb/present)
temp=$(cat /sys/class/power_supply/battery/temp)
state=$(cat /sys/class/power_supply /battery_charging_enabled)

Start the loop and keep cycling while the charger is present.

while (($present > 0))
do
present=$(cat /sys/class/power_supply/usb/present)

# If temp is over around 350, charging is disabled.
if (($temp > 350 && $state == 0)); then
echo 0 > sys/class/power_supply/battery_charging_enabled
state=0
fi

# If temp is above around 350, charging is enabled.
if (($temp < 350 && $state == 1)); then
echo 1 > sys/class/power_supply/battery_charging_enabled
state=1
fi

# Sleep for a while before re-checking the situations.
sleep 120
done

# Re-enable charging when the charger is removed. Preparing for the next time.
if (($present < 1)); then
echo 1 > /sys/class/power_supply/battery_charging_enabled
fi

Question: Anyone can help to understand the function for these two additional files:

  • therm_miti_usb5v
  • therm_miti_usb9v

Some details can be found here: https://github.com/Hundsbuah/SGP771_SGP712

edit retag flag offensive close delete

Comments

Neat! Another interesting feature could be limiting charging to 80% or something like that, which (as far as I understand) improves battery life.

Federico ( 2019-01-17 19:41:49 +0300 )edit

Those files seem to handle thermal mitigation, and perhaps contain parameters for when charging on 5v and 9v (which is a USB-C thing) respectively. Probably the parameters are are in amps because it's what you'd measure, thus making wattage dependent on voltage. You don't happen to have example content?

attah ( 2019-01-17 21:51:47 +0300 )edit
1

You are not updating state variable properly inside the loop, and not updating temp variabld at all. Also, second comment about temperature is not correct.

addydon ( 2019-01-18 04:48:40 +0300 )edit

Yeah. I guess this should be changed:

if (($temp > 350 && $state == 0)); then

to:

if (($temp > 350 && $state == 1)); then

and:

if (($temp < 350 && $state == 1)); then

to:

if (($temp < 350 && $state == 0)); then
Filip K. ( 2019-01-18 08:55:24 +0300 )edit