Skip to content
AndrewGoalPublic

About

Battery charge-threshold profiles for Linux laptops: longevity/travel/no-limit modes, self-healing guard timer, tiny CLI, Omarchy menu.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

batt-mode

Battery charge-threshold profiles for Linux laptops, with a self-healing guard timer, a tiny CLI, and an optional Omarchy/Hyprland menu.

Stop cooking your battery at 100% on the desk. One command (or one menu click) switches between longevity, travel and no limit modes.

Omarchy menu

$ batt-mode status
mode      : longevity
threshold : 50% -> 80%
battery   : 79% (Not charging, 11.76 V, 0.0 W)
AC        : online
expires   : -
sysfs set : 50% -> 80%

Why

A lithium battery ages fastest when it sits at high state of charge and high temperature — exactly what a laptop that lives on a desk does. Capping charging at 80% and only topping up below 50% removes most of that stress while keeping a usable buffer.

ThinkPad ECs (and some others) expose threshold knobs:

/sys/class/power_supply/BAT0/charge_control_start_threshold
/sys/class/power_supply/BAT0/charge_control_end_threshold

...but they are lost on EC reset, battery swap, or firmware hiccup, and there is no desktop UI for them. batt-mode fixes both: it stores the mode, re-applies it every 15 minutes, and gives you a one-click switch.

Modes

Mode Thresholds Use
longevity (default) 50% → 80% laptop stays plugged in
travel 95% → 100%, auto-reverts leaving the house for a few hours
max 0% → 100% hand control back to the firmware
custom S E S% → E% anything else

travel expires (default 12 h) and quietly falls back to longevity, so forgetting to switch back cannot leave the battery parked at 100% for weeks.

Install

git clone https://github.com/AndrewGoal/batt-mode.git
cd batt-mode
sudo ./install.sh

Requires a battery exposing charge_control_start_threshold / charge_control_end_threshold (ThinkPad, and several other business laptops). install.sh installs the CLI, the root helpers, a systemd timer and a narrow sudoers.d rule so mode changes never prompt for a password.

Usage

batt-mode                    # status
batt-mode longevity          # 50 -> 80 (default)
batt-mode travel 8           # up to 100%, revert to longevity after 8h
batt-mode max                # 0 -> 100
batt-mode custom 60 85       # 60 -> 85
batt-mode toggle             # longevity <-> travel
batt-mode trim 80            # discharge a full battery down to 80%
batt-mode trim-stop          # cancel a running trim
batt-mode notify             # status as a desktop notification
batt-mode is travel          # exit 0 if travel is active (scripting / menus)

trim (optional)

If the battery is already at 100% and you switch to longevity, nothing discharges it — charging simply stops. trim uses the EC's force-discharge feature to run the machine from the battery while plugged in, down to the stop threshold, then restores normal behaviour. Takes ~30–60 min on a typical pack; log with journalctl -t batt-mode -f.

Omarchy / Hyprland integration

Copy integrations/omarchy-menu.jsonc into ~/.config/omarchy/extensions/omarchy-menu.jsonc (it hot-reloads), then open the menu with omarchy menu summon battery.

Optional keybinding, in ~/.config/hypr/bindings.lua:

o.bind("SUPER + ALT + B", "Battery mode", "omarchy menu summon battery")

How it works

batt-mode               user CLI (no root needed to read status)
  └─ sudo -n            narrow sudoers rule
     └─ batt-mode-apply      writes /etc/batt-mode.conf + sysfs thresholds
batt-mode.timer (15m)
  └─ batt-mode-guard    expires travel mode, re-applies thresholds after EC resets
batt-mode-trim          root helper: force-discharge down to the stop threshold

Config lives in /etc/batt-mode.conf:

MODE=longevity
START=50
STOP=80
UNTIL=0        # epoch seconds; 0 = never expires

FAQ

status says "Not charging" forever. Normal. With start=50, the EC only begins charging at or below 50% and stops at 80%. Between those, it does nothing.

Thresholds look right but the battery keeps charging to 100%. Some ECs ignore threshold writes while on battery; batt-mode stores the mode and the guard timer applies it once AC is connected.

Did the guard timer reset my travel mode after a reboot? Only if it expired. Modes are persistent; expiry is stored as a timestamp.

Does this work on non-ThinkPads? It works on any machine whose EC exposes charge_control_*_threshold. trim additionally needs charge_behaviour with force-discharge.

中文速览

batt-mode 是一个电池充电阈值切换工具,给常年插电的笔记本用:

  • longevity(默认):50% 才开始充,充到 80% 停 —— 避开"满电 + 高温"这个最伤电池的组合
  • travel:临时放到 95→100% 出门用,默认 12 小时后自动退回 longevity,忘记切回来也不会一直满电
  • max:0→100%,交回固件管理
  • trim:电池已经在 100% 时,用 EC 的 force-discharge 主动放电到阈值(插着电也能放)

ThinkPad 的充电阈值在 EC 复位或换电池后会丢失,所以除了 CLI 还有个 15 分钟一次的守护定时器自动补回来。

sudo ./install.sh      # 安装(含免密 sudo 规则、systemd timer)
batt-mode              # 看状态
batt-mode travel 8     # 出门模式,8 小时后自动恢复

Omarchy 用户可把 integrations/omarchy-menu.jsonc 合并进 ~/.config/omarchy/extensions/omarchy-menu.jsonc,之后 omarchy menu summon battery 或绑一个键就能一键切换。

Uninstall

sudo ./uninstall.sh    # restores 0/100 and removes units, helpers and the sudoers rule

License

MIT

About

Battery charge-threshold profiles for Linux laptops: longevity/travel/no-limit modes, self-healing guard timer, tiny CLI, Omarchy menu.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages