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.

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: