YorkshireIoT / ha-google-fit

Home Assistant Google Fit Custom Component
MIT License
98 stars 9 forks source link

Feature request: Add "Calories consumed" Entity #146

Open ELind77 opened 1 year ago

ELind77 commented 1 year ago

Checklist

Is your feature request related to a problem? Please describe.

As a user, I would like to be able to see the "calories consumed" data that my third party applications write to Google Fit in Home Assistant.

Describe the solution you'd like

When I have a third-party integration with Google fit that adds calorie consumption data to Google Fit, I would like that data to be available in Home Assistant.

Concretely, when I go to the Entities section of the HASS Integtations page for Google Fit, I would like to see, "Calories consumed" as a row in the presented table with values pulled from my calorie tracking app.

Ideally, I'd like it if this integration could auto-discover new metrics in Google Fit as they emerge but I'm not sure if that's possible with the API.

Describe alternatives you've considered

I have looked around for calorie tracking apps with APIs that integrate with Home Assistant and I haven't found anything that works for me. It looks like there is a MyFitnessPal integration but it hasn't been updated in 5 years and I think using Google Fit as a hub API is a better long term solution than relying on individual end-user apps.

Additional context

I'm a passable Python developer and I skimmed the repo but I haven't built a HASS integration before and I'm not sure I'd be much help with the amount of time I have to contribute but this is something I want so, if nothing else, I'm motivated.

YorkshireIoT commented 12 months ago

Hi @ELind77, I've put this on the backlog because it's not going to be done in the near future as there are other quality of life things I won't to focus on first.

If you're up to it, feel free to have a stab at it yourself. Just fork the repository and as a starting point the calories burnt is probably the best sensor to copy. It's really not too much work, biggest sticking point would be if it needed a new access permission so be sure to check that

ELind77 commented 12 months ago

Thanks for the response. I'll explore implementing it myself. I have some questions along that direction though.

  1. Is this commit a good example for me to follow for what I'm trying to do? https://github.com/YorkshireIoT/ha-google-fit/commit/85c03c05dd2aefc1b8bfa0867cfed32163c33559
  2. How do I find the equivalent of the class path-looking thing for the new data type? https://github.com/YorkshireIoT/ha-google-fit/blob/main/custom_components/google_fit/const.py#L85
  3. After looking at the docs briefly, I'm concerned I won't be able to access this additional data type. It says:

Note: Custom data types are only available to the apps that created them. Other apps can't see or use your custom data types.

Do you think that means there's no way for HASS to read the "CaloriesConsumed" data? Is there an easy way for me to test things like this in the package? Either interactively or with a script I can run to check error messages and whatnot?

YorkshireIoT commented 12 months ago
1. Is this commit a good example for me to follow for what I'm trying to do? [85c03c0](https://github.com/YorkshireIoT/ha-google-fit/commit/85c03c05dd2aefc1b8bfa0867cfed32163c33559)

Yeh, although if you want an example where only 1 sensor is added commit 364b6de might be better

2. How do I find the equivalent of the class path-looking thing for the new data type? https://github.com/YorkshireIoT/ha-google-fit/blob/main/custom_components/google_fit/const.py#L85

That's a good point, I forgot about that. It's actually a bit of a pain. First you need to make sure you actually have some valid data in your Google Fit account for the sensor type you're looking for.

Then you need to go here, find the sensor data you want to read and look at the OAuth Permission Scope.

Then you have to go to the Google API Playground, authorize using that same permission scope for Fitness v1 and exchange the tokens for you account.

Finally, in the Request URI enter this: https://fitness.googleapis.com/fitness/v1/users/me/dataSources and send the request. In the response you're looking for something that starts with dervied and ends with merged that matches what you want.

3. After looking at [the docs](https://developers.google.com/fit/datatypes/custom) briefly, I'm concerned I won't be able to access this additional data type.  It says:

Note: Custom data types are only available to the apps that created them. Other apps can't see or use your custom data types.

As long as your third-party provider has implemented the data type properly using one of the existing data types then this shouldn't be a problem. Google does have a nutrition sensor type which contains calories consumed.

Do you think that means there's no way for HASS to read the "CaloriesConsumed" data? Is there an easy way for me to test things like this in the package? Either interactively or with a script I can run to check error messages and whatnot?

This is actually a bit of a deficiency in CONTRIBUTING.md docs. I'm going to quickly update this so it's easier to get started with developing.

⚠️ Having said all that though, having looked at the sensor type in the Google docs I wouldn't advise tackling this as a good first time change. It looks like the nutrition sensor is a lot more involved than just querying its native type, as the calories data is embedded deeper within the data. That means there will need to be some more fundamental updates to the code base to accomodate this new type.

lunarok commented 10 months ago

I'm interested in that one also (using more and more the Health hub and now having also the food in it) I check quickly and yes seems different. If I can help, I'm willing, but not sure I can do it alone.

Ni3kjm commented 6 months ago

Great work guys, Just wanted to say, I would love to see this feature for calories consumed to graph alongside calories burned for comparison 😁