Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong battery percentage and status #137

Closed
manuelmazzuola opened this issue Jan 12, 2018 · 27 comments
Closed

Wrong battery percentage and status #137

manuelmazzuola opened this issue Jan 12, 2018 · 27 comments
Labels

Comments

@manuelmazzuola
Copy link

The battery status and level are not correct.
Status bar report that battery is discarching and level is stuck on 48%.

image

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

Which OS are you using?

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Jan 12, 2018

acpi -V
Battery 0: Charging, 100%,  until charged
Battery 0: design capacity 7570 mAh, last full capacity 5582 mAh = 73%

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Jan 12, 2018

I'm using Archlinux
Linux manuel-xps 4.14.12-1-ARCH #1 SMP PREEMPT Fri Jan 5 18:19:34 UTC 2018 x86_64 GNU/Linux

lsb_release -a
LSB Version:    1.4
Distributor ID: Arch
Description:    Arch Linux
Release:        rolling
Codename:       n/a

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

sigh

It seems to me the kernel exposes charge_full and charge_now pseudo files while my configuration expects energy_full and energy_now.

Can you locally modify ~/.tmux.conf and do the replacement and confirm this is the problem?

@manuelmazzuola
Copy link
Author

Made this change and reloaded but nothing has changed.

263,264c263,264
< #           bat_energy_full="$batpath/charge_full"
< #           bat_energy_now="$batpath/charge_now"
---
> #           bat_energy_full="$batpath/energy_full"
> #           bat_energy_now="$batpath/energy_now"

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

I would have replaced all energy_full by charge_full, same for energy_now

@manuelmazzuola
Copy link
Author

Others occurrences are just variables names, anyway I've replaced all and the result is the same.

diff --git a/.tmux.conf b/.tmux.conf
index 1a494f7..5df46ff 100644
--- a/.tmux.conf
+++ b/.tmux.conf
@@ -260,10 +260,10 @@ run 'cut -c3- ~/.tmux.conf | sh -s _apply_configuration'
 #         if [ -r "$bat_capacity" ]; then
 #           charge=$(awk -v charge="$charge" -v capacity="$(cat "$bat_capacity")" 'BEGIN { print charge + capacity
/ 100 }')
 #         else
-#           bat_energy_full="$batpath/energy_full"
-#           bat_energy_now="$batpath/energy_now"
-#           if [ -r "$bat_energy_full" ] && [ -r "$bat_energy_now" ]; then
-#             charge=$(awk -v charge="$charge" -v energy_now="$(cat "$bat_energy_now")" -v energy_full="$(cat "$bat_energy_full")" 'BEGIN { print charge + energy_now / energy_full }')
+#           bat_charge_full="$batpath/charge_full"
+#           bat_charge_now="$batpath/charge_now"
+#           if [ -r "$bat_charge_full" ] && [ -r "$bat_charge_now" ]; then
+#             charge=$(awk -v charge="$charge" -v charge_now="$(cat "$bat_charge_now")" -v charge_full="$(cat "$bat_charge_full")" 'BEGIN { print charge + charge_now / charge_full }')
 #           fi
 #         fi

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

Yeah I expected to just be variable names but I didn't take the time to review the implementation carefully.

Well what you can do is try to is $ cat /sys/class/power_supply/BAT0/charge_now and $ cat /sys/class/power_supply/BAT0/charge_full to see the output. The ratio of the two value is what I use to compute the charging percentage.

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

Also, running $ cut -c3- ~/.tmux.conf | sh -sx _battery() should give a very verbose log of what's going on

@manuelmazzuola
Copy link
Author

These numbers don't add up.

$ cat /sys/class/power_supply/BAT0/charge_now
7570000
$ cat /sys/class/power_supply/BAT0/charge_full
5582000

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

But in fact you have /sys/class/power_supply/BAT0/capacity and that's what I'm using when present.

What's the content of that pseudo file?

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

Also how many batteries do you have?

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Jan 12, 2018

I have just one battery BAT0

$ ls /sys/class/power_supply
AC  BAT0  hidpp_battery_0  hidpp_battery_1
$ cat /sys/class/power_supply/BAT0/capacity
135

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Jan 12, 2018

All the BAT0 pseudo files values.

POWER_SUPPLY_NAME=BAT0
POWER_SUPPLY_STATUS=Full
POWER_SUPPLY_PRESENT=1
POWER_SUPPLY_TECHNOLOGY=Li-poly
POWER_SUPPLY_CYCLE_COUNT=0
POWER_SUPPLY_VOLTAGE_MIN_DESIGN=7600000
POWER_SUPPLY_VOLTAGE_NOW=8696000
POWER_SUPPLY_CURRENT_NOW=1000
POWER_SUPPLY_CHARGE_FULL_DESIGN=7570000
POWER_SUPPLY_CHARGE_FULL=5582000
POWER_SUPPLY_CHARGE_NOW=7570000
POWER_SUPPLY_CAPACITY=135
POWER_SUPPLY_CAPACITY_LEVEL=Full
POWER_SUPPLY_MODEL_NAME=DELL JHXPY53
POWER_SUPPLY_MANUFACTURER=SMP

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

As per https://www.kernel.org/doc/Documentation/power/power_supply_class.txt

~ ~ ~ ~ ~ ~ ~  Charge/Energy/Capacity - how to not confuse  ~ ~ ~ ~ ~ ~ ~
~                                                                       ~
~ Because both "charge" (µAh) and "energy" (µWh) represents "capacity"  ~
~ of battery, this class distinguish these terms. Don't mix them!       ~
~                                                                       ~
~ CHARGE_* attributes represents capacity in µAh only.                  ~
~ ENERGY_* attributes represents capacity in µWh only.                  ~
~ CAPACITY attribute represents capacity in *percents*, from 0 to 100.  ~
~                                                                       ~
~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~

Having a capacity value of 135 likely means your kernel and/or battery driver/firmware (if such a thing exists) is broken.

@manuelmazzuola
Copy link
Author

@gpakosz
Copy link
Owner

gpakosz commented Jan 12, 2018

Somewhat, in your results POWER_SUPPLY_CHARGE_FULL never reached POWER_SUPPLY_CHARGE_FULL_DESIGN while POWER_SUPPLY_CHARGE_NOW does.

This is bogus 😐

Maybe you can try to gather more information with the Archlinux people?

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Jan 12, 2018

I've just opened a 3d on the arch forum.

@manuelmazzuola
Copy link
Author

Fixed by replacing energy_* with charge_* and discharging and charging completely the battery https://bbs.archlinux.org/viewtopic.php?pid=1760749#p1760749

@gpakosz
Copy link
Owner

gpakosz commented Jan 13, 2018

Good to know. In your case, since you have a capacity pseudo file, replacing energy_xxx with charge_xxx doesn't change anything.

I think I'll just leave it as is until someone really doesn't have either capacity or energy_xxx pseudo files.

@gpakosz
Copy link
Owner

gpakosz commented Jan 13, 2018

Are we good?

@manuelmazzuola
Copy link
Author

Sure 👍

@manuelmazzuola
Copy link
Author

manuelmazzuola commented Jan 15, 2018

Last thing about the battery indicator, I've chosen the heat palette but when the battery is low the percentage is barely visible.
tmux_conf_battery_bar_palette='heat'
image

@gpakosz
Copy link
Owner

gpakosz commented Jan 15, 2018

Agreed, but can you please open a dedicated issue?

@gpakosz gpakosz closed this as completed Jan 15, 2018
@szaffarano
Copy link

szaffarano commented May 24, 2018

I have a wireless keyboard and a wireless mouse, both of them expose a battery device that makes an incorrect battery status level. If I exclude /sys/class/power_supply/hidpp_battery_* in line 271 of tmux.conf:

 271 # $(find /sys/class/power_supply -maxdepth 1 -iname '*bat*')

the status level is ok. May be you can exclude devices with scope=Device?

$ cat /sys/class/power_supply/hidpp_battery_2/scope    
Device

Thanks

@gpakosz
Copy link
Owner

gpakosz commented May 24, 2018

Hello @szaffarano

Could you please open a dedicated issue? Can you also list everything in /sys/class/power_supply/hidpp_battery_2/ please?

@szaffarano
Copy link

Done, issue #161 created

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants