android icon indicating copy to clipboard operation
android copied to clipboard

Implement Health Connect Sensors

Open psbankar opened this issue 1 year ago β€’ 8 comments

Summary

Implementing health connect API to create various sensors.

Screenshots

Link to pull request in Documentation repository

TODO

Any other notes

Issue #2537

I have just implemented a few data points from the Health Connect API. Still a lot more work to do. Creating a pull request to set the task in motion and getting others opinions. List of sensors that can be implemented: https://developer.android.com/reference/kotlin/androidx/health/connect/client/records/package-summary#classes Further action required -

According to the nature of Home Assistant, it can come under Fitness and Wellness use case

psbankar avatar Jun 12 '24 02:06 psbankar

This is awesome but i think will require some thought about how to get required stuff from Google before/after the PR is accepted/merged. I suppose maybe its best to first try for approval and go from there? Honestly speaking its tough to say what Google will say the app can qualify for. For example we do not qualify for all the permissions Tasker is approved for, otherwise we would be able to restore our call number sensor.

dshokouhi avatar Jun 14 '24 17:06 dshokouhi

This is awesome but i think will require some thought about how to get required stuff from Google before/after the PR is accepted/merged. I suppose maybe its best to first try for approval and go from there? Honestly speaking its tough to say what Google will say the app can qualify for. For example we do not qualify for all the permissions Tasker is approved for, otherwise we would be able to restore our call number sensor.

In order to actually request the permissions we need to upload a version that requests the permissions. There isn't a way without merging to start the approval requests.

JBassett avatar Jun 14 '24 19:06 JBassett

initial tests look great!

image

lots of decimals returned for calories burned....strangely it does not match the amount we get from health services where the data is taken from the watch directly...maybe fitbit is doing its own thing?

image

https://github.com/home-assistant/android/blob/master/wear/src/main/java/io/homeassistant/companion/android/sensors/HealthServicesSensorManager.kt#L359

dshokouhi avatar Jun 14 '24 21:06 dshokouhi

lots of decimals returned for calories burned....strangely it does not match the amount we get from health services where the data is taken from the watch directly...maybe fitbit is doing its own thing?

Fixed the precision to 2 decimals. And can you check in the Health Connect logs where the additional 3 kcal is coming from? Some other app might be writing into health connect or maybe my logic to calculate total calories is incorrect.

psbankar avatar Jun 15 '24 03:06 psbankar

Another requirement for getting approval is displaying privacy policy when clicked on Health Connect permissions page. For this, we can either

  • add code at the beginning of onCreate in LaunchActivity to receive intent and redirect directly to privacy policy webpage
  • or redirect user to the settings page where there the privacy policy item is listed.

psbankar avatar Jun 15 '24 04:06 psbankar

And can you check in the Health Connect logs where the additional 3 kcal is coming from? Some other app might be writing into health connect or maybe my logic to calculate total calories is incorrect.

the difference is expected there actually, the health services sensor update every 15 minutes however I think fitbit will sync once an hour so I wouldnt expect them to have the same value but should be fairly close.

Here is an overnight graph for comparison

health connect image

health services image

Another requirement for getting approval is displaying privacy policy when clicked on Health Connect permissions page. For this, we can either

  • add code at the beginning of onCreate in LaunchActivity to receive intent and redirect directly to privacy policy webpage
  • or redirect user to the settings page where there the privacy policy item is listed.

personally I am indifferent on where to put it however we already have a privacy policy mention in our settings page so I think another one can't hurt. Can we maybe combine them?

dshokouhi avatar Jun 15 '24 23:06 dshokouhi

On clicking privacy policy on Health Connect permission page, it will redirect to Home Assistant privacy policy webpage

psbankar avatar Jun 16 '24 23:06 psbankar

I see a lot of chat about google approval. Are we likely to see this in the app soon? I'm excited to get some fitness data after This Google Fit Integration Said the fit API has been deprecated (for new users at least).

glennmca-dev avatar Jun 22 '24 11:06 glennmca-dev

This PR is failing to push to the play store as we now need to submit for approval. Have requested the correct people to do so for us so hopefully we will hear back soon. Until then this will be holding up PR's being merged and sent to the play store until resolved.

dshokouhi avatar Aug 05 '24 16:08 dshokouhi

According to the docs the app should be able to publish to the Play Store before approval. The users see a different permission popup if there is no approval.

psbankar avatar Aug 05 '24 16:08 psbankar

According to the docs the app should be able to publish to the Play Store before approval. The users see a different permission popup if there is no approval.

yea the action is failing suggesting thats not the case :) the action attempts to push to our internal beta track which is where this is failing

[16:14:57***: Google Api Error: Invalid request - You need approval to use the following Health Connect permissions in your app: android.permission.health.READ_ACTIVE_CALORIES_BURNED,android.permission.health.READ_TOTAL_CALORIES_BURNED,android.permission.health.READ_WEIGHT. Learn more: https://support.google.com/googleplay/android-developer/answer/12991134

I believe by publish they mean an app that has never published and does not have health connect features in it which we are already a published app.

dshokouhi avatar Aug 05 '24 16:08 dshokouhi

BTW if approval with Google is successful we were thinking that due to https://github.com/home-assistant/android/pull/4552 we shoudl probably go for adding a heart rate sensor next to bring the data back to some extent

dshokouhi avatar Aug 05 '24 17:08 dshokouhi

Health connect form submitted, now to wait 7-14 business days. Hopefully we wont see too much back and forth here.

dshokouhi avatar Aug 09 '24 15:08 dshokouhi

Can't wait to see all other sensors implemented after this succeeds.

bazb avatar Aug 09 '24 16:08 bazb

@dshokouhi hoping you might have an update for us?

wwelles avatar Aug 30 '24 15:08 wwelles

@wwelles unfortunately no updates from Google yet. Today is actually the last business day for them to respond. I also just noticed that they changed their policy and those changes take place TOMORROW (what are the odds right? πŸ˜‚ )

https://support.google.com/googleplay/android-developer/answer/9888170?sjid=4865781794872932585-NC

We’re updating our [Health Connect policy](https://support.google.com/googleplay/android-developer/answer/13986130) to streamline the Health Connect application process and align with the Health Apps policy. The existing form-based application will be replaced with a new Play Console declaration later this year. (effective August 31, 2024)

We actually already have approval for Health Apps declaration as we are using the Body Sensor permission for Heart Rate on Wear OS and Activity Detection on the phone so hopefully the new process will be easier and faster. Our current approval is for Activity and Fitness which is very similar to Fitness and Wellness category we initially applied for.

Given that once approved we have mostly everything lined up to push the next beta. We actually have another deadline that is up TODAY that will also impact the releases so a lot is held up here.

dshokouhi avatar Aug 30 '24 15:08 dshokouhi

Appreciate all the hard work that's gone into this, hopefully they'll update us soon!

Al-Girard avatar Sep 05 '24 13:09 Al-Girard

Hey all just wanted to give a quick update. We were finally able to submit our health connect declaration to Google last night and its in reviewnow. Given we get approval, next weeks beta (2024.10.2-full) should contain the new sensors!

dshokouhi avatar Oct 06 '24 16:10 dshokouhi

We have received approval for the set of health connect permissions in this PR! So next weeks beta (2024.10.2.-full) will contain the new sensors, once approved of course. Thanks again for the PR @psbankar πŸ™ ! For now I will leave #2537 open so the discussion on adding remaining sensors can continue there. (These are a good Hacktoberfest item for anyone interested, speaking of which these sensors can also use a companion app docs update 😜 )

dshokouhi avatar Oct 07 '24 05:10 dshokouhi

What new beta? the home assistant beta (2024.10.2.-full)?

mapsindustrial avatar Oct 09 '24 09:10 mapsindustrial

Do we have any new good news?

mapsindustrial avatar Oct 13 '24 11:10 mapsindustrial

@mapsindustrial as mentioned twice already the build is now waiting for approval from Google and once done it will be part of the apps beta program.

https://play.google.com/apps/testing/io.homeassistant.companion.android

dshokouhi avatar Oct 13 '24 17:10 dshokouhi