zackelia / bclm

macOS command-line utility to limit max battery charge
MIT License
1.89k stars 92 forks source link

keyNotFound(code: "CHWA") #49

Open Tackoil opened 3 months ago

Tackoil commented 3 months ago

After updating the macOS 15.0 beta 5, bclm is not working well. Running read or write will get an error (maybe) following.

keyNotFound(code: "CHWA")

I know that using the beta version of macOS is my own risk. Creating this issue is just for a notice about this change.

ftpd commented 3 months ago

I experience the same issue - just for the record.

Zw96042 commented 3 months ago

I'm also experiencing this issue

IShinji commented 3 months ago

same

CalebMtuwetaM commented 3 months ago

I have the same issue

zackelia commented 3 months ago

Ouch, not sure what we can do without it. Unless this was accidental, we'll just have to wait and see what replacement key (if there will be one) can do the same trick. Before, we learned about CHWA from the Asahi SMC driver so we'll see what findings they have soon I assume: https://github.com/AsahiLinux/linux/blob/asahi/drivers/power/supply/macsmc_power.c

yanzhem02 commented 3 months ago

I updated my system to 15.1 beta 2 and encounter the same issue.

TrainerBlade commented 3 months ago

same error message. using MacOS 15.0 beta (24A5320a)

samzong commented 3 months ago

same with me. Version 15.1 Beta (24B5024e)

TimNN commented 3 months ago

Asahi now seems to have changes for the latest firmware: https://github.com/AsahiLinux/linux/commit/c6ccbdd693e7d0944642064aa5df1010fe29c35d

zackelia commented 3 months ago

@TimNN Good eye! I'll install Sequoia on another volume and test that out.

GimmiGoose commented 3 months ago

Got this too on 15.1 I am using AlDente until it gets fixed, but will definitely switch back once it is fixed, because I prefer a more "native" solution.

TimNN commented 3 months ago

When trying to manually write to (or read from) CHLS (via smc), I'm getting kIOReturnNotPrivileged:

$ sudo smc -k CHLS -w 0150
Error: SMCWriteKey() = e00002c1

Disabling SIP didn't seem to help either...

zackelia commented 3 months ago

Getting the same error even just reading CHLS. From Console:

kernel    SMCC::smcYPCEventCheck ERROR: not entitled for key CHLS

Not really sure what entitlement I need to sign with to get access to this key. com.apple.private.applesmc.user-access stood out to me but I can't sign with that one.

TimNN commented 3 months ago

Ugh, this is very sad. I guess the only options are:

sibilus commented 2 months ago

CHWA is also gone on macOS Sonoma 14.7. I seem to be able to read and write CHLS though, but I'm not sure how it's supposed to function as nothing seems to happen when I change it.

thaff786 commented 2 months ago

https://github.com/lslqtz/bclm_loop/tree/main

Fork of BCLM called BCLM_Loop which I can confirm does work on Sequoia 15.0 release. It installs and can be enabled pretty much in the same fashion as the original BCLM.

Under the hood it may not be as clean or elegant as the original BCLM as it runs in a loop as a background service (as opposed to writing to the SMC), but it still does the job 100% as far as I can tell so far with no impact on battery life when unplugged.

Still hoping the original BCLM can be fixed though.

TimNN commented 2 months ago

@sibilus: Which value did you try to write? Based on the Asahi code, setting CHLS to 0150 (hexadecimal) should have a similar behavior to setting CHWA to 1.

(The 01 apparently means "discharge down to target percentage" and 50 is the target percentage, in this case 80%).

anqut commented 2 months ago

I'm getting the same error, after updating to macOS 15.0

zackelia commented 2 months ago

This is great news if people are able to read/write CHLS! Something must've changed since the last beta if the entitlement isn't necessary anymore? I'll be able to test it out again in a few days.

TimNN commented 2 months ago

@zackelia: The success report was for "macOS Sonoma 14.7", so I have very little hope that this is going to work on 15.0.

I assume that 14.7 got the firmware update with CHLS, but the entitlement protections were only implemented in 15.0.

On the 15.0 release (24A335)) I still cannot write CHLS. I'll be testing this on all future releases as well, of course, but have relatively little hope.

sibilus commented 2 months ago

@TimNN: I've tried 0150 on 14.7, but it doesn't seem to work, unfortunately.

wpiekutowski commented 2 months ago

I tried CHLS with 0150 and 0100 (which seems to be supposed to cause discharge) on 14.7, but both values unfortunately do nothing.

I'm turning on builtin "Optmized battery charging" and I'll see if they maybe improved it.

yuukiyuuna commented 2 months ago

in macos 15.0 not work

ryudexter commented 2 months ago

My OCD is going nuts seeing the battery icon go to %81 😅 Really hope this can be a fix for this awesome application 🙏🏻

emmaus-zam commented 2 months ago

My OCD is going nuts seeing the battery icon go to %81 😅 Really hope this can be a fix for this awesome application 🙏🏻

agreed! for anyone struggling with this I found the free version of AlDente to be an adequate replacement. It's inferior since not a native solution, so hopefully it's only temporarily needed.

myTerminal commented 2 months ago

agreed! for anyone struggling with this I found the free version of AlDente to be an adequate replacement. It's inferior since not a native solution, so hopefully it's only temporarily needed.

I tried it, and it does seem to work even without a reboot. Now we just have to wait for a fix, but have something to use till then.

Immortalin commented 2 months ago

I am pretty sure they have the same issue

https://github.com/AppHouseKitchen/AlDente-Charge-Limiter/issues/1326

sozercan commented 2 months ago

I changed to use https://github.com/mhaeuser/Battery-Toolkit now which works with any limits.

chriswep commented 2 months ago

I am pretty sure they have the same issue

https://github.com/AppHouseKitchen/AlDente-Charge-Limiter/issues/1326

They use a background process to monitor the battery. This is different from just setting an SMC value and letting the MacBook firmware do the rest which this tool does. The AlDente method still works with sequoia, I have it currently running.

linkc0de commented 2 months ago

macOS Ventura 13.7 (22H123) : same issue

ninadpchaudhari commented 2 months ago

This is so backwards! Seems they added a feature to limit charge on new iPhone 16 models [1] while removing the ability to write to SMC to achieve the exact same thing on Macs with Sequoia

PiterrsPl commented 2 months ago

i hope it will renew for this system during zackelia

eproxus commented 2 months ago

I could swear the charge limit set by bclm was synced to my Apple Watch as well which never charged over 80% when I had it enabled on my M2 MacBook Pro (but obviously not on my iPhone 14 Pro), but now with Sequoia it charges back to 100% again.

ssh352 commented 2 months ago

upgraded from 14.6.1 -> 14.7 got the same issue.

IshanFernandoCutAndDry commented 2 months ago

macOS 15.0 same issue

pgardiner commented 2 months ago

Same issue on macOS 15.0. Using Al Dente for now, but would like to go back to bclm, which has been perfect since I started using it, and has definitely extended my battery life.

PiterrsPl commented 2 months ago

https://github.com/lslqtz/bclm_loop/tree/main > > Fork BCLM o nazwie BCLM_Loop, który mogę potwierdzić, działa na wydaniu Sequoia 15.0. Instaluje się i można go włączyć w taki sam sposób jak oryginalny BCLM. > > Pod maską może nie być tak czysty lub elegancki jak oryginalny BCLM, ponieważ działa w pętli jako usługa w tle (w przeciwieństwie do pisania do SMC), ale nadal wykonuje pracę w 100%, o ile mogę powiedzieć do tej pory, bez wpływu na żywotność baterii po odłączeniu zasilania. > > Nadal jednak mam nadzieję, że oryginalny BCLM może zostać naprawiony.

https://github.com/lslqtz/bclm_loop/tree/main

Fork of BCLM called BCLM_Loop which I can confirm does work on Sequoia 15.0 release. It installs and can be enabled pretty much in the same fashion as the original BCLM.

Under the hood it may not be as clean or elegant as the original BCLM as it runs in a loop as a background service (as opposed to writing to the SMC), but it still does the job 100% as far as I can tell so far with no impact on battery life when unplugged.

Still hoping the original BCLM can be fixed though.

hi i have one question how to install this fork ? because its not so easy like using brew. please help me because I have spend few hours to install this fork and I have no idea how to do this .. my Mac is with m1 procesor

lslqtz commented 2 months ago

hi i have one question how to install this fork ? because its not so easy like using brew. please help me because I have spend few hours to install this fork and I have no idea how to do this .. my Mac is with m1 procesor

brew support has been added, but versions obtained through it may occasionally be out of date.

BTW: It only supports Apple Silicon based Mac computers. (I don't have an Intel Mac to test)

$ brew tap lslqtz/formulae
$ brew install bclm_loop

And, macOS 15.1 beta 5 still does not provide the required permissions to write to CHLS.

$ sudo smc -k CHWA -r
  CHWA  [    ]  no data
$ sudo smc -k CHLS -r
Error: SMCReadKey() = e00002c1
ssh352 commented 2 months ago

I changed to use https://github.com/mhaeuser/Battery-Toolkit now which works with any limits.

@lslqtz I was deciding on bclm_loop and Battery-Toolkit, could you advise on the benefits of bclm_loop over Battery-Toolkit?

for reference: I've asked the Battery-toolkit author https://github.com/mhaeuser/Battery-Toolkit/discussions/38

ideally the micro charging is as infrequent as possible when the laptop runs on power adapter.

variia commented 2 months ago

@ssh352 i switched to Battery-Toolkit yesterday temporarily. it is GUI but i like the more fine-grained control over my charging and the option to drain (condition) my battery while in clam-shell mode.

Screenshot 2024-09-24 at 13 43 39 Screenshot 2024-09-24 at 13 44 30
lslqtz commented 2 months ago

I changed to use https://github.com/mhaeuser/Battery-Toolkit now which works with any limits.

@lslqtz I was deciding on bclm_loop and Battery-Toolkit, could you advise on the benefits of bclm_loop over Battery-Toolkit?

for reference: I've asked the Battery-toolkit author mhaeuser/Battery-Toolkit#38

ideally the micro charging is as infrequent as possible when the laptop runs on power adapter.

bclm_loop is an improvement on bclm [1]. It has no GUI and runs silently in the background. This means it does not occupy the menu bar, but is less flexible. In terms of energy consumption, although the two projects use different methods, there is almost no difference in actual use. In addition, since the code of bclm_loop is simpler, it is easier to make user-defined code modifications.

In addition, bclm_loop, like bclm, (used to) support firmware-based charging control, and the current version of bclm_loop will still try to use firmware-based charging control on supported firmware.

[1] The original purpose of bclm_loop was to provide MagSafe LED control capabilities based on bclm. (PR https://github.com/zackelia/bclm/pull/39)

If you need a GUI and the greater user flexibility it provides, there are other options, including this one or something like AIDente.

ssh352 commented 2 months ago

In addition, bclm_loop, like bclm, (used to) support firmware-based charging control, and the current version of bclm_loop will still try to use firmware-based charging control on supported firmware.

thanks very helpful info.

"Battery Toolkit uses the OS APIs to be notified of changes to the charging level and is idling most of the time. "

Battery-toolkit appears not firmware based though.

PiterrsPl commented 2 months ago

thx

PiterrsPl commented 2 months ago

hi i have one question how to install this fork ? because its not so easy like using brew. please help me because I have spend few hours to install this fork and I have no idea how to do this .. my Mac is with m1 procesor

brew support has been added, but versions obtained through it may occasionally be out of date.

BTW: It only supports Apple Silicon based Mac computers. (I don't have an Intel Mac to test)


$ brew tap lslqtz/formulae

$ brew install bclm_loop

And, macOS 15.1 beta 5 still does not provide the required permissions to write to CHLS.


$ sudo smc -k CHWA -r

  CHWA  [    ]  no data

$ sudo smc -k CHLS -r

Error: SMCReadKey() = e00002c1

Thx very much for help

Nolenius commented 1 month ago

I'm also hoping the original BCLM can be fixed, very helpful! Does anyone use batt [https://github.com/charlie0129/batt] ?

reedgrass777 commented 1 month ago

Does anyone use batt [https://github.com/charlie0129/batt] ?

Why should I prefer BCLM over batt? It seems batt gets the job done, isn't it?

sozercan commented 1 month ago

Why should I prefer BCLM over batt? It seems batt gets the job done, isn't it?

Main difference is that bclm doesn't run in the background, but it's at the firmware level. Anything else runs in the background.

majal commented 1 month ago

Why should I prefer BCLM over batt? It seems batt gets the job done, isn't it?

Main difference is that bclm doesn't run in the background, but it's at the firmware level. Anything else runs in the background.

Which further means that batt and others will not be able to monitor charging if the system is suspended. (That's why batt by default will disable charging before suspend, which means no charging of a closed laptop.)

I'm actually thinking of having both batt and bclm together. batt has more features while the computer is on, and bclm limits charging even when the system is suspended.

ivankovnatsky commented 1 month ago

Forgive me, but this does not seem like a suitable place to discuss other battery tools.

yuukiyuuna commented 1 month ago

Is there any update plan for this project ?