cyberjunky / python-garminconnect

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

Body battery #115

Closed ZooLee77 closed 12 months ago

ZooLee77 commented 1 year ago

Hello,

Thank you for make this project! I make a report for my coach, but I cannot find the body battery values. How can I see it?

Thanks, Zoltan

psdupvi commented 1 year ago

I was able to find them in get_stats_and_body (option 7 in example.py) and `get_stats' (option 3 in example.py)

You should see values in the top level of the return that look like this:

... , 'bodyBatteryChargedValue': 56, 'bodyBatteryDrainedValue': 50, 'bodyBatteryHighestValue': 83, 'bodyBatteryLowestValue': 27, 'bodyBatteryMostRecentValue': 33, 'bodyBatteryVersion': 2.0, ...

E.g., to get the most recent value:



today = date.today()
USERNAME = 'your-username'
PASSWORD = 'your-password'

api = Garmin(USERNAME,PASSWORD)
api.login()

stats = api.get_stats(today)

print(stats['bodyBatteryMostRecentValue'])```
ZooLee77 commented 1 year ago

Thank you! I saw it, but I want to make a graph about the BB values for a day. Stress and steps are there. It is hard to see if I have a low BB from the morning then go to exercise or get a high BB so the exercise was the cause to get low at the end.

cyberjunky commented 1 year ago

@ZooLee77 in 0.1.52 you can find a new body battery API call (option / in example.py) It returns an array for each day... Hope you can use it, if you want to share your project please let us know, I'm planning on creating a 'used by:' section in the README to list projects using this package... some are quite nice and exciting.

ZooLee77 commented 1 year ago

@cyberjunky Thank you! It works, however it is very limited. Only 6 datapoints are exist for a day, while web page shows multiple. Anyway it works and good for now. E.g.: api.get_body_battery(startdate.isoformat())[0]["bodyBatteryValuesArray"] [[1674255600000, 44], [1674281340000, 100], [1674284400000, 100], [1674290700000, 97], [1674338580000, 41], [1674341820000, 44]]

Honestly my code is a crap, but works. Have to make some comments and simplification, then I can share it. Download the latest activity, make diagram from the FIT file, and collect other metrics as well, so thank you, it is based on your API.

cyberjunky commented 1 year ago

@ZooLee77 did you made the progress you wanted with your script?

ZooLee77 commented 1 year ago

Almost, I think the BB is comming from the report section, where there is some limited number of data point for a day:https://connect.garmin.com/modern/report/84/wellness But there is a detailed report under the daily report for that e.g.: https://connect.garmin.com/modern/daily-summary/2023-03-28/bodyBattery

Do you have any idea if the second one is reachable via API?

matin commented 1 year ago

Using #144, you can do the following:

Summary

garmin.connectapi("/wellness-service/wellness/dailySummaryChart?date=2023-03-28")
[{'startGMT': '2023-03-28T06:00:00.0',
  'endGMT': '2023-03-28T06:15:00.0',
  'steps': 0,
  'pushes': 0,
  'primaryActivityLevel': 'none',
  'activityLevelConstant': True},
 {'startGMT': '2023-03-28T06:15:00.0',
  'endGMT': '2023-03-28T06:30:00.0',
  'steps': 0,
  'pushes': 0,
  'primaryActivityLevel': 'none',
  'activityLevelConstant': True},
 {'startGMT': '2023-03-28T06:30:00.0',
  'endGMT': '2023-03-28T06:45:00.0',
  'steps': 0,
  'pushes': 0,
  'primaryActivityLevel': 'none',
  'activityLevelConstant': True},
...
]

Heart rate

garmin.connectapi("/mobile-gateway/heartRate/forDate/2023-03-28")
{'ActivitiesForDay': {'requestUrl': '/activitylist-service/activities/fordailysummary/mtamizi',
  'statusCode': 200,
  'headers': {},
  'errorMessage': None,
  'payload': [{'activityId': 10793581482,
    'activityName': 'Cuajimalpa de Morelos Senderismo',
    'description': None,
    'startTimeLocal': '2023-03-28T10:47:08.0',
    'startTimeGMT': '2023-03-28T15:47:08.0',
    'activityType': {'typeId': 3,
     'typeKey': 'hiking',
     'parentTypeId': 17,
     'isHidden': False,
     'restricted': False,
     'trimmable': True},
    'eventType': {'typeId': 9, 'typeKey': 'uncategorized', 'sortOrder': 10},
    'distance': 5019.169921875,
    'duration': 2796.4970703125,
    'activeSplitSummaryDuration': None,
    'ownerId': 2591602,
    'ownerDisplayName': 'mtamizi',
    'calories': 475.0,
    'floorsClimbed': None,
    'bmrCalories': 68.61775218822338,
    'activeCalories': 406.3822478117766,
...
  'successful': True},
 'SleepTimes': {'currentDaySleepEndTimeGMT': 1680009660000,
  'currentDaySleepStartTimeGMT': 1679981400000,
  'nextDaySleepEndTimeGMT': 1680095040000,
  'nextDaySleepStartTimeGMT': 1680066000000}}

Those are the endpoints the mobile app uses.

cyberjunky commented 1 year ago

@matin so i need to add these calls I guess ;-)

cyberjunky commented 1 year ago

For daily stepsdata above see option 8 in example.py, for heartrate 9, and newly added above one as 'I' get_activities_fordate()

matin commented 12 months ago

156 solves this

cyberjunky commented 12 months ago

Available in version 0.2.7

ZooLee77 commented 11 months ago

Thank you! I made the repo public, because I do not have time to clean, but want to share it: https://github.com/ZooLee77/Report_to_Coach