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

Wattage not showing when multiple batteries used #5

Open
blacktoz opened this issue Aug 16, 2024 · 24 comments
Open

Wattage not showing when multiple batteries used #5

blacktoz opened this issue Aug 16, 2024 · 24 comments

Comments

@blacktoz
Copy link

hey ! I have a Thinkpad T580 which have two batteries, one external, that I can "hotswap", and the other which is internal.
While using the secondary battery, which is used in priority when plugged in, it doesn't show the wattage on the plasmoid. When removing it, it does show the battery wattage for the internal battery.

ls /sys/class/power_supply/ returns :
AC BAT0 BAT1 ucsi-source-psy-USBC000:001 ucsi-source-psy-USBC000:002

Kernel : 6.9.10-arch1-1
Plasma : 6.1.3
Using Wayland

ask me whatever you need else !
Thanks!

@magillos
Copy link
Owner

Could you check testing.plasmoid from main Github page?

@blacktoz
Copy link
Author

Hey! so this does work, but it creates a problem now, when unplugging the external battery to use the internal one, it works fine, but when plugging the battery back, the laptop doesn't recognize the external battery and needs a reboot. When trying this while the testing plasmoid uninstalled, it does work as expected, no need for a reboot to change a battery

@magillos
Copy link
Owner

Can you check testing1.plasmoid? When testing in Plasma, make sure to run plasmashell --replace after installing and adding widget. If you still have issues, could you try running it with QT_LOGGING_RULES="qt.qml.connections=true" plasmoidviewer --applet testing1.plasmoid and let me know if it spits out anything useful.

@blacktoz
Copy link
Author

hmmm, the testing1.plasmoid doesn't want to install, also seems like it is lighter than the others
image

@magillos
Copy link
Owner

My bad. Try testing2.plasmoid

@blacktoz
Copy link
Author

Now it seems to be stuck on "Reading Current" because it tries reading "current_now" but isn't there on the BAT0 and BAT1 directories
image

@magillos
Copy link
Owner

How about testing3.plasmoid?

@blacktoz
Copy link
Author

It only spams this in the logs with no readouts
image
Cannot run with plasmoidviewer since I cannot directly use a .plasmoid

@magillos
Copy link
Owner

It's going to be tricky. Everything works well on my side with those changes, but I only have one battery. And as I stated in readme, I used LLMs to make this widget. So there is that. I have one more idea. It's ugly but maybe it works. Try testing4.plasmoid.

@blacktoz
Copy link
Author

yeah, totally understand that. So it does show the power status when both batteries are connected, when unplugging the external battery, it shows false reading, and in the logs, it shows that it is still trying to read the BAT1
image

@blacktoz
Copy link
Author

when relaunching plasmashell, it does show accurate readings, and putting in the battery again, it recognizes it, and gives again accurate readings

@blacktoz
Copy link
Author

I didn't mention that, but to swap the battery, I need to suspend the computer, close the lid, and remove the battery, I cannot swap the battery without suspending it, it will shutdown

@magillos
Copy link
Owner

All good then? I will have to consider if I want to add this version to KDE Store though. I wouldn't want to break anything for other devices.
It's now summing up power usage from both power_now files (in BAT0 and BAT1). Assuming one of the batteries will always show "0", the reading should be accurate. But it's not very elegant.

If you could also test it with and without external battery, with unplugged and plugged chargers for each configuration, to make sure it works well in all instances.

@blacktoz
Copy link
Author

well yes and no, if I put the battery again, I will need to relaunch plasmashell in order to get accurate readings, if I don't, I will get values like : 15W or 16W, but in powertop and energy informations on plasma shows me that I consume like 7.5W, like the picture I sent above

@magillos
Copy link
Owner

My guess is Plasma has a reading from main battery cached, and with external battery inserted the reading is doubled. To fix it, Claude AI added timer which surely isn't the right way to do it but you can have a go at it with testing5.plasmoid

@blacktoz
Copy link
Author

ahah, so now, when I remove the battery, it gives the false readings for the internal battery, but putting the battery in it again does show good readings, but something is weird, because when I put the battery in, the computer takes like 1 minute to use the external battery in priority, but within this minute, it still uses the internal battery, which is normal, but it is giving good readings for the internal battery, which shouldn't because just before it was giving false readings. after the minute passes and switches to the external battery, it shows also the good readings..

Sorry if something is wrong in the way i've written this, I don't know how to give a great explanation of what's happening

@magillos
Copy link
Owner

I thought timer won't work well here. Version 4 would be the best for now.

I still would like to try fixing it properly.
Do you always have both directories present (/sys/class/power_supply/BAT0 and /sys/class/power_supply/BAT1), regardless if you attach extra battery?
If yes, do they both have power_now files present, with or without external battery attached?
Do you have "present" file in each directory?

@blacktoz
Copy link
Author

If I have both batteries :
BAT0 and BAT1 are present
BAT0 power_now : 0
BAT0 present : 1

BAT1 power_now : 7725000
BAT1 : present : 1

Now, if I remove BAT1, which is the external battery :
BAT0 power_now : 6594000
BAT0 present : 1

BAT1 directory disappears when external battery is removed

@blacktoz
Copy link
Author

When I replug the battery,
BAT1 present : 1
BAT1 power_now : 0

after waiting a minute so that the computer switches to external battery
BAT1 present : 1
BAT1 power_now : 11786000

@magillos
Copy link
Owner

You can try version 6 but I don't know if it's going to work. I tried something simpler this time.

@blacktoz
Copy link
Author

nope, now even after plugging the battery again, it gives me false readings, as well as with only one battery connected

@magillos
Copy link
Owner

magillos commented Aug 17, 2024

I'll give it likely the last try with versions 7, 8 and 9. 7 uses timer and for version 8 and 9 I asked Claude to use functions from original Plasma 5 widget that supported 2 batteries well, AFAIK. But at this point, I'm running out of ideas/prompts and I'm afraid I'm lacking knowledge how to fix this. If none of this works, maybe you could use version 4 as it works best.

@blacktoz
Copy link
Author

yeah I think I'll use the version 4, the version 7 gives me weird readouts, and 8 and 9 are stuck onto reading the values..
I'll try to make it myself, I don't have any knowledge but who knows, I may know how to fix it :)
Thanks for the help!

@magillos
Copy link
Owner

Good luck and if you find a fix share it here so we could maybe include that in the widget. Unfortunately version 4 doesn't seem to be working on one of my laptops, so at least for now I won't be making it official.

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

No branches or pull requests

2 participants