Manage battery charge limit
- Repo: github.com/pepa65/bat
- After: github.com/tshakalekholoane/bat
- License: MIT
- Required: Linux-5.4-rc1+ systemd-244+
bat v0.16.1 - Manage battery charge limit
Repo: github.com/pepa65/bat
Usage: bat <option>
Options (every option except 's[tatus]' needs root privileges):
[s[tatus]] Display charge level, limit, health & persist status.
[l[imit]] <int> Set the charge limit to <int> percent.
p[ersist] Persist the charge limit after driver reloads.
r[emove] Do not persist the charge limit after driver reloads.
h[elp] Just display this help text.
v[ersion] Just display version information.
The battery with regex 'BAT.' in environment variable BAT_SELECT will be used.
The goal is to replicate the functionality of the ASUS Battery Health Charging utility for ASUS laptops on Windows which aims to prolong the battery's life-span 1 2.
- Linux kernel module:
asus_nb_wmi
- System variables used:
/sys/class/power_supply/BAT?/
- Persist states for
systemd
:hibernate
,hybrid-sleep
,multi-user
,sleep
,suspend
,suspend-then-hibernate
- Linux kernel version later than 5.4-rc1 which is the earliest version to expose the battery charge limit variable.
- To persist the battery charge limit setting after restart/hibernation/wake-up, the application relies on systemd version 244 or later (bundled with most current Linux distributions).
This has been reported to only work with some ASUS and Lenovo ThinkPad laptops. For Dell Lattitude/Precision laptops, use package smbios-utils: smbios-battery-ctl --set-custom-charge-interval=50 80
. For other manufacturers there is also TLP.
Precompiled binaries (Linux x86_64) are available from the GitHub releases page, download the latest here.
sudo wget -qO /usr/local/bin/bat "gitlab.com/pepa65/bat/-/jobs/artifacts/main/raw/bat?job=building"
sudo chmod +x /usr/local/bin/bat
Alternatively, the application can be build from source by running the following command in the root directory of this repository. This requires a working version of Go:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -ldflags="-s -w"
To install, do: sudo mv bat /usr/local/bin
(requires root privileges).
You can also rename the binary to something else if another program with the same name already exists.
Or install by simply: go install github.com/pepa65/bat@latest
bat
Sample output:
[BAT0]
Level: 45%
Limit: 80%
Health: 85%
Status: Charging
Persist: yes
sudo bat 80
Sample output:
[BAT1] Charge limit set, to make it persist, run:
bat persist
sudo bat 0
Sample output:
[BATC] Charge limit unset
sudo bat persist
Sample output:
[BATT] Persistence enabled for charge limit: 80
sudo bat remove
Sample output:
[BAT0] Persistence of charge limit removed
sudo BAT_SELECT=BAT1 bat remove
Output:
[BAT1] Persistence of charge limit removed