Question

To the best of my knowledge, MacBooks will still charge if the power supply attached provides less wattage then the laptop was designed for. Is there a way to view the current power input, preferably a simple terminal command, or would that be impossible/always the same for some reason?

If relevant, I have a MacBook Pro (13-inch, 2017, Two Thunderbolt 3 ports), but would like a way that works on other models as well.

Was it helpful?

Solution

There is a straightforward way to determine instantaneous* battery charging current, assuming you have developer tools installed:

ioreg -rw0 -c AppleSmartBattery | grep -o -e '"ChargingCurrent"=[0-9]*'

The number is specified in milliamps.

However, this is not going to be the same as the current entering through your AC adapter (this is most apparent when the battery is fully charged, in which case the current will be 0), so it may not help you with what you're doing. I'm not aware of a place where that information gets published, although the PMU must certainly measure it.

Similarly, you can view the instantaneous* voltage of the battery, in millivolts, with

ioreg -rw0 -c AppleSmartBattery | grep -o -e '"Voltage" = [0-9]*'

which, when multiplied by the above current, will give you the power being delivered to the battery (in microwatts, so divide by a factor of 1,000,000 to get watts). But, again, it is not the same as the power being delivered by the AC adapter.

You can view more power-related parameters with

ioreg -rw0 -c AppleSmartBattery

Update:

I experimented on two systems – a T2-based MBP with Catalina and a non-T2-based MBP with Big Sur – and found that the former has the keys AdapterPower and SystemPower contained in the BatteryData dictionary property of AppleSmartBattery:

"BatteryData" = {"StateOfCharge"=98,"PMUConfigured"=0,"DesignCapacity"=8790,"QmaxCell1"=9017,"AdapterPower"=1101610469,"SystemPower"=1104635067,"ResScale"=244,"QmaxCell2"=9048,"QmaxCell0"=9082,"CycleCount"=69,"Voltage"=12503}

So this is a promising source for determining both the power being delivered by the AC adapter as well as the power being consumed by the system. These, along with the earlier battery charge current & voltage that I showed, could give you a pretty complete picture of the power situation.

I couldn't figure out the units at first, since the numbers are too high to be W, mW, and even µW, and too low to be nW. Then I remembered that some keys are stored as floating point values, and when I converted 1101610469 into an IEEE-754 float, I got the very reasonable-looking 21.1552219391, which means that it's published in units of watts.

You can therefore – on at least certain hardware or software – view the AC adapter power consumption with

ioreg -rw0 -c AppleSmartBattery | grep BatteryData | grep -o '"AdapterPower"=[0-9]*' | cut -c 16- | xargs -I %  lldb --batch -o "print/f %" | grep -o '$0 = [0-9.]*' | cut -c 6-

and system power consumption with

ioreg -rw0 -c AppleSmartBattery | grep BatteryData | grep -o '"SystemPower"=[0-9]*' | cut -c 16- | xargs -I %  lldb --batch -o "print/f %" | grep -o '$0 = [0-9.]*' | cut -c 6-

This uses lldb to do the IEEE-754 conversion, so you, again, will need developer tools installed. It is also very straightforward to write a small CLI tool that uses the IOKit framework to dump these out without needing Xcode installed on the target system, if you needed to have that.

* - Note that these values only seem to update once a minute or so, so they aren't truly instantaneous.

Licensed under: CC-BY-SA with attribution
Not affiliated with apple.stackexchange
scroll top