The Google Health API provides data types that track a user's sleep patterns,
including duration, quality, and physiological metrics during rest. These
metrics help applications provide insights into recovery, sleep hygiene, and
long-term health trends.

Physiological metrics such as Heart Rate Variability (HRV), Oxygen
Saturation (SpO2), and respiratory rate are recorded specifically during
sleep because the body is in a stable, resting state. This allows the API to
capture a baseline of the user's autonomic and respiratory health without the
interference of daytime stressors, physical activity, or varying environmental
conditions.

Understand the differences between these data types to determine which metrics
suit your application.

## Supported data types

The API supports the following data types for measuring sleep:

<br />

| Data type | Available operations | Scope |
|---|---|---|
| **[Daily Heart Rate Variability](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#dailyheartratevariability)** **dataType:** `daily-heart-rate-variability` **filter parameter:** `daily_heart_rate_variability` **Record type:**Daily [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Alta HR - Fitbit Blaze - Fitbit Charge 2 - Fitbit Charge 3 - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - Fitbit Inspire 2 - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Inspire HR - Fitbit Ionic - Fitbit Luxe - Pixel Watch - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Daily Oxygen Saturation](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#dailyoxygensaturation)** **dataType:** `daily-oxygen-saturation` **filter parameter:** `daily_oxygen_saturation` **Record type:**Daily [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Ionic - Fitbit Luxe - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Daily Respiratory Rate](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#dailyrespiratoryrate)** **dataType:** `daily-respiratory-rate` **filter parameter:** `daily_respiratory_rate` **Record type:**Daily [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Alta HR - Fitbit Blaze - Fitbit Charge 2 - Fitbit Charge 3 - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - Fitbit Inspire 2 - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Inspire HR - Fitbit Ionic - Fitbit Luxe - Pixel Watch - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Daily Sleep Temperature Derivations](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#dailysleeptemperaturederivations)** **dataType:** `daily-sleep-temperature-derivations` **filter parameter:** `daily_sleep_temperature_derivations` **Record type:**Daily [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) [Skin Temperature guide](https://developers.google.com/health/data-types/skin-temperature.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - Fitbit Inspire 2 - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Inspire HR - Fitbit Ionic - Fitbit Luxe - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Heart Rate Variability](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#heartratevariability)** **dataType:** `heart-rate-variability` **filter parameter:** `heart_rate_variability` **Record type:** [Sample](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#ObservationSampleTime) [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Alta - Fitbit Alta HR - Fitbit Blaze - Fitbit Charge 2 - Fitbit Charge 3 - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - Fitbit Flex 2 - Fitbit Inspire - Fitbit Inspire 2 - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Inspire HR - Fitbit Ionic - Fitbit Luxe - Fitbit MobileTrack - Pixel Watch - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) - Fitbit Versa Lite | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Oxygen Saturation](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#oxygensaturation)** **dataType:** `oxygen-saturation` **filter parameter:** `oxygen_saturation` **Record type:** [Sample](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#ObservationSampleTime) **Storage resolution:**1 minute [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Ionic - Fitbit Luxe - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Respiratory Rate Sleep Summary](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#respiratoryratesleepsummary)** **dataType:** `respiratory-rate-sleep-summary` **filter parameter:** `respiratory_rate_sleep_summary` **Record type:** [Sample](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#ObservationSampleTime) [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Vitals guide](https://developers.google.com/health/data-types/vitals.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Alta HR - Fitbit Blaze - Fitbit Charge 2 - Fitbit Charge 3 - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - Fitbit Inspire 2 - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Inspire HR - Fitbit Ionic - Fitbit Luxe - Pixel Watch - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) | list, reconcile | `.health_metrics_and_measurements.readonly` `.health_metrics_and_measurements.writeonly` |
| **[Sleep](https://developers.google.com/health/reference/rest/v4/users.dataTypes.dataPoints.md.txt#sleep)** **dataType:** `sleep` **filter parameter:** `sleep` **Record type:**Session [Webhook support](https://developers.google.com/health/webhooks.md.txt) [Sleep guide](https://developers.google.com/health/data-types/sleep.md.txt) #### Compatible devices - [Fitbit Air](https://store.google.com/product/google_fitbit_air) - Fitbit Alta - Fitbit Alta HR - Fitbit Blaze - Fitbit Charge 2 - Fitbit Charge 3 - Fitbit Charge 4 - Fitbit Charge 5 - [Fitbit Charge 6](https://store.google.com/product/fitbit_charge_6) - [Fitbit Edge](https://store.google.com/product/google_fitbit_edge) - Fitbit Flex 2 - Fitbit Inspire - Fitbit Inspire 2 - [Fitbit Inspire 3](https://store.google.com/product/fitbit_inspire_3) - Fitbit Inspire HR - Fitbit Ionic - Fitbit Luxe - Pixel Watch - Pixel Watch 2 - [Pixel Watch 3](https://store.google.com/product/pixel_watch_3) - [Pixel Watch 4](https://store.google.com/product/pixel_watch_4) - Fitbit Sense - [Fitbit Sense 2](https://store.google.com/product/fitbit_sense_2) - Fitbit Versa - Fitbit Versa 2 - Fitbit Versa 3 - [Fitbit Versa 4](https://store.google.com/product/fitbit_versa_4) - Fitbit Versa Lite | list, get, reconcile, create, update, batchDelete | `.sleep.readonly` `.sleep.writeonly` |
[*Table: Google Health API Sleep data types*]

<br />

## Sleep sessions and short awakenings

A Sleep Session (`Sleep`) represents a discrete sleep event, such as a single
nightly sleep or a daytime nap. It includes a detailed breakdown of
non-overlapping sleep stages alongside brief wake transition intervals known as
short awakenings.

- **Sleep Session (`Sleep`)** : Represents a discrete sleep event (`LIGHT`, `DEEP`, `REM`, `AWAKE` stage intervals) that partition the contiguous timeline of the primary rest.
- **Short Awakenings (`shortAwakenings`)** : Brief wake transitions or awakenings that occur during rest. Unlike standard `AWAKE` stage intervals (which divide the non-overlapping contiguous sleep stage progression), short awakenings are distinct segments that can overlap with surrounding sleep stages. They provide granular visibility into restlessness and micro-awakenings without disrupting the primary sleep stage structure.
- **Nocturnal Awakenings** : Mid-night awakenings (such as getting up for water) are identified by on-device sensor fusion (accelerometer, gyroscope, and step count). Applications can detect nocturnal awakenings by filtering `stages` for intervals with `type: "AWAKE"` (used in both `CLASSIC` and `STAGES` sleep logs) or by inspecting `outOfBedSegments`.

### Example

```json
{
  "name": "users/user-id/dataTypes/sleep/dataPoints/data-point-id",
  "sleep": {
    "interval": {
      "startTime": "2026-04-20T22:30:00Z",
      "startUtcOffset": "-14400s",
      "endTime": "2026-04-21T06:30:00Z",
      "endUtcOffset": "-14400s"
    },
    "type": "STAGES",
    "stages": [
      {
        "startTime": "2026-04-20T22:30:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-04-20T23:45:00Z",
        "endUtcOffset": "-14400s",
        "type": "LIGHT"
      },
      {
        "startTime": "2026-04-20T23:45:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-04-21T01:15:00Z",
        "endUtcOffset": "-14400s",
        "type": "DEEP"
      }
    ],
    "shortAwakenings": [
      {
        "startTime": "2026-04-20T23:10:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-04-20T23:11:30Z",
        "endUtcOffset": "-14400s",
        "type": "AWAKE"
      }
    ],
    "summary": {
      "minutesInSleepPeriod": "480",
      "minutesAsleep": "455",
      "minutesAwake": "25",
      "minutesToFallAsleep": "15",
      "minutesAfterWakeUp": "10"
    }
  }
}
```

### Create a sleep session

To create a sleep session entry, send a `POST` request to the `sleep` data
points endpoint. The response includes the `name` field containing the
`data-point-id`, which can be used in an
[Update (Patch)](https://developers.google.com/health/endpoints.md.txt#update) or
[Delete](https://developers.google.com/health/endpoints.md.txt#delete) request.

### Request

```
POST https://health.googleapis.com/v4/users/me/dataTypes/sleep/dataPoints
Authorization: Bearer access-token
Content-Type: application/json

{
  "sleep": {
    "interval": {
      "startTime": "2026-06-07T22:00:00Z",
      "startUtcOffset": "-14400s",
      "endTime": "2026-06-08T06:00:00Z",
      "endUtcOffset": "-14400s"
    },
    "type": "STAGES",
    "stages": [
      {
        "startTime": "2026-06-07T22:00:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-07T22:30:00Z",
        "endUtcOffset": "-14400s",
        "type": "LIGHT"
      },
      {
        "startTime": "2026-06-07T22:30:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-07T23:45:00Z",
        "endUtcOffset": "-14400s",
        "type": "DEEP"
      },
      {
        "startTime": "2026-06-07T23:45:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-08T02:15:00Z",
        "endUtcOffset": "-14400s",
        "type": "LIGHT"
      },
      {
        "startTime": "2026-06-08T02:15:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-08T02:45:00Z",
        "endUtcOffset": "-14400s",
        "type": "REM"
      },
      {
        "startTime": "2026-06-08T02:45:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-08T05:15:00Z",
        "endUtcOffset": "-14400s",
        "type": "LIGHT"
      },
      {
        "startTime": "2026-06-08T05:15:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-08T06:00:00Z",
        "endUtcOffset": "-14400s",
        "type": "REM"
      }
    ]
  }
}
```

### Response

```
{
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.devicesandservices.health.v4.DataPoint",
    "name": "users/user-id/dataTypes/sleep/dataPoints/data-point-id",
    "sleep": {
      "interval": {
        "startTime": "2026-06-07T22:00:00Z",
        "startUtcOffset": "-14400s",
        "endTime": "2026-06-08T06:00:00Z",
        "endUtcOffset": "-14400s"
      },
      "type": "STAGES",
      "stages": [
        {
          "startTime": "2026-06-07T22:00:00Z",
          "startUtcOffset": "-14400s",
          "endTime": "2026-06-07T22:30:00Z",
          "endUtcOffset": "-14400s",
          "type": "LIGHT"
        },
        {
          "startTime": "2026-06-07T22:30:00Z",
          "startUtcOffset": "-14400s",
          "endTime": "2026-06-07T23:45:00Z",
          "endUtcOffset": "-14400s",
          "type": "DEEP"
        },
        {
          "startTime": "2026-06-07T23:45:00Z",
          "startUtcOffset": "-14400s",
          "endTime": "2026-06-08T02:15:00Z",
          "endUtcOffset": "-14400s",
          "type": "LIGHT"
        },
        {
          "startTime": "2026-06-08T02:15:00Z",
          "startUtcOffset": "-14400s",
          "endTime": "2026-06-08T02:45:00Z",
          "endUtcOffset": "-14400s",
          "type": "REM"
        },
        {
          "startTime": "2026-06-08T02:45:00Z",
          "startUtcOffset": "-14400s",
          "endTime": "2026-06-08T05:15:00Z",
          "endUtcOffset": "-14400s",
          "type": "LIGHT"
        },
        {
          "startTime": "2026-06-08T05:15:00Z",
          "startUtcOffset": "-14400s",
          "endTime": "2026-06-08T06:00:00Z",
          "endUtcOffset": "-14400s",
          "type": "REM"
        }
      ]
    }
  }
}
```

## Sleep efficiency and latency metrics

In addition to sleep stages and physiological metrics, the API provides key
metrics that quantify sleep quality and sleep onset. Sleep efficiency and sleep
onset latency are standard clinical metrics that describe how effectively a user
rests relative to their total time in bed, providing insight into sleep hygiene
and restfulness.

### Sleep efficiency score

Sleep efficiency is a standard metric defined as the proportion of time spent
asleep relative to total time spent in bed. The API computes sleep efficiency
using the following formula:

    Sleep Efficiency Score = round( (Total Minutes Asleep / Total Minutes In Bed) * 100 )

The efficiency score is calculated just before sleep level (stages)
partitioning. The total minutes asleep returned in the API response (in the
`summary.minutesAsleep` field) reflects the final result after sleep levels are
computed.

If a user or researcher manually modifies the start or end time of a sleep log,
the API recalculates the sleep efficiency score and adjusts stage partitions
according to sensor data recorded within the new bedtime and waketime boundary.

### Sleep onset latency

Sleep onset latency measures the time elapsed from when a user intends to
fall asleep (the start of "in bed" or "lights out" time) until sleep onset
occurs.

For logs generated automatically (`metadata.manuallyEdited` is `false`),
`summary.minutesToFallAsleep` defaults to `"0"` because no explicit intent to
fall asleep was logged. When in-bed start times are manually recorded or edited
(`metadata.manuallyEdited` is `true`), the API computes and populates
`summary.minutesToFallAsleep` along with `summary.minutesAfterWakeUp`.

### Guidance for research and manual logging

When participants manually record or adjust in-bed start and end times:

1. Updating in-bed boundaries changes the sleep `interval` (and `summary.minutesInSleepPeriod`).
2. Sleep levels and stage partitions automatically adjust to evaluate sensor data within the new window.
3. Sleep efficiency score, `summary.minutesToFallAsleep`, and `summary.minutesAfterWakeUp` are re-derived based on the updated time window.

## Daily sleep temperature derivations

Daily Sleep Temperature Derivations measure the variation in a user's skin
temperature during sleep compared to their baseline. This data is typically
reported once per day after a major sleep session.

## Respiratory rate

Respiratory rate measures the user's breaths per minute. During sleep, it is a
key metric for monitoring sleep quality and potential disturbances. The API
supports sample respiratory rate (`respiratory-rate`), daily summaries
(`daily-respiratory-rate`), and session-level sleep summaries
(`respiratory-rate-sleep-summary`).

## Heart rate variability (HRV)

HRV measures the variation in time between each heartbeat. It is a key
indicator of the autonomic nervous system's state; high HRV during sleep
generally signifies better recovery and readiness, while low HRV can indicate
stress or overtraining. The API supports sample HRV (`heart-rate-variability`)
and daily summaries (`daily-heart-rate-variability`).

## Oxygen saturation

Blood oxygen saturation (SpO2) represents the percentage of oxygen-saturated
hemoglobin relative to total hemoglobin in the blood. Monitoring SpO2 during
sleep helps detect potential breathing disturbances and confirms whether the
user maintains adequate oxygen levels throughout the night. The API supports
sample SpO2 (`oxygen-saturation`) and daily summaries
(`daily-oxygen-saturation`).

When you query minute-level `oxygen-saturation`, the Google Health API returns
only validated data points and filters out invalid measurements caused by
arm movement, a loose wrist fit, or low sensor confidence (under 50%), as well
as readings adjacent to motion noise. Because invalid minutes are excluded,
minute-level coverage can be sparse and timestamp gaps are expected. Both
`oxygen-saturation` and `daily-oxygen-saturation` rely on the same validated
readings. For details on the validation criteria, see [Minute-level SpO2
filtering and data validity](https://developers.google.com/health/data-types/vitals#spo2-filtering).

## Holistic view of sleep health and recovery

While each metric provides specific insights, they are deeply interrelated and
together offer a holistic view of a user's recovery. Sleep stages (Light, Deep,
REM) provide the structural foundation of rest, while physiological markers
like HRV and SpO2 indicate how the body is physically responding to that rest.
For example, a high-quality sleep session with optimal Deep sleep often
correlates with higher HRV, signifying effective recovery of the autonomic
nervous system.

Combining these with respiratory rate and sleep temperature derivations allows
applications to identify potential disturbances. A sudden spike in respiratory
rate or a deviation in sleep temperature can contextualize why a user might
have spent less time in restorative stages. By analyzing these data types in
tandem, developers can provide a comprehensive assessment of sleep hygiene and
long-term health trends.

## Guidelines

When integrating sleep metrics in your app, use these guidelines:

- **Session Detail** : To show a user's sleep stages (Light, Deep, REM, Awake) and short awakenings, query the `sleep` data type.
- **Nocturnal Awakenings** : To track mid-night wake events without raw sensor streams, inspect the `sleep` stage intervals and filter for items with `type: "AWAKE"` (for both `STAGES` and `CLASSIC` sleep logs) or inspect `outOfBedSegments`.
- **Latency and Efficiency** : Use `summary.minutesToFallAsleep` and the sleep efficiency formula for sleep latency analysis. Note that `summary.minutesToFallAsleep` is populated when sleep logs are manually edited (`metadata.manuallyEdited` is `true`) or explicitly logged.
- **Physiological Monitoring** : For advanced health monitoring, combine the sleep session data with physiological and recovery metrics such as `respiratory-rate-sleep-summary`, `daily-sleep-temperature-derivations`, `daily-heart-rate-variability`, and `daily-oxygen-saturation`.
- **Reconciliation** : Use the `reconcile` operation to ensure that overlapping sleep logs from different devices (for example, a wearable and a mattress sensor) are merged into a single "main" sleep record.

## Calculate total time in deep sleep

To calculate the total time a user spent in a restorative deep sleep stage for
a specific night:

1. Query the `sleep` data type for the specified time range.
2. Iterate through the stages list and identify intervals where the `type` is `DEEP`.
3. Calculate the duration (End Time - Start Time) for each deep sleep interval and sum them.

The resulting sum provides the total physical duration of deep sleep for that
session.