Optimizing Battery Management on Linux Phones: A Dive into PinePhone and Librem 5

Hey everyone,

I’ve fully switched to using the Librem 5 as my daily driver and love it, but the battery management has been a bit of a project for me. Leaving it plugged in all day doesn’t sit right with me when the battery stays fully charged and keeps drawing power. So, I’ve been experimenting with ways to tweak this. I’ve managed to set up a system where the battery cuts off from charging when it hits a certain point but remains available for discharge down to a lower threshold if the phone needs it.

Here’s how the scripts work under various conditions:

  • Standard Charging: The phone charges to a predetermined upper limit (like 90%) and then stops to prevent battery strain.
  • Continuous Power Supply: If it remains plugged in post-charge, the phone priorities drawing power directly off the charger, sparing the battery , and only use the battery if the power supply is not producing enough juice.
  • Reconnection Nuances: Unplugging and replugging doesn’t immediately resume charging. It waits until the battery drops below a set lower threshold (say, 60%), which helps in maintaining battery health by avoiding short, unnecessary charge cycles.
  • Handling Power Fluctuations: For those times when the power source is unstable or you’re frequently plugging and unplugging, the script ensures that repetitive charging doesn’t kick in unless truly needed.
  • Customization: The thresholds for both the upper and lower limits can be adjusted to fit personal usage patterns and battery longevity goals.

Project Repositories:

On the PinePhone, managing this was pretty straightforward because the driver includes a ‘charge behavior’ driver that you can manipulate directly. For the PinePhonePro, you can find the charge behaviour control at this path:

/sys/class/power_supply/{battery_type}/charge_behaviour

The Librem 5, however, threw a curveball my way. It doesn’t support modifying charge behavior through the usual driver settings. The workaround I found on the wiki, using the charge LED as a control point. Here’s how I control it:

/sys/class/leds/chg_en/brightness

This lets me toggle the charging on and off

I’m looking to further refine these scripts and maybe even bundle them into a Flatpak. My next goals are adding rtcwake for it to check after every 30 mins for notifications and battery level, and maybe control the battery cutoff via I2C but that will require some testing.

Feel free to contribute and let me know what you all think about it.

If someone has a better method or can suggest a better workaround for the Librem 5, I’m all ears.

Heads-up: This setup is still very much DIY. Make sure you really dig into the scripts before deploying them. If your phone turns into Charmander that is all on you!

Cheers!

5 Likes

You may be interested in controlling temperature and CPU/GPU frequencies:

Do you do the thing with multiple batteries? I have 5 batteries for my Librem 5 so I almost never charge the unit itself – whenever I need it, I just put a full battery in off of one of the chargers.

However, if I need to battery swap while the device is still on, for a “fast charge” as I joking call it, I do that by attaching power, ripping out the battery, putting the full battery in, and then unattaching from power. It takes about 3 seconds, but technically it means there was a momentary “short charging cycle” of a second or two for both the “before” and “after” battery. Do you suppose this negatively impacts the health of these batteries? Would your script prevent that?

1 Like

I have never heard this could be a problem. Can you provide more background on this?

1 Like

Swapping batteries is a great way to go if you don’t like having the charger or power bank connected most of the time. Personally, I just don’t like the hassle of replacing batteries regularly. As for the wear, no, I don’t think 3 seconds would have any significant effect since you’re just swapping. Should be totally fine as far as I can tell.

1 Like

The concern with short, unnecessary charge cycles mostly applies to situations where they happen frequently, like topping off a battery from 90% to 100% multiple times a day. While lithium-ion batteries are durable, minimizing those shallow cycles at reduce long-term wear.

Each time the charger reconnects, the battery’s charging circuit ramps up, creating additional strain. This frequent start-stop charging behavior can accelerate wear over time, especially if the battery is near full charge. So the script tries to avoid that.

1 Like

Will definitely give this a trial run.

2 Likes

Good to know! Thanks! I will give the script a try as well.

2 Likes

That would be an interesting task. Did you have something in mind that should be done when the mobile heats up? or just prevent it all together? Because I do blv that there would be less heating if the battery is not being charged.