Skip to content

pepa65/bat

Repository files navigation

Go Report Card GoDoc Continuous Integration

bat v0.16.1

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.

About

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

Requirements

Disclaimer

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.

Installation

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

Examples

Print the current battery charge level, limit and status

bat

Sample output:

[BAT0]
Level: 45%
Limit: 80%
Health: 85%
Status: Charging
Persist: yes

Set a battery charge limit in percentage points (requires privileges):

sudo bat 80

Sample output:

[BAT1] Charge limit set, to make it persist, run:
bat persist

Undo the battery charge limit (requires privileges):

sudo bat 0

Sample output:

[BATC] Charge limit unset

Persist the currently set charge limit after restart/hibernation/wake-up (requires privileges):

sudo bat persist

Sample output:

[BATT] Persistence enabled for charge limit: 80

Remove the persist config settings (requires privileges):

sudo bat remove

Sample output:

[BAT0] Persistence of charge limit removed

Remove persist config settings for BAT1 (requires privileges):

sudo BAT_SELECT=BAT1 bat remove

Output:

[BAT1] Persistence of charge limit removed