Coder Social home page Coder Social logo

bclm's Introduction

BCLM

BCLM is a wrapper to read and write battery charge level max (BCLM)/CHWA values to the System Management Controller (SMC) on Mac computers. It supports both Intel and Apple silicon. This project was inspired by several battery management solutions, including Apple's own battery health management.

The purpose of limiting the battery's max charge is to prolong battery health and to prevent damage to the battery. Various sources show that the optimal charge range for operation of lithium-ion batteries is between 40% and 80%, commonly referred to as the 40-80 rule [1][2][3]. This project is especially helpful to people who leave their Macs on the charger all day, every day.

Installation

The easiest method to install BCLM is through brew.

BCLM is written in Swift and is also trivial to compile. Currently, it can only be compiled on macOS Catalina (10.15) or higher but it can run on OS X Mavericks (10.9) or higher.

A release zip is also provided with a signed and notarized binary for those who do not have development tools or are on an older macOS version.

Brew

$ brew tap zackelia/formulae
$ brew install bclm

From Source

$ make build
$ make test
$ sudo make install

From Releases

$ unzip bclm.zip
$ sudo mkdir -p /usr/local/bin
$ sudo cp bclm /usr/local/bin

Note: For older versions of macOS, it may be necessary to install the Swift 5 Runtime Support for Command Line Tools if you get the following error: dyld: Symbol not found

Usage

$ bclm
OVERVIEW: Battery Charge Level Max (BCLM) Utility.

USAGE: bclm <subcommand>

OPTIONS:
  --version               Show the version.
  -h, --help              Show help information.

SUBCOMMANDS:
  read                    Reads the BCLM value.
  write                   Writes a BCLM value.
  persist                 Persists bclm.
  unpersist               Unpersists bclm.

  See 'bclm help <subcommand>' for detailed help.

For Intel machines, when writing values, macOS charges slightly beyond the set value (~3%). In order to display 80% when fully charged, it is recommended to set the BCLM value to 77%. When charging while system is shut down or sleeping, the charging can go beyond set value more than average 3%.

$ sudo bclm write 77
$ bclm read
77

For Apple silicon machines, only the values 80 and 100 are supported and firmware >= 13.0 is required.

Note that in order to write values, the program must be run as root. This is not required for reading values.

Persistence

The SMC can be reset by a startup shortcut or various other technical reasons. To ensure that the BCLM is always at its intended value, it should be persisted.

This will create a new plist in /Library/LaunchDaemons and load it via launchctl. It will persist with the current BCLM value and will update on subsequent BCLM writes.

$ sudo bclm persist

Likewise, it can be unpersisted which will unload the service and remove the plist.

$ sudo bclm unpersist

bclm's People

Contributors

milljm avatar nata1993 avatar zackelia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bclm's Issues

keyNotFound(code: "BCLM")

any thoughts?

bclm read
keyNotFound(code: "BCLM")

sudo bclm persist
keyNotFound(code: "BCLM")

MacBook Pro
14-inch, 2021
Distro: OS X 13.5.1
CPU: Apple M1 Pro
Memory: 32 GB

BFCL value does not seem to be restored on reboot

Even after setting the bclm utility to launch at login, it doesn't seem to be restoring the BFCL property correctly. The MagSafe charger light is orange and it requires re running the utility to update it again. The BCLM property seems to be fine but that could be because it doesn't reset that value at reboot as easily, which could mean that its not running the command correctly at login.

macOS Mojave 10.14.6
MacBook Pro 13" Early 2015

Computer doesn't sleep

I set all durations to 1-minute but the computer never sleeps when the bclm is running. It was sleeping before I installed blcm. I'm running Sonoma 14.4 on an Apple M1 Max

Screenshot 2024-03-14 at 2 28 12 PM

Support for Mac OS Monterey

Looks like updating to Monterey Beta broke bclm. In terminal it's reading that its set but battery is charging to 100%.

Display correct charge indicator LED on Magsafe charger

On older MacBooks that use the MagSafe charger, the LED turns green if it has finished charging. Just changing the BCLM value does not influence the MagSafe LED color.
There is a value in the SMC called BFCL (Battery Final Charge Level) that holds the value for when the LED color should change to green. By default, for the machines that have this value, the value is 5 less than the BCLM. So for example, if you were to set the BCLM to 65%, then you would set the BFCL to 60%. This follows what Apple does because its default value is 5f, or 95%.
Please add this option for changing this value as well.

PS I've added this ability in https://github.com/godly-devotion/charge-limiter as well for reference.

keyNotFound(code: "BFCL")

When running bclm v.0.0.3 there is an following error output:

sudo bclm write 75
keyNotFound(code: "BFCL")

Running on USB-C Macbook Air 2019. It seems that Macbooks with USB-C charging doesn't have BFCL in SMC.

BTW: Thank you for this great and dead simple tool.

Doesnt work on MacOS 10.14.6

I've set bclm at 80 and set persist.
BCLM read is at 80.
Charging goes to 100%. Tested 2 times.
Is it a bug for 10.14.6 ?

BCLM persist failing on launch with code -9

Hi,

The utility works as expected, but doesn't persist on launch.
I've set the value at 80, but when I run bclm read after a reboot, I get 100.
This is on a mid 2012 MacBook Pro running Catalina.

I checked for the launch status code of the plist file and got this:

sudo launchctl list | grep com.zackelia.bclm.plist

  • -9 com.zackelia.bclm.plist

Is this a SIGKILL? I did get a popup at boot, asking since BCLM was downloaded from the internet, should I allow it to run? I clicked Allow. And if it hadn't run, I wouldn't expect to get an entry in launchctrl list anyway... confusing, eh?

Tried it several times, same result.

how to enable bclm directly from macOS?

Hi, I realize this isn't an issue for this app, but I've looked online and couldn't find this answer

How can I write the BCLM value to the SMC without using any 3rd party apps? Are there a set of terminal commands that will achieve the same thing? (And also allow reading the value, and reading/writing BFCL)

Thanks

doesn't work on 2008 aluminum unibody Macbook

FYI, doesn't seem to work on my 2008 aluminum unibody Macbook (with patched OS 10.12.6 High Sierra):
bclm read
gives
keyNotFound(code: "BCLM")

bclm read --version
gives
[0.0.4]

Meanwhile, I also tried OSX Battery Charge Limit and it returned the error

ERROR: SMC out parse failed
valid "  BCLM  [ui8 ]  60 (bytes 3c)"
current "  BCLM  [    ]  no data"

bclm becomes /usr/local/bin

Hi,

I believe my /usr/local/bin directory was non-existent because my laptop is new.

After running sudo make install, the /usr/local/bin IS the bclm binary and not a directory anymore.

I can run /usr/local/bin, literally. So I think this should be checked, and the directory should be created if it does not exist

Apple Silicon macOS Ventura - persist seems to be misbehaving

I've "installed" via the sudo cp bclm /usr/local/bin method.
I've set the charge level: sudo bclm write 80
I've confirmed the charge level: bclm read ==> 80
I've set persistence: sudo bclm persist
I've confirmed (using LaunchControl) that the com.zackelia.bclm.plist is loaded & running: /usr/local/bin/bclm write 80
I disabled Apple's native "Optimized Battery Charging" before installing bclm (REF #32 )

Earlier tonight, I had to remove my Mac from the charger for a while in the lab. The charge level had declined to 77% during that time. When I plugged the charger in again, I expected it to charge up to 80% - but it did not do this. Instead, hours later, it is still sitting at 77%.

Is this the expected behavior? What should I do to return the "persistence" to the set value of 80%??


UPDATE/FWIW: I've discovered that following a Restart, the bclm-controlled battery charging to the 80% level is resumed.

You're missing something here, dude.

Library not loaded on Mavericks

Hi, thanks so much for putting up this project. So relevant nowadays it's hard to believe a tool like this didn't exist for older OS X versions.

I'm trying to run the binary on Mavericks (10.9.5) and I'm getting the following error:

dyld: Library not loaded: @rpath/libswiftCore.dylib
  Referenced from: /usr/local/bin/bclm
  Reason: image not found
Trace/BPT trap: 5

Do you know what's happening?

How to stop it?

Thanks for the project.
But when I want to stop it and restore MAC's defaults, what should I do?
Just
sudo bclm write 100 ???

Hackintosh Support

Hi zackelia,

I am using Hackintosh on my T460s with v0.0.4, but I got the KeyNotFound(code: "BCLM") error.

Could you please tell me some details about how to check the SMC status from .kext files.

Thanks.

How this helps the Mac on the charger all day?

Hi, I don't quite understand how it extend battery lifespan.
It says 40-80 is best range for charging and using, but didn't say if battery always stay on 80 with charger all day will be good.
I also found the new battery health management of macOS, will discharge battery to 90, then charge it to full, then discharge, then charge... I think it try to keep battery in a flow state, and prevent battery be always full. So, will BCLM will do the same thing, or just keep battery on 80?

dyld: Symbol not found: _$s17StringLiteralTypes013ExpressibleByaB0PTl

Hello :)

Been using this on my old MacBook Air which runs Yosemite. Works flawlessly.

Yesterday, I installed High Sierra on my macbookpro13,1 from 2013. On this machine, I get this error when trying to use bclm:

> sudo Downloads/bclm --help
dyld: Symbol not found: _$s17StringLiteralTypes013ExpressibleByaB0PTl
  Referenced from: /Users/daniel/Downloads/bclm
  Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
 in /Users/daniel/Downloads/bclm
[1]    31538 abort      A=`alias` sudo env Downloads/bclm --help

I do have the file in question (Xcode 10.1):

> stat /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
  File: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
  Size: 6544080   	Blocks: 4832       IO Block: 4096   regular file
Device: 1,4	Inode: 3177401     Links: 3
Access: (0755/-rwxr-xr-x)  Uid: (  501/  daniel)   Gid: (   20/   staff)
Access: 2023-01-05 10:40:13.000000000 +0100
Modify: 2018-10-20 03:23:30.000000000 +0200
Change: 2023-01-04 15:27:38.000000000 +0100
 Birth: 2018-10-20 03:23:30.000000000 +0200

A little odd that it works on Yosemite, but not High Sierra? (I'm getting used to pretty much nothing working anymore on Yosemite XD)

Battery of watch being limited

My apple watch is not charging above 80%. It would seem that this utility is causing the apple watch to be limited to the same battery as my MacBook air m1

Idea for an addition to your readme and/or the BCLM console information

kudos to you for making a very nice clean bit of code to do something super useful!!!
I am just experimenting with it for the first time and it does seem to work well on my m1 macbook air.
what happens if my battery is currently at 100% and i enter "sudo bclm write 80" in terminal? will the macbook just switch to battery power if it is currently plugged in? I suppose that is the behavior to expect but my idea is to just say that is what will happen somewhere in readme or in the terminal when you type "bclm"

dyld: Symbol not found

Hello! I am really interested in this project!

However, this error shows up when running the bclm command in terminal after installing with brew or from release.
I am running MacOS 10.13.6, so I can't build it from source.

dyld: Symbol not found: _$s17StringLiteralTypes013ExpressibleByaB0PTl
  Referenced from: /usr/local/bin/bclm
  Expected in: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/macosx/libswiftCore.dylib
 in /usr/local/bin/bclm
[1]    6923 abort      bclm

Can provide any additional info if necessary.

It stopped working after upgrade to Sonoma 14.4

Hello,

I have MacBook Pro 16 M2 Max. Everything was okay before I updated MacOS to Sonoma 14.4 (23E214).

Since then, bclm stopped working. I tried to upgrade it using brew, but, unfortunately, it didn't help.

Persisting doesn't work.

I'm using a MacBook Air (Retina, 13-inch, 2018) which is running macOS Sonoma 14.3.1.
Persisting on my MacBook doesn't work. After restarting or waking up my MacBook from sleeping, the charging limit will change back to 100 even though I've persisted it using the command sudo balm persist before shutting down or sleeping. I can make sure that the command works properly because there is no error printed on the terminal while running this command. Also, when I try to run this command twice, I will get an output Already persisting!. Plus, I can see a notification of adding login item after running this command. So it seems that the command is running properly but the persisting doesn't work.
Could anyone please give some advice on the solution of issue?

support for Apple ARM M1

Hey there,

I use your extension on both of my other MacBooks and just want to say great job. Simple and easy to use.

I just got an M1 MBA and would love to use it as well but am having some trouble..

So far, I've:

  • installed homebrew natively under /opt/homebrew
  • ran the following successfully:
brew tap zackelia/formulae
  • but when i run:
sudo bclm write 72

i get the error:

sudo: unable to execute /opt/homebrew/bin/bclm: Bad CPU type in executable

Any pointers in the right direction? Happy to help get M1 support running with your package in any way :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.