Echoing /u/cheiKa3u, TLP is your friend. You'll need to also install acpi_call (or tp_smapi for older computer models) to get battery threshold working. The [Arch wiki entry](
https://wiki.archlinux.org/index.php/TLP) is helpful here, even if you don't run Arch.
Once you're set up, edit /etc/default/tlp to include lines like these, with the values you want:
START_CHARGE_THRESH_BAT0=40
STOP_CHARGE_THRESH_BAT0=60
This means charging only starts if you plug in below 40%, and it stops charging at 60%. If you plug in between 40% and 60%, it maintains the current charge.
Some useful tlp commands:
- tlp chargeonce: Charge to upper threshold once (bypassing lower threshold).
- tlp fullcharge: Set charge threshold to factory preset (96/100) temporarily (causing a full charge).
- tlp setcharge [start stop]: Set charge thresholds temporarily.
- tlp setcharge (no arguments): Restore configured thresholds.
In all cases, the configured thresholds are restored upon next system start.