# How to set battery charging thresholds on laptop...



## bleakwind (Apr 13, 2021)

When the laptop is charged to 95%, I want to stop charging...


```
# hwstat
                    Current                Unit
[Coretemp]
    CPU0:                Cannot get temperature
    CPU1:                Cannot get temperature
    CPU2:                Cannot get temperature
    CPU3:                Cannot get temperature
    CPU4:                Cannot get temperature
    CPU5:                Cannot get temperature
    CPU6:                Cannot get temperature
    CPU7:                Cannot get temperature

[ACPI Thermal]
    tz0:                56.1                C

[ACPI Battery (sysctl)]
    Cap remain:            75                percents
    Life time:            148                Min(s)
    State:                1
    Units:                2

[battery0]
    Present:            yes
    Design capacity:        21330                mWh
    Last full capacity:        22930                mWh
    Technology:            secondary (rechargeable)
    Design voltage            11400                mV
    Capacity (warn):        1146                mWh
    Capacity (low):            200                mWh
    Low/warn granularity:        -1                mWh
    Warn/full granularity:        -1                mWh
    Model number:            00HW022
    Serial number:             1020
    Type:                LiP
    OEM info:            LGC
    State:                discharging
    Remaining capacity:        37                percent
    Remaining time:            0:29
    Present rate:            17566                mW
    Voltage:            11097                mV

[battery1]
    Present:            yes
    Design capacity:        71100                mWh
    Last full capacity:        35020                mWh
    Technology:            secondary (rechargeable)
    Design voltage            11250                mV
    Capacity (warn):        1751                mWh
    Capacity (low):            200                mWh
    Low/warn granularity:        -1                mWh
    Warn/full granularity:        -1                mWh
    Model number:            01AV492
    Serial number:              852
    Type:                LION
    OEM info:            LGC
    State:                high
    Remaining capacity:        100                percent
    Remaining time:            1:59
    Present rate:            0                mW
    Voltage:            12307                mV
```


```
# uname -a
FreeBSD bleakwind.xxx.com 12.2-RELEASE-p6 FreeBSD 12.2-RELEASE-p6 GENERIC  amd64
```


```
# dmidecode -t 1
System Information
    Manufacturer: LENOVO
    Product Name: 20L5A01UHH
    Version: ThinkPad T480
```


----------



## aragats (Apr 13, 2021)

Good question. I have a ThinkPad too.
As far as I know you'll need ThinkPad SMAPI driver. However, I see it only under .../sys/i386/bios. There must be a reason why it doesn't exist for _amd64_ (or maybe I'm missing something).
There is also an old project thinkpad-smapi.


----------



## fernandel (Apr 22, 2021)

I found on reddit but it is to much for me:
https://libredd.it/r/freebsd/comments/lsygde/acpi_controlling_battery_charging_thresholds_on/


----------



## fernandel (Apr 23, 2021)

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=234403

Is it a dead project on FreeBSD?


----------



## Fuzzbox (Apr 24, 2021)

Hi,

T430 here.

What works for me to set charge start threshold to 80% and stop charge threshold to 95% :

Get battery acpi handle :

`sysctl dev.acpi_ibm.0.%location`
dev.acpi_ibm.0.%location: handle=\_SB_.PCI0.LPC_.EC__.HKEY

Use it to set the start charge threshold : 
`acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCCS' -i 80`

and set the stop charge threshold :
`acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCSS' -i 95`

Quite close to what was described in the Reddit post.
Don't know if it works on a T480.
Good luck.


----------



## aragats (Apr 24, 2021)

Seems to be working great in X1 Gen1, thanks, Fuzzbox !
Currently at 96% and AC plugged in:
	
	



```
% acpiconf -i0 | grep State
State:            high
```
which means it's not charging!


----------



## Fuzzbox (Apr 24, 2021)

I'm glad I could help.


----------



## fernandel (Apr 24, 2021)

Looks like it doesn't works on mine T495 with FreeBSD 13.0-RELEASE:

```
acpi_call -v -p '_SB_.PCI0.LPC0.EC.HKEY.BCCS' -i 99
Path: _SB_.PCI0.LPC0.EC.HKEY.BCSS
Number of arguments: 1
Argument 1 type: Integer
Argument 1 value: 99
Status: 4097
Result: Unknown object type '0'
```


```
acpi_call -v -p '_SB_.PCI0.LPC0.EC0_.HKEY.BCSS' -i 15
Path: _SB_.PCI0.LPC0.EC0_.HKEY.BCCS
Number of arguments: 1
Argument 1 type: Integer
Argument 1 value: 15
Status: 4097
Result: Unknown object type '0'
```


```
sysctl dev.acpi_ibm.0.%location
dev.acpi_ibm.0.%location: handle=\-SB_.PCI0.LPC0.ECO_.HKEY
```

Thank you.


----------



## Fuzzbox (Apr 24, 2021)

You really have to write '\-SB_.PCI0.LPC0.ECO_.HKEY'   , with the \ at the beginning.
`acpi_call -p '\_SB_.PCI0.LPC0.ECO_.HKEY.BCCS' -i 15`


----------



## fernandel (Apr 25, 2021)

Fuzzbox said:


> You really have to write '\-SB_.PCI0.LPC0.ECO_.HKEY'   , with the \ at the beginning.
> `acpi_call -p '\_SB_.PCI0.LPC0.ECO_.HKEY.BCCS' -i 15`


Now I got for both "0" and when I checked both if are they runing:

```
acpi_call -v -p '\_SB.PCI0.LPC0.EC0_.HKEY.BCSG' -i 1 -v
Path: \_SB.PCI0.LPC0.EC0_.HKEY.BCSG
Number of arguments: 1
Argument 1 type: Integer
Argument 1 value: 1
Status: 0
Result: 867
acpi_call -v -p '\_SB.PCI0.LPC0.EC0_.HKEY.BCTG' -i 1 -v
Path: \_SB.PCI0.LPC0.EC0_.HKEY.BCTG
Number of arguments: 1
Argument 1 type: Integer
Argument 1 value: 1
Status: 0
Result: 783
```

Is it look okay, please? Should I put both  in /etc/rc.conf?

Thank you.


----------



## Fuzzbox (Apr 25, 2021)

Now unplug the AC adapter and see how the charging behaves.
If it works and the thresholds are ok, the battery controller should keep them in memory until you change them again, or until you plug out / plug back in the battery from its compartment.


----------



## fernandel (Apr 25, 2021)

Fuzzbox said:


> Now unplug the AC adapter and see how the charging behaves.
> If it works and the thresholds are ok, the battery controller should keep them in memory until you change them again, or until you plug out / plug back in the battery from its compartment.


Thank you. I will try. I external monitor  connected with USB-C and it also charge a laptop. I will try to connect with HDMI and carged laptop with regular charger. For now `hwstat` shows:

```
[Coretemp]
    CPU0:                48.0                C
    CPU1:                48.0                C
    CPU2:                48.0                C
    CPU3:                48.0                C
    CPU4:                48.0                C
    CPU5:                48.0                C
    CPU6:                48.0                C
    CPU7:                48.0                C

[ACPI Battery (sysctl)]
    Cap remain:            89                percents
    Time remain:            On AC
    State:                0
    Units:                1

[battery0]
    Present:            yes
    Design capacity:        50450                mWh
    Last full capacity:        49150                mWh
    Technology:            secondary (rechargeable)
    Design voltage            11520                mV
    Capacity (warn):        2457                mWh
    Capacity (low):            200                mWh
    Low/warn granularity:        -1                mWh
    Warn/full granularity:        -1                mWh
    Model number:            5B10W139
    Serial number:             4773
    Type:                LiP
    OEM info:            SMP
    State:                high
    Remaining capacity:        89                percent
    Remaining time:            unknown
    Present rate:            0                mW
    Voltage:            12642                mV
```


----------



## Fuzzbox (Apr 25, 2021)

Hm... it's a good sign, since the remaining capacity is not 100%.
If you have set start at 15% and stop at 95%, it should not start charging again until your battery reaches a level lower than 15% (which is a bit low imho, something like 30% could be better for the health of the battery). Then it will charge from 15% to 95%, unless you unplug the AC adapter in between.


----------



## fernandel (Apr 25, 2021)

I am not sure if it works because I have 89% almost  one hour now. The light is orange but...and `hwstat` shows

```
[ACPI Battery (sysctl)]
    Cap remain:            89                percents
    Time remain:            On AC
    State:                0
    Units:                1

[battery0]
    Present:            yes
    Design capacity:        50450                mWh
    Last full capacity:        49150                mWh
    Technology:            secondary (rechargeable)
    Design voltage            11520                mV
    Capacity (warn):        2457                mWh
    Capacity (low):            200                mWh
    Low/warn granularity:        -1                mWh
    Warn/full granularity:        -1                mWh
    Model number:            5B10W139
    Serial number:             4773
    Type:                LiP
    OEM info:            SMP
    State:                high
    Remaining capacity:        89                percent
    Remaining time:            unknown
    Present rate:            0                mW
    Voltage:            12649                mV
```
and `sysctl -a | grep battery`

```
hw.acpi.battery.info_expire: 5
hw.acpi.battery.units: 1
hw.acpi.battery.state: 0
hw.acpi.battery.rate: 0
hw.acpi.battery.time: -1
hw.acpi.battery.life: 89
dev.battery.0.%parent: acpi0
dev.battery.0.%pnpinfo: _HID=PNP0C0A _UID=0 _CID=none
dev.battery.0.%location: handle=\_SB_.PCI0.LPC0.EC0_.BAT0
dev.battery.0.%driver: battery
dev.battery.0.%desc: ACPI Control Method Battery
dev.battery.%parent:
```


----------



## Fuzzbox (Apr 25, 2021)

Read my previous post again 

Charge stop threshold : the threshold your battery won't exceed when it's charging.
Charge start threshold : the threshold you have to reach before your battery starts charging again.

So, with a power source connected to you laptop, the battery will stay at 89% for now.
Disconnect the power source, you battery will discharge. 
Connect the power source again : if the remaining capacity is higher than 15%, it won't charge; if it's lower than 15% it will charge, up to 95%.

So, if you want your laptop to be "almost charged all the time but not 100%", you should set a start charge threshold higher, like 85% for instance, and a stop charge threshold at 95%. But if you use it almost always connected to a power source, something like 30% / 75% is enough.

I hope that's clearer


----------



## balanga (Apr 25, 2021)

fernandel said:


> fernandel said:
> 
> 
> > I am not sure if it works because I have 89% almost  one hour now. The light is orange but...and `hwstat` shows


I'm really out of my depth here, but looks like an interesting thread.... however what is `hwstat`?

Is it something you need to install?

I'm running FreeBSD 13.0-RELEASE on a ThinkPad T530i.


----------



## Fuzzbox (Apr 25, 2021)

You don't *need* it, since you can get the same data from other tools, but you can install it as a package or from ports ( /sysutils). It only displays CPU and battery infos.


----------



## balanga (Apr 25, 2021)

I've just installed sysutils/hwstat and this is what it outputs:-

```
[Coretemp]
    CPU0:                Cannot get temperature
    CPU1:                Cannot get temperature
    CPU2:                Cannot get temperature
    CPU3:                Cannot get temperature

[ACPI Thermal]
    tz0:                48.1                C

[ACPI Battery (sysctl)]
    Cap remain:            100                percents
    Time remain:            On AC
    State:                0
    Units:                1

[battery0]
    Present:            yes
    Design capacity:        47520                mWh
    Last full capacity:        46390                mWh
    Technology:            secondary (rechargeable)
    Design voltage            10800                mV
    Capacity (warn):        2319                mWh
    Capacity (low):            200                mWh
    Low/warn granularity:        1                mWh
    Warn/full granularity:        1                mWh
    Model number:            45N1005
    Serial number:            32534
    Type:                LION
    OEM info:            LGC
    State:                high
    Remaining capacity:        100                percent
    Remaining time:            unknown
    Present rate:            0                mW
    Voltage:            12168                mV
```

Seems odd that no CPU temperature is displayed... apart from that do things appear to be normal?


----------



## Fuzzbox (Apr 25, 2021)

Hm... do you have the coretemp module loaded ? I have 
	
	



```
coretemp_load="YES"
```
 in my /boot/loader.conf.
Btw, your battery is in very good health.


----------



## bleakwind (Apr 26, 2021)

Fuzzbox said:


> Hi,
> 
> T430 here.
> 
> ...



Thanks for your help.
My computer is Thinkpad T480.

```
# sysctl -a | grep dev.acpi_ | grep EC
dev.acpi_acad.0.%location: handle=\_SB_.PCI0.LPCB.EC__.AC__
dev.acpi_ec.0.%location: handle=\_SB_.PCI0.LPCB.EC__
dev.acpi_ec.0.%desc: Embedded Controller: GPE 0x16, ECDT
```

Is my locations is this?

```
dev.acpi_ec.0.%location: handle=\_SB_.PCI0.LPCB.EC__
```

and this?

```
acpi_call -p '\_SB_.PCI0.LPCB.EC__.HKEY.BCCS' -i 80
acpi_call -p '\_SB_.PCI0.LPCB.EC__.HKEY.BCSS' -i 95
```

Is it work for other brand laptop?


----------



## Fuzzbox (Apr 26, 2021)

Yes, I've just checked, and the "%location" I get from dev.acpi_ibm... and dev.acpi_acad... is the same.
So the acpi_call commands above are supposed to work.

As far as I know, it's not a common feature on laptops, even if exists for ages on Thinkpads. I *think* some Dell and Sony computers implement it, of course probably in a different way.


----------



## bleakwind (Apr 28, 2021)

Fuzzbox said:


> Yes, I've just checked, and the "%location" I get from dev.acpi_ibm... and dev.acpi_acad... is the same.
> So the acpi_call commands above are supposed to work.
> 
> As far as I know, it's not a common feature on laptops, even if exists for ages on Thinkpads. I *think* some Dell and Sony computers implement it, of course probably in a different way.



Clould you post this output? Thanks...


```
# sysctl -a | grep \_SB_.PCI0.LPCB.
```


----------



## Fuzzbox (Apr 28, 2021)

Sure :

```
sysctl -a|grep \_SB_.PCI0.LPC

dev.acpi_ibm.0.%location: handle=\_SB_.PCI0.LPC_.EC__.HKEY
dev.acpi_acad.0.%location: handle=\_SB_.PCI0.LPC_.EC__.AC__
dev.battery.0.%location: handle=\_SB_.PCI0.LPC_.EC__.BAT0
dev.psmcpnp.0.%location: handle=\_SB_.PCI0.LPC_.MOU_
dev.atkbdc.0.%location: handle=\_SB_.PCI0.LPC_.KBD_
dev.fpupnp.0.%location: handle=\_SB_.PCI0.LPC_.FPU_
dev.atdma.0.%location: handle=\_SB_.PCI0.LPC_.DMAC
dev.isab.0.%location: slot=31 function=0 dbsf=pci0:0:31:0 handle=\_SB_.PCI0.LPC_
dev.atrtc.0.%location: handle=\_SB_.PCI0.LPC_.RTC_
dev.hpet.0.%location: handle=\_SB_.PCI0.LPC_.HPET
dev.attimer.0.%location: handle=\_SB_.PCI0.LPC_.TIMR
dev.acpi_sysresource.1.%location: handle=\_SB_.PCI0.LPC_.SIO_
dev.acpi_ec.0.%location: handle=\_SB_.PCI0.LPC_.EC__
```


----------



## Birdy (Jul 10, 2021)

Fuzzbox said:


> Now unplug the AC adapter and see how the charging behaves.
> If it works and the thresholds are ok, the battery controller should keep them in memory until you change them again, or until you plug out / plug back in the battery from its compartment.


"... or until you plug out / plug back in the battery from its compartment."

Why is that?


----------



## ksiu (Jul 10, 2021)

Mine t440p stopped charging after I did the above 2 commands.


----------



## Fuzzbox (Jul 11, 2021)

Birdy said:


> "... or until you plug out / plug back in the battery from its compartment."


Removing the battery resets the battery controller on some Thinkpads.



ksiu said:


> Mine t440p stopped charging after I did the above 2 commands.


What do you mean by stopped charging ? What thresholds did you set and what is the current level of charge ?


----------



## ksiu (Jul 11, 2021)

Fuzzbox said:


> What do you mean by stopped charging ? What thresholds did you set and what is the current level of charge ?




```
#!/bin/sh

acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCCS' -i 75

acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCSS' -i 85
```

The charge cable is plugged into the wall.  The battery level is stuck at 79%.  It is neither going up or down.  Wierd.  I expect it to charge up to 85% and stop.

`$ acpiconf -i0
Design capacity:        56160 mWh
Last full capacity:     40510 mWh
Technology:             secondary (rechargeable)
Design voltage:         10800 mV
Capacity (warn):        2025 mWh
Capacity (low):         200 mWh
Low/warn granularity:   1 mWh
Warn/full granularity:  1 mWh
Model number:           45N1147
Serial number:            340
Type:                   LION
OEM info:               LGC
State:                  high
Remaining capacity:     79%
Remaining time:         unknown
Present rate:           0 mW
Present voltage:        11702 mV`


----------



## aragats (Jul 11, 2021)

ksiu said:


> The battery level is stuck at 79%. It is neither going up or down. Wierd. I expect it to charge up to 85% and stop.


That's correct, you set the "bottom" limit to 75%, it won't start charging until it goes below 75%. That's the expected behavior.


----------



## ksiu (Jul 11, 2021)

Fuzzbox said:


> Read my previous post again
> 
> Charge stop threshold : the threshold your battery won't exceed when it's charging.
> Charge start threshold : the threshold you have to reach before your battery starts charging again.
> ...



Ok, solved.  After reading the above by Fuzzbox, I think mine is working as intended.

So, when the battery is between the levels defined by "charge start" and "charge stop", the battery will still be charging but at a reduced rate (with just enough A/C juice to maintain the current battery level).


----------



## ksiu (Jul 11, 2021)

As someone who keeps his laptop near AC outlet 99% of the time, I am set start threshold and stop threshold to 50 and 60, respectively.  I read somewhere it is best to keep Lithium battery in this range, to maximum battery longevity.

Question:  is there a way to disable this threshold temporarily (allow the battery to charge to 100%)?


----------



## Fuzzbox (Jul 11, 2021)

ksiu said:


> Question: is there a way to disable this threshold temporarily (allow the battery to charge to 100%)?


No such option afaik (tlp indeed has it on Linux with the tlp fullcharge command). I did not manage to trigger a temporary full charge with acpi_call on FreeBSD.
You can only set new thresholds, like 98 start / 99 stop, to get a full charge. I guess we could script that to make it easier...


----------



## ksiu (Jul 30, 2021)

Fuzzbox said:


> Removing the battery resets the battery controller on some Thinkpads.



It looks like removing the battery on my T440P does NOT reset the battery controller.

Is 0 and 100 the default values for the controller?

`acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCCS' -i 0

acpi_call -p '\_SB_.PCI0.LPC_.EC__.HKEY.BCSS' -i 100`


----------



## Fuzzbox (Aug 1, 2021)

Afair, accepted values are between 0 and 99.


----------

