DEV Community

Takahiko Inayama
Takahiko Inayama

Posted on • Updated on

How to check Battery Health on iPadOS/macOS

This article is also available on Medium.

If you have iPhone, you probably have seen Battery Health. It’s useful to check how much your battery is damaged by age. Unfortunately, it’s not available on iPadOS and macOS.

But it’s technically not true. There are same statics recorded in analytics logs. I’ll tell you how to see them.

First, you have to enable equivalents of “Share iPhone & Watch Analytics” on your devices.

Share analytics, diagnostics, and usage information with Apple

Share analytics information from your Mac with Apple

Logs will be written on next 0:00 UTC once you’ve enabled these settings.

You can find logs from Settings app on iPad. (”Privacy & Security” ⇒ “Analytics & Improvements” ⇒ “Analytics Data”)

On Mac, they’ll be written on /Library/Logs/DiagnosticReports/(or will be moved to /Library/Logs/DiagnosticReports/Retired/).

Image description

There are JSON files start with Analytics-. You can view on your text editor. You’ll find rows which contains last_value_CycleCounton its values.

This line contains lots of statics. I’ll explain some of them I usually monitor.

  • last_value_CycleCount seems to be charge cycle counts.(Same as it on System Information app.)
  • last_value_MaximumCapacityPercentseems to be “Battery Health” which available on iPhone.
  • last_value_NominalChargeCapacity seems to be normalized battery capacity value which used to calculate “Battery Health’
  • last_value_DailyMaxSoc seems to be highest value of the battery percentage on the day.
  • last_value_DailyMinSoc seems to be lowest value of the battery percentage on the day.

Aside from above, last_value_AppleRawMaxCapacityis especially useful for me because I can see raw battery capacity values like before iOS 11.3.

For example, my iPad mini has 5124 mAh battery. And current last_value_AppleRawMaxCapacityis 4757. So it’s roughly 93% battery health. It’s lower compared to last_value_MaximumCapacityPercent (”Battery Health”) which has 97 percent. It’s interesting. 🤔

It’s also interesting to watch changes of these values.

Finally, I’ll show you an example Ruby code to read these stats.

require "json"

BATTERY_KEYS = [
  "last_value_CycleCount",
  # "last_value_AverageTemperature",
  # "last_value_DailyMaxSoc",
  # "last_value_DailyMinSoc",
  "last_value_MaximumCapacityPercent",
  "last_value_NominalChargeCapacity",
  "last_value_AppleRawMaxCapacity",
  # "last_value_batteryServiceFlags",
  # "last_value_ServiceOption",
  # "last_value_calibrationFlags",
]

Dir.glob("./*.{synced,core_analytics}") do |file_name|
  os_version = nil
  timestamp = nil
  messages = []

  File.readlines(file_name).each_with_index do |line, idx|
    data = JSON.parse(line)
    if idx == 0
      os_version = data["os_version"]
      timestamp = data["timestamp"]
    end

    message = data["message"]
    next unless message&.keys&.include?(BATTERY_KEYS[0])
    messages << message
  end

  puts os_version
  puts timestamp
  puts BATTERY_KEYS.join("\t")
  messages.each do |message|
    puts (BATTERY_KEYS.map do |k|
      message[k].nil? ? "null" : message[k]
    end).join("\t")
  end

  puts "\n"
end
Enter fullscreen mode Exit fullscreen mode

Have fun!!

Top comments (0)