Lenovo T440s battery status unknown, but charging?
This is a common issue with Thinkpad laptops with dual batteries.
When you plug in your laptop it will start by charging BAT0 while BAT1 reports a unknown state. BAT1 will report a charging state when BAT0 is full and BAT1 actually starts charging.
You need to take this into account in your script, and combine values for BAT0 and BAT1 to have something usable :
battery_level=$(("$battery_level_0 + $battery_level_1"))
battery_max=$(("$battery_max_0 + $battery_max_1"))
battery_percent=$(("$battery_level * 100"))
battery_percent=$(("$battery_percent / $battery_max"))
Here is a full example :
#!/bin/sh
path_ac="/sys/class/power_supply/AC"
path_battery_0="/sys/class/power_supply/BAT0"
path_battery_1="/sys/class/power_supply/BAT1"
ac=0
battery_level_0=0
battery_level_1=0
battery_max_0=0
battery_max_1=0
if [ -f "$path_ac/online" ]; then
ac=$(cat "$path_ac/online")
fi
if [ -f "$path_battery_0/energy_now" ]; then
battery_level_0=$(cat "$path_battery_0/energy_now")
fi
if [ -f "$path_battery_0/energy_full" ]; then
battery_max_0=$(cat "$path_battery_0/energy_full")
fi
if [ -f "$path_battery_1/energy_now" ]; then
battery_level_1=$(cat "$path_battery_1/energy_now")
fi
if [ -f "$path_battery_1/energy_full" ]; then
battery_max_1=$(cat "$path_battery_1/energy_full")
fi
battery_level=$(("$battery_level_0 + $battery_level_1"))
battery_max=$(("$battery_max_0 + $battery_max_1"))
battery_percent=$(("$battery_level * 100"))
battery_percent=$(("$battery_percent / $battery_max"))
if [ "$ac" -eq 1 ]; then
plug=""
echo "$plug $battery_percent %"
else
if [ "$battery_percent" -gt 95 ]; then
echo ""
elif [ "$battery_percent" -gt 85 ]; then
icon=""
elif [ "$battery_percent" -gt 60 ]; then
icon=""
elif [ "$battery_percent" -gt 35 ]; then
icon=""
elif [ "$battery_percent" -gt 10 ]; then
icon=""
else
icon=""
fi
echo "$icon $battery_percent %"
fi
Related videos on Youtube
Aqyr
Updated on September 18, 2022Comments
-
Aqyr almost 2 years
I'm trying to configure my Lenovo on arch linux. The last thing I need to do is get the battery 100% working.
Right now it appears that the main battery's state is unknown:
> acpi -V Battery 0: Unknown, 97% Battery 0: design capacity 5849 mAh, last full capacity 5956 mAh = 100% Battery 1: Charging, 96%, 00:05:50 until charged Battery 1: design capacity 1861 mAh, last full capacity 1536 mAh = 82% Adapter 0: on-line Thermal 0: ok, 43.0 degrees C Thermal 0: trip point 0 switches to mode critical at temperature 200.0 degrees C Cooling 0: x86_pkg_temp no state information available Cooling 1: intel_powerclamp no state information available Cooling 2: Processor 0 of 10 Cooling 3: Processor 0 of 10 Cooling 4: Processor 0 of 10 Cooling 5: Processor 0 of 10
But if I query the battery directly I get a completely different response:
> cat /sys/class/power_supply/BAT0/status Charging > cat /sys/class/power_supply/BAT0/uevent POWER_SUPPLY_NAME=BAT0 POWER_SUPPLY_STATUS=Charging POWER_SUPPLY_PRESENT=1 POWER_SUPPLY_TECHNOLOGY=Li-ion POWER_SUPPLY_CYCLE_COUNT=0 POWER_SUPPLY_VOLTAGE_MIN_DESIGN=11100000 POWER_SUPPLY_VOLTAGE_NOW=12389000 POWER_SUPPLY_POWER_NOW=0 POWER_SUPPLY_ENERGY_FULL_DESIGN=23200000 POWER_SUPPLY_ENERGY_FULL=19150000 POWER_SUPPLY_ENERGY_NOW=19050000 POWER_SUPPLY_CAPACITY=99 POWER_SUPPLY_CAPACITY_LEVEL=Normal POWER_SUPPLY_MODEL_NAME=45N1773 POWER_SUPPLY_MANUFACTURER=SANYO POWER_SUPPLY_SERIAL_NUMBER=16120
I'm at a complete loss as to what to do here. I have a script reporting battery life that runs off of the output of some of these commands and I would like it to be as complete as possible. Clearly the battery is charging, but why would acpi -V say it's unknown? Does anyone know?
-
Mathias Rav over 7 yearsI see roughly the same on my T460s. I think the two batteries take turns charging/discharging; currently my BAT0 is "Charging, 98%, 00:04:52 until charged", and my BAT1 is "Unknown, 79%", according to acpi. Laptop-mode-tools reports "You have a broken battery. Cannot determine actual state", but UPower has a heuristic to determine that the actual state of the battery is "Charging".
-
ddnomad about 5 yearsIf the laptop has only a single battery there are only 2 possible states: "discharging" and "charging" (and, well, "charged 100%"). When a laptop has 2 batteries it may use just one of them, then a state of a second battery would be deemed "unknown" (as it's neither charging nor discharging). I have the same thing happening with my Thinkpad X250 so I presume that's an expected behaviour.
-