[iOS Feature Request] Apple Healthkit Integration

It seems we’re already utilizing some of the iOS platform integrations within HomeAssistant, however not HealthKit.
Currently the health section of components is lacking abit which is then causing us to build our own integrations - With this data already in an accessible place.

I currently have a python script running to poll for changes to my logged weight on Myfitnesspal to then return it to a sensor within Home Assistant. This is a long winded way of retrieving data I originally store in Apple Health.

Could healthkit integration be looked into?

3 Likes

I hope this gets integrated as well. I’ve been asking about this since the first ios app beta I tried.
I want a sensor for my steps mainly so I can easily see my progress and get notified if I need to do a bit more steps at the end of the day for example.

if you are using owntracks: owntracks does send steps and walking-distances that are stored in healthkit if polled. i’m using it successfully as a step sensor:

@diplix thanks for sharing this! I’ll look into this :slight_smile:
do you need to have the app active all the time or does it still work if you force close it?
also is it possible to use this without having the tracking of owntracks active?

healthkit now has events like: “in-bed” “asleep” “awake”. if you have a sleep monitor.
This woudl be great triggers for home automation routines. Is anybody at all looking into integration of healthkit?

4 Likes

Following up on this, HealthKit isn’t ever happening at this point. Two primary issues:

  1. We only can read data from HealthKit when the device is unlocked. This would mean that the majority of the time when we are doing background updates, health data wouldn’t be accessible.
  2. Since the app first came out, Apple has published documentation about getting approval for HealthKit access and it is very unlikely the app would get approved. Approvable apps must make health and fitness the primary, not secondary, function of the app. More info is available here..

Sorry everyone, but this is dead for now. As always i’ll keep an eye on developments in the space but I don’t expect Apple to relax their privacy oriented policies anytime soon.

1 Like

Wouldn’t it be possible to use the HealthFit app (https://apps.apple.com/us/app/healthfit/id1202650514)

It can sync Health data to i.e. Google Sheets.

3 Likes

Great news!

This is precisely the app that was supposedly impossible to get Apple validation for.

I don’t own it yet but by looking at the number of export destinations, I’d be shocked if we don’t figure out a way to sync back data to HA. We could even get in touch with Stéphane Lizeray to collaborate on a dedicated HA integration that would probably ensure real-time events as well as data points logs.

Never despair,

—Arnaud

Any news here? @arnaudm did you try the app?

@arnaudm / @martindybal - I own the app (HealthFit) and would be happy to help test.

3 Likes

Did anything come of this? I am exploring FitBit and Withings to see if they will export Apple HealthKit data. I’m specifically trying to pull in workout count # and water intake.

@akeslo sorry I miss your comment. HealtFit looks exactly as app that we need. Is it possible to add HA as target platform?

1 Like

@martindybal - Sorry I meant that I paid for the app and would be happy to help test. I am not the developer.

Edit: I’ve emailed the developer but have not received a response

There is another app similar to HealthFit, called “Health Auto Export - JSON+CSV”. It also gets HealthKit data and can export it, and for $12 (one time) you can get access to exporting JSON or CSV to any API with a custom POST request. I haven’t tried it with Home Assistant (too new to know exactly how I would respond inside of Home Assistant to a POST request coming in from outside) but it seems like this would be doable, right? I’m not sure how often it makes these requests, but in the configuration for POST requests it has an option for “Enable automatic syncing”, so maybe it doesn’t it often, and in the background? I’m not sure.

Documentation for this app’s export features are at API Export Docs — Health Auto Export - Export Apple Health Data - JSON & CSV

@fivestones I actually stumbled on this over the weekend and thought the exact same - this looks more promising.

This is worth exploring. I have not heard anything back from the developer of healthfit

Looks like someone beat us to it: Exporting Apple Health Data to Home Assistant - SixtyMeters - Smart Home

1 Like

Ohh, very nice. Good find! :slight_smile: I’ll be looking into this one some more, for sure.

Hi everyone,

I’m the developer of Health Auto Export, and I’ve tracked down this thread after I got an email from someone asking if I could make a direct integration with Home Assistant.

I’ll first admit I haven’t used Home Assistant myself. I first became aware when a Home Assistant user shared his blog post about creating his own integration via API Export – the one referenced above in fact (SixtyMeters).

In order to possibly create a direct integration, I’m trying to understand how people are using the health data being exported, how to structure the data, and how to create something flexible enough to accommodate different use-cases.

If anyone wants to give some input and be an early tester, please reach out.

As an FYI on the question of how often the automatic export runs, it will not run as long as your phone is locked, since health data is inaccessible while iPhone is locked; however, by default, it will run multiple times per day, essentially most times when you unlock your phone, subject to iOS limiting background execution, or can be configured to run less frequently.

I’ll try not to ramble too much here. Feel free to ask any further questions for clarification.

7 Likes

@Lybron thank you for your willingness to assist.

Taking a similar approach to the blog post, I was able to use node-red to get the integration working via a webhook:
image

Node Red Export:

[{"id":"d92725ad.fa81d8","type":"tab","label":"Health API","disabled":false,"info":""},{"id":"7370ab07.315e84","type":"ha-webhook","z":"d92725ad.fa81d8","name":"health","server":"e056fc93.5eff4","version":1,"outputs":1,"webhookId":"health","outputProperties":[{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"},{"property":"payload","propertyType":"msg","value":"","valueType":"data"}],"x":90,"y":140,"wires":[["e25ad690.522868"]]},{"id":"e25ad690.522868","type":"function","z":"d92725ad.fa81d8","name":"Parse POST","func":"metrics = {}\n\nfor (i=0; i<msg.payload.data.metrics.length; i++)\n{\n  value = 0\n  for (x=0; x<msg.payload.data.metrics[i].data.length; x++)\n  {\n    value = value + msg.payload.data.metrics[i].data[x].qty\n    \n  }\n  metrics[msg.payload.data.metrics[i].name] = parseFloat(value).toFixed(0)\n}\n\nmsg.payload = metrics\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":270,"y":240,"wires":[["46ee9e56.64c05","2af3c20c.33404e"]]},{"id":"46ee9e56.64c05","type":"ha-entity","z":"d92725ad.fa81d8","name":"update Step Count","server":"e056fc93.5eff4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"step_count"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"steps"}],"state":"payload.step_count","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":520,"y":240,"wires":[[]]},{"id":"2af3c20c.33404e","type":"ha-entity","z":"d92725ad.fa81d8","name":"update Water Intake","server":"e056fc93.5eff4","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"water_intake"},{"property":"device_class","value":""},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"Oz"}],"state":"payload.dietary_water","stateType":"msg","attributes":[],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","outputOnStateChange":false,"outputPayload":"$entity().state ? \"on\": \"off\"","outputPayloadType":"jsonata","x":520,"y":300,"wires":[[]]},{"id":"e056fc93.5eff4","type":"server","name":"Home Assistant","version":1,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Results:
image
image

Can I please be an early tester? I’d be happy to help out.

One thing I’d like to do with the data is displaying it on a home assistant dashboard, e.g., Your number of steps so far today, your current weight (along with a graph of recent weights), maybe a comparison to previous days (“you’re farther along today in your step count than you have been on any day since 3 weeks ago”). Doing the manipulation of the data to put things on a dashboard is not hard to do inside of home assistant/node red. Just getting the data there is the main thing that is needed.

Can you explain more of how you went about this? The blog post also is a little light on the details on this. I haven’t used node red until now and I’m stuck at some simple things like what exactly the url should be for making the post request to get the data into node red. And the Node Red export that you posted–where does this go in Node Red? In your update Step Count/Water Intake nodes? Or somewhere else entirely?