Set battery charge threshold

I like your idea and I also asked this question in the matrix group, without success. Maybe a discussion here will bring up some solutions.

I already found this post battery-charge-notification which plays a sound when the battery level reaches a threshold. This solution does not de- and reactivate charging.

Regarding your [2], I modified it like that:

#!/bin/sh

# Start/stop blinking of status LED when battery is out of device
# https://forums.puri.sm/t/new-post-my-first-week-of-librem-5-convergence/12431/53
# sudo i2cset -f -y 3 0x6a 0x07 0xcd # turns STAT LED off
# sudo i2cset -f -y 3 0x6a 0x07 0x8d # turns STAT LED back on

# Charger: /sys/class/power_supply/tps6598x-source-psy-0-003f/*     
# USB-C module: /sys/class/power_supply/bq25890-charger/*
# Battery: /sys/class/power_supply/max170xx_battery/*

STOP_THRESHOLD=80
START_THRESHOLD=30

while true; do
  AC_STATE=$(cat /sys/class/power_supply/tps6598x-source-psy-0-003f/online)
  if [ $AC_STATE = "1" ]; then
    echo "on AC"
    BAT_LEVEL=$(cat /sys/class/power_supply/max170xx_battery/capacity)
    CURRENT=$(cat /sys/class/power_supply/max170xx_battery/current_now)
    echo "current=$CURRENT"
    if [ $BAT_LEVEL -gt $STOP_THRESHOLD ]; then
      echo "bat level > $STOP_THRESHOLD%"
      if [ $CURRENT -gt 0 ]; then
        echo "charger disabling"
        sleep 10
#        ectool chargecontrol idle <-- modify
      fi
    elif [ $BAT_LEVEL -lt $START_THRESHOLD ]; then
      echo "bat level < $START_THRESHOLD%"
      if [ $CURRENT -lt 0 ]; then
        echo "charger enabling"
        sleep 10
#        ectool chargecontrol normal <-- modify
      fi
   else
    echo "charger state OK, idling..."
   fi
  else
    echo "not on AC, idling..."
  fi
sleep 10
done

I changed the AC to tps6598x-source-psy-0-003f, the BAT0 to max170xx_battery and ‘cat …’ to $(cat …) . I also comment out the command ectool to check, if the script recocnizes the states. With my Librem5 it works.

The next step is to add the command to start and stop charging while the device is plugged to a dock or power charger. Does anybody know the command for that?

1 Like