MyFitness Pal

I was going to start a new topic for just this, but figured I should probably see if somebody here was still on this…

It is possible to use python to access myfitnesspal without registering to their API (which I tried, but no success yet) via the myfitnesspal library.

Here is a script I just put together. Do any of you know how to integrate this into Home Assistant? There is pyscript (HACS addon), but I have not worked with it yet myself…

#!/usr/bin/env python3

import myfitnesspal

client = myfitnesspal.Client(my_username, password=my_password)

day = client.get_date(2021, 1, 17)
print(day)

weight = client.get_measurements('Weight')
print(weight)

activities = day.exercises[0].get_as_list()
print(activities)

This will return

01/17/21 {'calories': 1830.0, 'carbohydrates': 273.0, 'fat': 36.0, 'protein': 79.0, 'sodium': 19364.0, 'sugar': 62.0}

OrderedDict([(datetime.date(2021, 1, 17), most_recent_weight), (datetime.date(2021, 1, 13), second_most_recent_weight)])

[{'name': 'Running (jogging), 8 kph (7.5 min per km)', 'nutrition_information': {'minutes': 61.0, 'calories burned': 741.0}}]

I really hope this sodium value has been calculated incorrectly…


I am considering working on a script that will request the activities per day, then writes them to an influxdb. Perhaps I’ll do the same for the weight data, but I already log it via OpenMQTTGateway and node-red in an influxdb database.

However!! I am a hobbyist spaghetti coder. While I won’t mind sharing the code here if I got somewhere, it won’t be well written, bug free, or guaranteed to work that great.

So have any of you already done this? Either integrated myfitnesspal into Home Assistant directly, or perhaps written something that will publish these values locally via mqtt (so that Home Assistant, or any other tool, could easily access them)?

1 Like