Using Termux on an Android smartphone and a WiFi Smart Plug the phone can control its charging via half hour cron'ed termux-battery-status, MQTT and openHAB to control the plug. Termux hasn't battery status events (Termux issue 382) hence cron.

When I get home, I plug in the phone and manually switch on the WiFi plug.

I wonder what is the best charging plan for battery life.

Currently the plan is simply

if between 10pm and 5am
   if charge < 20%
      power on plug
   if charge < 50%
      power on plug

if charge > 80%
   power off plug

at 05:00am
   power on plug

(at 7:00am the charge should be at 80%)

Do you know a better plan? Are the 50% / 80% limits ok?

This way I also control an old tablet that is used as smart home display and speaker, but as it is alway at home I only let it cycle between 30% and 80%.

  • For battery life keep it between 40% and 60%. Most LiO batteries age less if charged only around 50%.
    – Robert
    Oct 31, 2021 at 12:28
  • The best we can provide factually is about the battery percentage. For the timing/schedule, it depends on personal restrictions which cannot be possibly applied to others having different restrictions, which also makes this opinion-based (i.e. there are no charging plans that can be applied generally).
    – Andrew T.
    Oct 31, 2021 at 13:22


Browse other questions tagged .