#97·bat

bug: threshold ranges on ThinkPads

Author: SylChamberCreated Aug 14, 2024Updated Dec 19, 2024

Computer: Lenovo ThinkPad T14 Gen 1 AMD (manufactured in 2021) CPU: AMD Ryzen PRO 7 4750U OS: Ubuntu 24.04

I could not set a battery threshold on my Lenovo ThinkPad T14 Gen1 (while it works on my Asus ROG Strix G15 2021). I got the following error:

bash
$ sudo bat threshold 80
A fatal error occurred. Please rerun the command with the `--debug` flag enabled
and file an issue with the resulting output at the following address
https://github.com/tshakalekholoane/bat/issues/new.

with the debug flag:

bash
$ sudo bat threshold 80 --debug
write /sys/class/power_supply/BAT0/charge_control_end_threshold: invalid argument

goroutine 1 [running]:
runtime/debug.Stack()
	/opt/homebrew/Cellar/go/1.22.0/libexec/src/runtime/debug/stack.go:24 +0x5e
main.main.func1()
	/Users/tshaka/x/bat/main_linux.go:111 +0x57
panic({0x5383a0?, 0xc000124270?})
	/opt/homebrew/Cellar/go/1.22.0/libexec/src/runtime/panic.go:770 +0x132
main.main()
	/Users/tshaka/x/bat/main_linux.go:247 +0x1125

When searching on the battery system path, I found the UbuntuHandbook page on setting battery threshold. Trying to set the end threshold manually failed as well:

bash
$ sudo sh -c "echo 80 > /sys/class/power_supply/BAT0/charge_control_end_threshold"
sh: 1: echo: echo: I/O error

It led me to try manually setting the lower charging threshold to a lower value than the end value:

bash
sudo sh -c "echo 20 > /sys/class/power_supply/BAT0/charge_control_start_threshold"

Which I unfortunately did before trying to read the current value. :-( I don't know what it was before. Afterwards, I could set the end threshold, manually or with bat.

I gather that the end threshold must not be lower than the start threshold.