Pebble.Health

Access Pebble Health data such as step count, active time, distance, sleep, calories, heart rate, and heart-rate variability.

Check supported first on older watches, then request metrics and subscribe to service events for live updates.

import Pebble.Health as Health

type Msg
    = GotSupported Bool
    | GotSteps Int
    | HealthEvent Health.Event

init _ =
    ( model
    , Cmd.batch
        [ Health.supported GotSupported
        , Health.value Health.StepCount GotSteps
        ]
    )

subscriptions _ =
    Health.onEvent HealthEvent

Heart-rate variability is collected only while an app holds an HRV sample period. Use setHrvSamplePeriod to start sampling and hrvPpiMs to read the latest peak-to-peak interval. HRV requires firmware 4.32+ on watches whose sensor supports it.

For a runnable example, use the watch-demo-health project template in the IDE.

Native Pebble C API

Types

Metric

type Metric
    = StepCount
    | ActiveSeconds
    | WalkedDistanceMeters
    | SleepSeconds
    | RestfulSleepSeconds
    | RestingKCalories
    | ActiveKCalories
    | HeartRateBPM

A Pebble health metric.

Event

type Event
    = SignificantUpdate
    | MovementUpdate
    | SleepUpdate
    | HeartRateUpdate
    | HrvUpdate

A Pebble health service event.

Commands

supported

supported : (Bool -> msg) -> Cmd msg

Request whether the Health API is available on this watch.

value

value : Metric -> (Int -> msg) -> Cmd msg

Request the current value for a metric.

For example, value StepCount GotSteps requests the current step count.

sumToday

sumToday : Metric -> (Int -> msg) -> Cmd msg

Request today's total for a metric.

sum

sum : Metric -> Int -> Int -> (Int -> msg) -> Cmd msg

Request the total for a metric between two Unix timestamps in seconds.

accessible

accessible : Metric -> Int -> Int -> (Bool -> msg) -> Cmd msg

Request whether a metric is available between two Unix timestamps in seconds.

hrvPpiMs

hrvPpiMs : (Int -> msg) -> Cmd msg

Request the latest heart-rate variability peak-to-peak interval in milliseconds.

Returns 0 when no reading is available yet, or when the watch/firmware does not support HRV.

setHeartRateSamplePeriod

setHeartRateSamplePeriod : Int -> Cmd msg

Request a heart-rate sample period in seconds.

Pass 0 to release the request. Heart-rate and HRV sample periods are independent and share the app's sensor subscription.

setHrvSamplePeriod

setHrvSamplePeriod : Int -> Cmd msg

Request an HRV sample period in seconds.

Pass 0 to stop HRV collection. HRV is only sampled while a period is held.

Subscriptions

onEvent

onEvent : (Event -> msg) -> Sub msg

Receive health service events.