Applehealth Autoexport

Hi all, Apple Health is similar to Alexa and Home Assistant in some ways. It is pretty much a database of health related metrics. Some of the data is gathered from iPhones but there are a number of hardware devices and associated apps that measure various attributes and can write to Apple Health.

E.g a blood glucose meter can use NFT to send data to it’s app and gives pairs like
timestamp: 5.7ml/mol
A set of bluetooth scales might record weight , bmi , percentage muscle/ fat/ water
A smart watch may record steps and heart rate ect.

usually some or all of this data can be written and synced to apple health.

This can be quite convenient, e.g Home Assistant supports some bluetooth scales which is good of course but then you get problems with bluetooth range and then you end up with a device dedicated to communicating to that device and then relaying the data via wifi to your main HA install. Does that make any sense? do you really need access to a set of bathroom scales 24/7 The scales don’t even need that , they can store the data till your iphone is in range and the app take in the data and passes it to apple health anyway.

Home assistant devs have essentially said Apple will not allow an app that is not primarily health focused to access Apple Health . So it’s not possible then? No HA can’t directly interact with Apple Health but there is an iPhone App which can periodically export Apple Health data to HA.

This isn’t free although it has a free trial for 7 days and then various subscription offers the best being euro 11.99 for lifetime subscription, which is a pretty good deal, considering how much access you get to different metrics and hardware devices. Since HA doesn’t need to interact directly it’s a gateway to lots of new data sources.

Here is where i am the mqtt export exports data to the mqtt broker in home assistant and listening to the topic brings in a mass of data (which I don’t know how to deal with) there is a catch using mqtt for this transfer of data in that the auto export app needs to be in the foreground on the iphone.

There is a dedicated HA export which uses a long lived access token and exports the data to https://yourhomeassistant:8123/api/states/hae.applehealth

I think this is working although i find some data fails but that maybe because there is no data for that metric in apple health.

So this is where I am stuck I’m probably getting data to HA successfully but no idea how to create a sensor to record say BMI or say Steps into a sensor that can be logged into HA of course once this data is in HA it can then be viewed and used for automations.

So I need help getting this working so far I have only found some one using it with innodb and node red to bring the data into Home assistant but its probably possible to define sensors to consume the data in HA directly.

2 Likes

Hi,

i am also trying to get the data in HA but currently without success. I get an error message saying that there is something wrong with the header token.

Can you maybe share how you filled out the form of the Auto Export App? Especially the section where the key-value pair should be included.

This is something what is not 100% clear for me based on the documentation here: https://www.healthyapps.dev/how-to-configure-automatic-apple-health-exports#homeassistant

P.S. - I’ve tried a different method. Within the Auto Export is also Home Assistant as source possible to select. For this i created a Long-Live-Token.

MQTT
This method does not throw any error like for @blackest but i can’t see a new sensor after i got the message from the Auto Export App that the content was published successfully.

Hi finding the documentation confusing , you are in good company, and It is.

  • Add the token to the configuration headers as the key-value pair “Authorization”:“Bearer <your_auth_token>”.

Ok so lets do the HA authorisation and send some data.

I called my automation for HA applehealth,
so we need a url in homeassistant
e.g
https://myha.duckdns.org:8123/api/states/hae.applehealth

autoexport always adds the hae. bit

So assuming that’s your HA server then you need a header which is a key pair

Authorization : Bearer extremelylonglivedtokenthat you generatedinhomeassistant

This is hard to get on to your phone one method might be to use facebook messenger on your computer and then open the message in facebook messenger on your phone and then copy paste. :slight_smile:

You don’t have to create the endpoint in HA it happens automatically.
do a test send and hopefully it won’t complain, it’s not going to send metrics for things you havent got say a value for magnesium in Applehealth you can manually add values and you may find some useful shortcuts that can write e.g toothbrushing time to applehealth.
Anyway when you have sent some data go to lovelace and look for unused entities they should all start hae something choose to add them to your dashboard (probably on an entities card) and there you have the latest values for each metric in home assistant.

Not long after doing this you will probably find that HA’s history isn’t that good for recording metrics.

So the next game is to use influxdb and grafana . You can get these as addons which is easy or if you run core like me you can install the apps.

Influxdb you need a home_assistant database a user and password for that db with admin rights. thats mostly it you can do is via ssh to your pi.

grafana is a bit of a pig to setup and it needs its ini file configuring you need to get its interface being served over https and get it to use your HA SSL cert, you also want it to allow itself to be embedded in HA and you need to get lovelace to allow you to see it in an iframe in HA which can lose the title bar if you find the right javascript.

Assuming you have node red installed and working with HA you need the influx addon for node red added to your palette. This gives you an input node an output node and a batch node. this needs the serrver url and port 8086 the database name and your user and password for the database.

now you need the webhook node configuring and the best guideline i can give you is this post

now if you change the HA instance to yours set a webhook id e.g mytest and configure your http node to use that hook address you should find that generates an object when you press the test button.

Now you can create a new automation in autoexporrt using a rest automation. use the address you already created in node red and select a metric. manual sync and hopefully your debug node in this flow now receives an object from your iphone. if you start unpacking that object in the debug window you should see timestamps and values for the data that you sent.

Congratulations you now have data going from your iphone to nodered.

After that… well i havent got there yet but

Should be able to get you to the point where you can use your configured webhook to pass the data to the function node and from there write it to the database with the batch node.

Next you will want to setup dashboards with grafana to visualise the data. At some point I will complete this journey and may be able to give detailed instructions, or maybe someone will give me a hand with this :slight_smile:

2 Likes

It’s finally working. Get the data via the Home Assistant export method into HA. After that i’ve installed InfluxDB and Grafana. Created a new database and user. Next added the DB as source to Grafana and created my first visual!

Was really hard as i tried a lot but now was worth the effort!

1 Like

Great iOS application… love it. Now I can track all my stats!!!

im confused on the Key Pair part, no matter what i enter in key and value i dont get it working :confused: can someone point out what exactly has to go were?

Without the quotes:

Key: “Authorization”
Value: “Bearer <your_auth_token>”

I found that suddenly I get a error on my automation for Home Assistant:
Could not publish Active Energy → The network connection was lost.

It worked for days and I not changed anything on router, home assistant, iPhone.
(only updated to iOS16)

I‘ve also updated to iOS 16 but the automations still work.

Removed the app and reinstalled it. now it work again. Only the automation is not update every 5min (I add this in automation) and have to update manual

Did this short update interval of 5 minutes has worked for you before updating to iOS16?

No. Here screenshot. Last update 17:47 and now it’s 22:18.So since then no.update

Well… Hi there. On this Screenshot your last update is clearly on 22:17:47. (hh:mm:ss). So it is accurate

What I wanted to say. That there was a big time gap between them. And I add every 5 minutes update. I read the site and saw the restrictions of apple that it can’t update when your screen is off. I understand now that this will happen what I saw.

If somebody is interested in the way how i have setup Auto Health Export with Home Assistant here is a Youtube Video i’ve cerated (in german).

3 Likes

I connect to my Home Assistant installation https://ha.xxx.xxx.me from outside via my Synology. I entered everything exactly like the video from smartmatic, unfortunately it doesn’t work. Unfortunately I get the message Failed to push. Has anyone included this with the Synology URL?

Is there an English version of this?

So I can get the export to work, I can see the entities in HA, but I can’t do anything with the entities, it says “This entity (‘hae.testing_step_count’) does not have a unique ID, therefore its settings cannot be managed from the UI. See the documentation for more detail.”

I don’t run docker so I can’t use the Influx integration, but I have added it and Graffana as Add-ons. Are there instructions about what to do with the Add-ons, and will it make it such that I can display the entities on a picture elements dashboard card for example? Right now I can see the data if I go into Settings, Devices, Entities and click on the entity, but there is no Entity ID that I can use for YAML on the dashboard to display the values, it just gives me the error I mentioned above when I try to click on the cog to get the entity ID.

Sorry, there is no video recorded in english but if you use Grafana plus InfluxDB you can build your own individual graphs and add it to the HA Dashboard.

Hi, I got this working and I’ve got it in Influx and the information is synching. But I can’t find the data point I want. I know the data point is in Health Auto Export and I have all the metrics selected to sync.

I can find the total Running Plus Walking distance miles fine. I can’t find my workout miles. I enabled include workouts and include workout metadata. I can visually confirm that the workout miles are accurate in the Health Auto Export App. I’m just having trouble finding it in Influx DB. I’ve resorted to trying every section and I can’t find it. Can anybody tell me the path that’s specific to the workout data and subsequently the workout miles?