Closed alaneuler closed 1 year ago
Shouldn't it just be battery charging off
?
If we limit changer at 80%. Then after 30 60 mins later, the current battery is 79% and the macbook will charge then. So can you made a script to limit chager 80% and when the current battery level 70% they have rechange again.
ps: AIDenta has this function and maybe the software alway read battery level informations so they make macbook drain enegry so much, maybe lost 10 20% overnight when close lid.
Shouldn't it just be
battery charging off
?
Nope, "battery charing off" means:
"Discharge" mean:
If we limit changer at 80%. Then after 30 60 mins later, the current battery is 79% and the macbook will charge then. So can you made a script to limit chager 80% and when the current battery level 70% they have rechange again.
But say if current SOC is 90% and the charge limit is set to 80%? There will be a long time the SOC of battery exceeds 80%. What we can do is to wait it drain naturally.
ps: AIDenta has this function and maybe the software alway read battery level informations so they make macbook drain enegry so much, maybe lost 10 20% overnight when close lid.
If I activates AlDente's "discharge' functionality, the macOS runs totally on battery (I can confirm this on menu bar's battery status) but not what you have said.
@alaneuler Oh, did not know that. Can MacOS even disconnect from a charger while it's still plugged in? Is Aldenter Pro open source? If so, we could look into the code to see how it's doing that.
I've been trying to use IOKit to limit charging, but it doesn't work. Looking at AlDente's issue tracker shows many people having problems with the Discharge functionality, so it's possible it doesn't work well at all.
@DUOLabs333 Yes, absolutely. Even Aldente free version has this functionality, but it seems that code of "discharge" is not open sourced. You can find out here by yourself.
Yeah, I checked there, but didn't find it (it seems that the version on GitHub is not the same as the one put in the releases).
Apple's open API doesn't provide what you want (guessing...), besides IOKit, you can also check IOPMLib.
Aldente works well on Monterey but not for Ventura, it's not surprising though because most of the macOS battery related apps rely on the private API SMCKit.
The only I can think of that works is basically run a while loop to drain the battery, but that sounds incredibly wasteful and not guaranteed to work in all situations.
Hey @alaneuler did you find the smc
code for disabling the adapter input? I don't have time to dig into the aldente source code but if you find the code I can add it over the xmas holiday.
@actuallymentor it seems that Aldente doesn't open source its discharge functionality code.
Ah that's too bad. I'll leave this issue open.
If anyone figured out the right SMC key to disable adapter input (while the adapter is plugged in) please let me know.
Ah that's too bad. I'll leave this issue open.
If anyone figured out the right SMC key to disable adapter input (while the adapter is plugged in) please let me know.
You had a discussion with "aykevl" in Oct. (https://github.com/zackelia/bclm/issues/20#issuecomment-1269192439). There was also a link to the source "macsmc_power.c" with the wanted information inside.
I did test the following and it seems to work: sudo smc -k CH0I -w 01 // battery starts to discharge even with PS connected sudo smc -k CH0I -w 00 // back to normal behavior
I also found the key "SBAS" (smc -k SBAS -r) which seems to deliver a more precise charge-level than "pmset -g batt". Guess AlDente uses SBAS.
I just tried this in my own tool and it works perfectly.
Though SBAS seems a minute behind pmset.
Though SBAS seems a minute behind pmset.
rather different values: https://apphousekitchen.com/feature-explanation-hardware-battery-percentage/
"sudo smc -k CH0I -w 01" works for me, it does make my m1 macbook to use battery to discharge, but it also invalidates clamshell mode.
...it also invalidates clamshell mode.
what does it mean excactly? I don't have an external display to test
@howie65 thanks for the sleuthing! I'll add it to the todo list (a PR is welcome of course).
...it also invalidates clamshell mode.
what does it mean excactly? I don't have an external display to test
If you execute the command while in clamshell mode, the clamshell mode will be deactivated and macbook goes to sleep immediately. The effect is exactly as you unplug power cable forcing macbook running in battery mode while in clamshell mode.
Hope this is clear enough. Probably we need something to inhibit the sleep to make this works for clamshell mode.
Hope this is clear enough. Probably we need something to inhibit the sleep to make this works for clamshell mode.
Ok I understand. caffeinate command should help here.
@howie65 sounds like the easiest way to do this is to caffeinate this line.
The thing I want to avoid is forcing the device to be awake when on battery power. That is a source of battery drain (Windows devices have this issue when put in a backpack for example).
Ideally we'd do:
if <check if adapter is connected>
caffeinate sleep
else
just sleep
Though I'm not sure what is the most elegant way to check for plugged-in status.
@howie65 sounds like the easiest way to do this is to caffeinate this line.
The thing I want to avoid is forcing the device to be awake when on battery power. That is a source of battery drain (Windows devices have this issue when put in a backpack for example).
Ideally we'd do:
if <check if adapter is connected> caffeinate sleep else just sleep
Though I'm not sure what is the most elegant way to check for plugged-in status.
Hi, im willing to try this. Can you elaborate how to run the commands in order to achieve this? Im trying to:
Yeah i know aldente is supposed to do all this automatically, however, it does not. Not even with pro subscription. I just requested a refund after trying everything.
Hi, im willing to try this. Can you elaborate how to run the commands in order to achieve this?
Normally there should be all tools in the box now to go manually.
This should be the steps but I cannot test because of missing external monitor. Please report if this works.
thanks for you quick response. running cmd "sudo smc -k CH0I -w 01" puts the computer to sleep. So i ran it after running "caffeinate" and it still puts the computer to sleep. Meaning as soon as the computer detects the power adpater is "unplugged" in clamshell mode, it goes to sleep (normal macos behavior).
Sorry to hear that caffeinate isn't the solution to prevent from sleep.
Google has led me to this page: https://beebom.com/use-macbook-clamshell-mode-without-power-adapter/ Maybe you like to give "Amphetamine" a chance?
Sorry to hear that caffeinate isn't the solution to prevent from sleep.
Google has led me to this page: https://beebom.com/use-macbook-clamshell-mode-without-power-adapter/ Maybe you like to give "Amphetamine" a chance?
hi, thanks for your help. I remember i tried this before and didnt work. but i was doing the procedure wrong.So after following all these steps, in order for it to work:
Note: it will not work if you start the session (step 1) and disconnect the power. It will automatically go to sleep (normal macos behaviour). So i think with battery app at 80% + amphetamine I can manually calibrate and now keep my battery healthy. Thanks all for your help.
Functionality for discharge is now added. See new help message of battery
.
Hi, great work here!
I have just one little additional problem. New monitor with type-C port have typically charging capability, which means you can use an external monitor while charging in a single type-C cable. But if mac's battery exceeds the limit, I can't have it reduce to a lower percentage. Aldente has a Discharge functionality which is exactly what I'm describing (but I'm a CLI guy sadly).
Can you please work on this?
I'm willing to code and just don't know how to achieve this.