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

error on huawei matebook d16 2022 #10

Closed
mascherm opened this issue Mar 20, 2023 · 23 comments
Closed

error on huawei matebook d16 2022 #10

mascherm opened this issue Mar 20, 2023 · 23 comments
Labels
bug Something isn't working solved

Comments

@mascherm
Copy link

mascherm commented Mar 20, 2023

thank you for this nice extension but i cant get it to work on my matebook d16 2022. it always says "Battery Health Charging encountered an unexpected error.".
Bildschirmfoto vom 2023-03-20 15-45-16

@maniacx
Copy link
Owner

maniacx commented Mar 20, 2023

Do you have this sysfs path?
/sys/devices/platform/huawei-wmi/charge_thresholds

You can test by ls command in terminal

ls -l /sys/devices/platform/huawei-wmi/charge_thresholds
Let me know what is the result

@mascherm mascherm changed the title error on huawei matebook d15 2022 error on huawei matebook d16 2022 Mar 20, 2023
@mascherm
Copy link
Author

no such file or directory.

@maniacx
Copy link
Owner

maniacx commented Mar 20, 2023

Which Linux distro do you use?
Are you able to set battery threshold using command line or any any other app in Linux?

@mascherm
Copy link
Author

mascherm commented Mar 20, 2023

ubuntu. i found a file called "charge_control_thresholds" in this folder. when i write "0 75" in it it stops charging at 75% for example.

edit: ok, it worked with "0 60" now with "0 75" it does not seem to work, with 60 it stopped at 59% but now with 75 it already charged to 76%

@maniacx
Copy link
Owner

maniacx commented Mar 20, 2023

Oh. Seems like I was using the older sysfs path.
I will add the new sysfs path.. in my next update.

/sys/devices/platform/huawei-wmi/charge_control_thresholds

Just to confirm are you using the above path to set charge threshold?

Did you try setting a any other custom value besides zero. Such as 50 60?

echo '50 60' | sudo tee /sys/devices/platform/huawei-wmi/charge_control_thresholds

Apologies if there are any typo's commenting using mobile.

@mascherm
Copy link
Author

path is correct, i will try different values tomorrow and come back to you, i have to discharge it first.

@maniacx
Copy link
Owner

maniacx commented Mar 21, 2023

I was reading this issue.
aymanbagabas/Huawei-WMI#55

From what I understand ( I could be wrong)

  • Huawei a year back introduce smart charging feature via bios update.
  • Smart charging will apply threshold automatically based on device condition.
  • If smart charging is enabled then custom threshold values will be ignored.
  • Smart charging can be turned OFF in bios.
  • Setting custom a threshold values of "0" to start or end threshold will automatically turn ON smart charging

You can check in bios if you have the smart charging and turn it off.
Then you can turn try to apply custom threshold but it should not be '0'
Also i f you are dual booting windows I do not know if smart charge charging will enable again and if there is a way to disable it

Also if you do not have smart charging feature I would recommend you to set it above 40-50 and definately not use 0
Reason:

  • I have checked most manufacturer use end threshold in the range of 80 to 50% and the difference between start and end threshold is not more than 10% . (for example if end is 60 the start would be 50). Although seems like huawei is the only brand who has 1 mode with threshold 40-70.
  • To avoid degrading the battery, Manufacturer always recommend not to discharge battery more that 20%
  • if you set start threshold to '0' and if your battery reaches near 0% and you lose power/or unplug the charging, there are chances that your laptop my just shutdown and you lose any unsaved data

Test everything and let me know what you find. I will update the extension accordingly.

@mascherm
Copy link
Author

mascherm commented Mar 21, 2023

i found no option in bios to disable smart charge, bios is very limited on this device. i am dual booting and in windows there is a software called huawei pc manager where i can activate smart charge or set the stop charging treshold to 50%, 60%, 70%, 80%, 90% or 100%.
under smart charge it says that it will just hold the battery at 70% when plugged in a long time or battery temperature too high.

i did some testing with 50 60, 60 70, 70 80, 60 78 and 40 76

it always charged to 1% under the end treshold, stopped charging and stayed there. under gnome settings -> energy it changes from "charging" to "not charging", when i unplug it just tells me the time remaining on battery.

the first time when i plugged the ac in at around 63% with settings set 60 70 it discharged to 60 and stayed there. but i couldnt reproduce this. all the other times it charged to 69% and stayed there.

it only starts discharging when for example i set 70 80 and battery stopped at 79% and then i change it to for example 60 78 and it starts discharging to 78 and stays there.

@maniacx
Copy link
Owner

maniacx commented Mar 22, 2023

it always charged to 1% under the end treshold, stopped charging and stayed there. under gnome settings -> energy it changes from "charging" to "not charging", when i unplug it just tells me the time remaining on battery.

This is normal behavior. The 1% error is also I would say is an accepted value.

the first time when i plugged the ac in at around 63% with settings set 60 70 it discharged to 60 and stayed there. but i couldnt reproduce this. all the other times it charged to 69% and stayed there.

This is a strange issue. No idea what is the reason behind this.

it only starts discharging when for example i set 70 80 and battery stopped at 79% and then i change it to for example 60 78 and it starts discharging to 78 and stays there.

This too is a normal expected behaviour when start and end threshold are set.

Kindly test this extesnion, I have added the correct sysfs file path.
Battery-Health-Charging_Huawei_trial1.zip

Extract and open terminal in the extracted folder. Run ./install.sh
Restart shell (logout -relogin for wayland or Alt-F2 and type 'r' on X-11)
Let me know if the extension works.
As the extension only applies threshold using commandline and the rest is done by the kernel. Just check the if threshold are applied on cmdline level,

cat /sys/devices/platform/huawei-wmi/charge_control_thresholds

@mascherm
Copy link
Author

it only starts discharging when for example i set 70 80 and battery stopped at 79% and then i change it to for example 60 78 and it starts discharging to 78 and stays there.

This too is a normal expected behaviour when start and end threshold are set.

my fault, i thought when set for example 50 60 it would charge to 60 and then discharge to 50 and do this again and again.

i got the unexpected error when i turned trial1 version on the first time, the threshold was 0 0 when i looked in the file. i changed it to 50 60 in terminal and turned your extension on again and it seems to work now.

i can change tresholds. but when i change from balanced (80 75) to maximum lifespan (60 55) mode i get no notification like normal and it only changes the start charging treshold to 55. so i get 80 55 instead of 60 55. when i try to set it again to maximum lifespan mode it changes to the correct values and i get the notification. this also happens from full capacity mode to balanced mode where i get 75 100 the first try. the second try it sets the values correctly to 75 80.

@maniacx
Copy link
Owner

maniacx commented Mar 23, 2023

Strange. I just tried it using a dummy file it seem to update the both start and end threshold values.
It could be the kernel taking some time to update and the extension is reading the value before it is updated.

Could you do few test for me.
Test no 1.

  • Set a threshold value using the extension. ignore any error message or no notifcation issue by the extension.
  • Then check using cat in terminal if the values are updated.
    cat /sys/devices/platform/huawei-wmi/charge_control_thresholds

Repeat the test for all 3 modes.
If both start and end threshold are updated and equal to the what you have set in the extension, Then try test 2

use both echo and cat in 1 command

echo '50 60' | sudo tee /sys/devices/platform/huawei-wmi/charge_control_thresholds && cat /sys/devices/platform/huawei-wmi/charge_control_thresholds
this will output two line result. First line result are from echo and second line results are from cat. both line should ahve the same results.

Try 3 different sets of values. and let me know what are the results.

@maniacx
Copy link
Owner

maniacx commented Mar 23, 2023

Another question. Are you using any additional custom kernel module? Such as https://github.com/aymanbagabas/Huawei-WMI

Or is it the default Ubuntu kernel?
Also what is your kernel version?

@mascherm
Copy link
Author

* Set a threshold value using the  extension. ignore any error message or no notifcation issue by the extension.

* Then check using cat in terminal if the values are updated.
  `cat /sys/devices/platform/huawei-wmi/charge_control_thresholds`

full capacity mode gives me 95 100
balanced mode gives me 75 100
maximum lifespan mode gives me 55 100

only when i select the mode a second time the stop charging value also sets correctly.

Repeat the test for all 3 modes. If both start and end threshold are updated and equal to the what you have set in the extension, Then try test 2

use both echo and cat in 1 command

echo '50 60' | sudo tee /sys/devices/platform/huawei-wmi/charge_control_thresholds && cat /sys/devices/platform/huawei-wmi/charge_control_thresholds this will output two line result. First line result are from echo and second line results are from cat. both line should ahve the same results.

Try 3 different sets of values. and let me know what are the results.

i tried 3 different values and echo and cat results are the same.

Another question. Are you using any additional custom kernel module? Such as https://github.com/aymanbagabas/Huawei-WMI
Or is it the default Ubuntu kernel?
Also what is your kernel version?

i dont use custom kernel modules, i am on 6.2.7 but i also tried it with ubuntus latest 5.19.0.38 which gives me the same results.

@maniacx
Copy link
Owner

maniacx commented Mar 23, 2023

On last test.
Can you set the threshold using command line again echo with the same value in the same order.

First echo 95 100
Verify using cat
Then echo 75 80
Verify using cat
Then echo 55 60
Verify using cat

@mascherm
Copy link
Author

test

like this?

@maniacx
Copy link
Owner

maniacx commented Mar 24, 2023

Yes. Ok there is no issues with kernel or your system, but my extension. Need to figure out by trial.
My extension changes threshold like this in trial1
echo "50 60" > /sys/devices/platform/huawei-wmi/charge_control_thresholds

I have changed it to this in trial2
echo "50" "60" > /sys/devices/platform/huawei-wmi/charge_control_thresholds

[email protected]

If it work then good. If it doesnt the send me the logs

  • plz disable the extension.
  • in terminal to get the logs
    journalctl -f -o cat /usr/bin/gnome-shell
  • Then enable the extension and any logs starting with "Battery Health Charging" copy and paste it here.

@mascherm
Copy link
Author

mascherm commented Mar 24, 2023

same issue, here is the log. i started at full, clicked balanced, clicked balanced a second time, clicked lifespan, clicked lifespan a second time. clicked blanced, clicked full.

Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=100
Battery Health Charging: ARG2=95

Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=80
Battery Health Charging: ARG2=75

Battery Health Charging: Error threshold values not updated
Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=80
Battery Health Charging: ARG2=75

Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=60
Battery Health Charging: ARG2=55

Battery Health Charging: Error threshold values not updated
Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=60
Battery Health Charging: ARG2=55

Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=80
Battery Health Charging: ARG2=75

Battery Health Charging: Battery Health Charging: DEVICECMD=BAT0_END_START
Battery Health Charging: ARG1=100
Battery Health Charging: ARG2=95

just noticed that going full -> balanced -> lifespan hast the problem but going lifespan -> balanced -> full works just fine.

@maniacx
Copy link
Owner

maniacx commented Mar 24, 2023

The extension it not using the correct path to change threshold
/sys/devices/platform/huawei-wmi/charge_control_thresholds

Instead extension is using
/sys/class/power_supply/BAT0/charge_control_end_threshold
And
/sys/class/power_supply/BAT0/charge_control_start_threshold

Huawei has two way of setting threshold, but the recommended way is using charge_control_threshold

I will fix this issue first to force it to use charge_control_threshold

@maniacx
Copy link
Owner

maniacx commented Mar 25, 2023

Please test trial 4. It should work.
[email protected]_trial4.zip

If not test trial5.
Battery-Health-Charging@maniacx.github.com.shell-extensiontrial5.zip

If both not working send me log of trial 4

@maniacx
Copy link
Owner

maniacx commented Mar 25, 2023

Sorry about this. ignore trial4 .logs are not enabled trial4 and 5

test trial6 instead.

if 6 fails. test trial5.

if trial5 fails too then install trial6 again and send me the log. if trial 6 works no logs needed.

[email protected]_trial6.zip

@mascherm
Copy link
Author

i tried trial6 and it works perfectly. thank you again for your work!

@maniacx
Copy link
Owner

maniacx commented Mar 26, 2023

Thanks for support helping me fix it.

@maniacx maniacx closed this as completed Mar 26, 2023
@maniacx
Copy link
Owner

maniacx commented Mar 26, 2023

Hello mascherm. When you have free time could you test this new version.

Link here #11

@maniacx maniacx reopened this Mar 26, 2023
@maniacx maniacx closed this as completed Mar 28, 2023
@maniacx maniacx added bug Something isn't working solved labels May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working solved
Projects
None yet
Development

No branches or pull requests

2 participants