20223-12-20: Battery chargestart and stop thresholds on OpenBSD
================================================================

I often use my laptops as portable desktops: they are plugged
into AC power and an external monitor/keyboard 95% of time.
Unfortunately, continuous charging is hard on the battery. To
mitigate this, ThinkPads have customizable start and stop
charging thresholds, such that the battery will only start
charging if its level falls below the start threshold, and it
will stop charging as soon as it reaches the stop threshold.
Suggested thresholds from Lenovo's battery team can be found in
this [comment][0].

You can set these thresholds on Linux using [tlp-stat(8)][1],
and you can make the values persist across reboots by setting
`START_CHARGE_THRESH_BAT0` and `STOP_CHARGE_THERSH_BAT0` in
`/etc/tlp.conf`.

I recently installed OpenBSD on my work ThinkPad, but struggled to
find any information on how to set the thresholds under OpenBSD. After
only finding a [dead-end thread][2] from 2021 on misc@, I started
digging around on how to implement it myself. The `acpithinkpad` and
`acpibat` drivers looked promising, and a bit of Google-fu lead me to
the following small announcement in the [OpenBSD 7.4 release
notes][3]:

> New sysctl(2) nodes for battery management,
> hw.battery.charge*. Support them with acpithinkpad(4) and
> aplsmc(4).

Lo and behold, setting the start and stop threshold in OpenBSD
is simply a matter of setting `hw.battery.chargestart` and
`hw.battery.chargestop` with `sysctl`. The documentation was not
[committed][4] in time for the 7.4 release, but you can read it
in -CURRENT's [`sysctl(2)`][5]. I personally set the following
values in `/etc/sysctl.conf`:

```
hw.battery.chargestart=40
hw.battery.chargestop=60
```

[0]: https://pointieststick.com/2020/06/08/lenovo-thinkpad-x1-yoga-impressions-bugs-workarounds-and-thoughts-about-the-future/#comment-22688
[1]: (https://manpages.debian.org/unstable/tlp/tlp-stat.8.en.html).
[2]: https://www.mail-archive.com/search?l[email protected]&q=subject:%22Re%5C%3A+How+to+set+ThinkPad+battery+charge+thresholds%5C%3F%22&o=newest&f=1
[3]: https://www.openbsd.org/74.html
[4]: https://marc.info/?l=openbsd-cvs&m=169730997126948
[5]: https://man.openbsd.org/sysctl.2#HW_BATTERY~2