Skip to main content

Sleep process

Introduction

The sleep is monitored on the bracelet, the data is sync to the SDK, then the sleep is processed in the morning to have a sleep session with start / stop and sleep slots.

Requirements

Settings for sleep

Sleep explained

Sleep is a complex matter, as we don't all have the same behavior during our sleep. The sleep needs to be accurate for different situation:

  • No wake up during the night
  • Wakes up and get out of bed to go to the bathroom
  • User checks their phone as soon as they wake up, or later during the day

Monitoring period

Start of sleep monitoring on the bracelet

The sleep is monitored on the bracelet from bedtime - 2h.

End of sleep monitoring on the bracelet

In the morning, starting from risetime - 2h, the bracelet detect activity from the user, if the user is active, then the sleep is stopped. If no activity is detected, the sleep monitoring will be stopped at risetime + 3h.

It is possible to stop the sleep manually, by sending a stop sleep command through the SDK. Why a manual stop? The manual stop is useful for the last situation "Use checks their phone as soon as they wake up". If the user is still in bed, and check their phone, it is possible that no activity is detected as the person stays in bed. We recommand putting a "Stop sleep now" button in your app, if no activity is detected but the user wants to check their sleep, they can click on the button, sleep will be stopped and ready soon after that.

Manual stop technically

Sleep analysis

1) Sleep Monitoring on the bracelet

2) Continuous sync to the SDK during the night or in the morning

3) Activity detected on the bracelet, sleep monitoring stopped on the bracelet

4) Sync to the SDK detects the stop sleep, launches the sleep processing

5) Sleep is ready with start time, stop time, sleep stages: light sleep / deep sleep / awake period / REM sleep

Manual Stop sleep

By sending the stop sleep command to the bracelet, the sleep process will be stopped. 2 minutes after the sleep process will give a result.

Send stop sleep:

dataSdkManager?.sleepProcessUpdater?.sendStopSleep(bleDevice,

The bracelet has to be connected for it to succed.

Sleep process technically

The sleep data is transfered to the SDK continuoustly. Throught the night, the sleep data is synced to SDK. Technically it consist of saving the bytes into .wiff.part files.

This process of those files is triggered automatically in the sync process of the bracelet.

When the sleep monitoring is stopped on the bracelet, the .part.wiff files are combined into a single .wiff file.

The .wiff is processed by the Philips Library (in the SDK) and will give a sleep session.

A wiff file can contain multiple nights, and multiple sleep sessions.

The app tries to process the wiff file 4 times maximum, if a sleep session cannot be identified (bracelet not worn during the night for example), the wiff file will be deleted. There is a 2 minutes delay between each trials.

Sleep session

The sleep monitoring provides a sleep session (start, stop, 30 seconds slots), then the sleep session is filtered to obtain the best user friendly result. Here are the filtering steps:

  • Remove awake blocks at the beginning and the end of the night.
    • The sleep will always start and end with a sleep stage (light / REM / deep)
  • Noice filtering: the graph is flattened, the slots have to last at least 2 min straight
    • Example: REM sleep during 20 min, then one 30 seconds awake slot, and after 10 more minutes of REM sleep: the 30s awake will be filtered and will not appear
  • 1 minute slots
    • Slots have 0 seconds (22:01:00, 22:02:00, etc)
    • Start and stop time have 0 seconds too

Sleep status

To check where we are in the sleep process the following function can be called

fun getSleepState(
braceletPlan: DevicePlan,
sleepSummaryRepository: SleepSummaryRepository,
heartRateSummaryRepository: HeartRateSummaryRepository,
localSettingRepository: LocalSettingRepository,
dayDate: Date,
risetime: HourMinuteRecord,
onDone: (PhilipsSleepState) -> Unit
)

It will return the following enum

enum class PhilipsSleepState {
NOT_AVAILABLE_WATCH_NOT_WORN, // watch not worn (verified with HRM data, no HRM during the night)
AVAILABLE, // ready and stored in DB
IS_TODAY_AND_IS_ONGOING, // sleep still being recorded on the bracelet
IS_TODAY_AND_IS_PROCESSING, // recording stopped on the bracelet, processing on the app side
IS_TODAY_AND_IS_PROCESSING_FROM_PROCESS_NOW, // recording stopped on the bracelet using the "Stop Sleep" button on the app, processing on the app side
NOT_AVAILABLE // Philips process couldn't identify a sleep
}