6

I have a 2016 MBP and due to my work-from-home setup I need to use an external monitor for working, which force the Mac to use the discrete graphic card and thus a faster battery drainage (together with other software).

Given the advertised feature that should put the battery charging on hold at 80%, the last weekend I have updated the OS from 10.14 to 11.1, but that feature doesn't seems to work as expected: even if enabled (by default), it always charge up to 100%; sometime it happend to actually stop charging, but after a few seconds it ramped again up to 100% automatically.

My question is, is there a way to force that behavior ? I've looked at pmset's man-page, but I haven't seen anything related.

Thanks in advance!

3 Answers 3

6

Here's a tool that I've seen recommended by others:

https://github.com/davidwernhart/AlDente

It can limit your charging to specific percentages. However, I've not used it myself.

2
  • It does seems to work with my machine, but it put me on the right track. Thank you!
    – dezzeus
    Commented Jan 15, 2021 at 12:03
  • Just a note it took a little work for me to get this working - involving disabling the System Preferences solution and restarting - but that it did start working
    – Ezekiel
    Commented Jan 15, 2021 at 15:45
3

Not really an already available solution, but Ezekiel put me on the right track: AlDente, while (currently; I've opened an issue) not working for me, attempt to writes a BCLM value in the SMC controller. So I've tried a different solution and found this one which does the job (from CLI).

0

Source: A guide on limiting macOS battery charging to at most 80%.

Limiting macOS charging to 80%:

1. Install smc:

To install smc on your macOS, follow these steps:

# Install smcfancontrol using Homebrew
brew install --cask smcfancontrol

# Copy the 'smc' binary to /usr/local/bin/ for global access
sudo cp '/Applications/smcFanControl.app/Contents/Resources/smc' /usr/local/bin/

2. Update sudo permissions:

To avoid entering your password every time you use the smc command with sudo, you can update the sudoers file.

  1. Open the sudoers file using the visudo command:
sudo visudo
  1. Scroll to the bottom of the file and add the following line. Replace username with your actual macOS username:
username ALL=(ALL) NOPASSWD: /usr/local/bin/smc
  1. Save and exit the editor.

3. Using the Zsh Functions:

Make sure you have added the provided Zsh functions to your .zshrc or another Zsh configuration file.

# Apple Silicon laptops with firmware > 13.0 have a native charge threshold that does not required any userspace daemon running.
# This native limit works even when the laptop is sleeping or powered off therefore it is preferable to the userspace daemon.
# Nonetheless, it only works with fixed thresholds (80% as upper limit and 70% as lower limit).
# CHWA key is the one used to enable/disable the native limit. 01 = 80% limit, 00 = no limit
##
typeset -g smc_command="/usr/local/bin/smc"
typeset -g smc_charge_limit_key="CHWA"
typeset -g smc_charge_limit_status_on="01"
typeset -g smc_charge_limit_status_off="00"

function battery-charge-limit-enable {
    if [[ "$(uname)" == "Darwin" ]]; then
        if [[ ! -e "${smc_command}" ]]; then
            echo 'SMC command not found!'
            return 1
        fi

        sudo "${smc_command}" -k "${smc_charge_limit_key}" -w "${smc_charge_limit_status_on}"
    else
        echo "Not a Darwin system."
    fi
}

function battery-charge-limit-disable {
    if [[ "$(uname)" == "Darwin" ]]; then
        if [[ ! -e "${smc_command}" ]]; then
            echo 'SMC command not found!'
            return 1
        fi

        sudo "${smc_command}" -k "${smc_charge_limit_key}" -w "${smc_charge_limit_status_off}"
    else
        echo "Not a Darwin system."
    fi
}

function battery-charge-limit-status {
    if [[ "$(uname)" == "Darwin" ]]; then
        if [[ ! -e "${smc_command}" ]]; then
            echo 'SMC command not found!'
            return 1
        fi

        local status_raw="$(sudo "${smc_command}" -k "${smc_charge_limit_key}" -r)"

        # Extract the bytes using regex
        if [[ "$status_raw" =~ 'bytes ([0-9]+)' ]]; then
            status_raw=$match[1]
        fi

        case "$status_raw" in
            "${smc_charge_limit_status_on}")
                echo "on"
                ;;
            "${smc_charge_limit_status_off}")
                echo "off"
                ;;
            *)
                echo "Unknown ${smc_charge_limit_key} status: $status_raw"
                ;;
        esac
    else
        echo "Not a Darwin system."
    fi
}
  • To enable the battery charge limit:

    battery-charge-limit-enable
    
  • To disable the battery charge limit:

    battery-charge-limit-disable
    
  • To check the status of the battery charge limit:

    battery-charge-limit-status
    

With these functions in place and smc installed, you can easily manage the battery charge limit of your macOS device from the terminal.

Compatibility

This needs an updated firmware on an Apple Silicon machine.

See Also

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .