HKCategoryTypeIdentifierSleepAnalysis — reading Apple Health sleep stages correctly
Sleep is the one Apple Health identifier that is a category type, not a quantity, and it carries a value that quietly ruins totals: In Bed.
Open your file
Drop your file here
export.zip straight from the Health app — do not unzip it
No account. No upload. The file is read on this device and never leaves it.
Nothing has been sent anywhere. 0 requests to this site, for the page's own code.
In Bed is not a sleep stage
HKCategoryTypeIdentifierSleepAnalysis records segments, each tagged with a value. One of those values is InBed, and it overlaps the actual sleep segments rather than sitting beside them — the Watch marks the whole in-bed window and the asleep windows inside it. Add In Bed to Asleep and you count the same minutes twice, reporting eleven hours of sleep for an eight-hour night. It is why our pipeline treats In Bed as context, never as sleep.
The iOS 16 stage change
Before iOS 16, Apple wrote a single Asleep value. From iOS 16 the Watch distinguishes AsleepCore, AsleepDeep and AsleepREM. A multi-year export contains both eras, so a reader that only knows the new tokens loses every night before the change, and one that only knows the old token loses the staging after it. This page reads both.
This identifier is one of dozens. The Apple Health data dictionary lists every identifier this parser reads, with its canonical type and unit.