cyberjunky / python-garminconnect

Python 3 API wrapper for Garmin Connect to get activity statistics
MIT License
964 stars 149 forks source link

Pulling HRV #175

Closed esmoyer closed 8 months ago

esmoyer commented 1 year ago

I don't think this is an issue, more just checking my sanity. I have a Venu2 and am able to see HRV values doing the Health Snapshot; so I assume the data is somewhere, but when I use the example.py to pull HRV it just give me none. So before i dug too much into it, does anyone happen to know if maybe the HRV data is stored differently for the Venu2?

I tried to use Postman to query but am getting 400 bad request errors; so I am obviously missing something; I have tried a couple different URLs which I assume is my issue: (ie https://connect.garmin.com/proxy/hrv-service/hrv/2023-11-07).

I am trying to pull HRV into https://github.com/stratus-ss/garmin-influxdb. If anyone has some additional insight that could point me in some direction or tell me that the HRV data from the Venu2 is available; it would be greatly appreciated!

psdupvi commented 8 months ago

Sorry for the very long delayed response

I believe that if you have to do HRV via a Health Snapshot, it would be stored in the Activity Data for that activity, and not in the general HRV stats data.

Specifically, if I follow the Garmin calls, I see two endpoints that appear to have most of the data: https://connect.garmin.com/wellnessactivity-service/activity/summary/{date}/{health_snapshot_uuid} https://connect.garmin.com/wellnessactivity-service/activity/epoch/{health_snapshot_uuid}

There are sample outputs from my data below, using a Forerunner 955 Solar. I imagine yours will be similar

The epoch endpoint returns data like the following:

{
    "userProfilePK":" int",
    "activityUuid": "string",
    "epochDescriptorDTOList": [
        {
            "key": "timestamp",
            "index": 0
        },
        {
            "key": "heartRate",
            "index": 1
        },
        {
            "key": "stress",
            "index": 2
        },
        {
            "key": "spo2",
            "index": 3
        },
        {
            "key": "respiration",
            "index": 4
        }
    ],
    "epochArray": [
        [
            1673997196000,
            72.0,
            6.0,
            null,
            18.010000228881836
        ],
        ...

The summary endpoint returns data like:

{
    "userProfilePk": "int",
    "activityUuid": {
        "uuid": "string"
    },
    "calendarDate": "2023-01-17",
    "rulePK": 2,
    "activityName": "Health Snapshot - Evening",
    "notes": null,
    "wellnessActivityType": "HEALTH_MONITORING",
    "startTimestampGMT": "2023-01-17T23:13:16.0",
    "endTimestampGMT": "2023-01-17T23:15:16.64",
    "startTimestampLocal": "2023-01-17T18:13:16.0",
    "endTimestampLocal": "2023-01-17T18:15:16.64",
    "summaryTypeDataList": [
        {
            "summaryType": "HEART_RATE",
            "minValue": 62.0,
            "maxValue": 72.0,
            "avgValue": 66.0
        },
        {
            "summaryType": "RESPIRATION",
            "minValue": 17.799999237060547,
            "maxValue": 18.940000534057617,
            "avgValue": 18.100000381469727
        },
        {
            "summaryType": "STRESS",
            "minValue": 6.0,
            "maxValue": 18.0,
            "avgValue": 12.0
        },
        {
            "summaryType": "RMSSD_HRV",
            "avgValue": 125.0
        },
        {
            "summaryType": "SDRR_HRV",
            "avgValue": 155.0
        }
    ],
    "timeInZoneList": [
        {
            "zoneNumber": 0,
            "millisInZone": 120000,
            "zoneLowBoundary": 0
        },
        {
            "zoneNumber": 1,
            "millisInZone": 0,
            "zoneLowBoundary": 75
        },
        {
            "zoneNumber": 2,
            "millisInZone": 0,
            "zoneLowBoundary": 111
        },
        {
            "zoneNumber": 3,
            "millisInZone": 0,
            "zoneLowBoundary": 127
        },
        {
            "zoneNumber": 4,
            "millisInZone": 0,
            "zoneLowBoundary": 142
        },
        {
            "zoneNumber": 5,
            "millisInZone": 0,
            "zoneLowBoundary": 152
        }
    ],
    "deviceMetaData": {
        "deviceId": "int",
        "deviceTypeId": 37010,
        "deviceVersionId": 913610,
        "deviceVersion": "14.8.0.0",
        "deviceName": "Forerunner 955 Solar"
    }
}

I also found https://connect.garmin.com/wellnessactivity-service/activity/summary/list?limit=20&start=1&until=2024-03-11, which returns a list of all the Health Snapshot activities. The output here is basically a list of the summary responses, for each activity. You could probably use that to get the UUID if you need the epoch data, or just use only that endpoint if all you care about is the summary data

esmoyer commented 8 months ago

No worries. I appreciate the detail. I actually just upgraded to the Venu3 and am able to pull in the HRV I was looking for now. Thank you!