I want a shortcut that automatically exports Apple Health’s Sleep Data to a Google Sheet.
I’ve done this for other Apple Health data, but Sleep is much more complicated because it logs data every few minutes and the kind of data is logs varies (i.e., it changes from Awake to Deep to REM to Core versions of sleep while you sleep).
The other issue is sleep start time and sleep end time vary (i.e. I could go to sleep at 9pm yesterday or 1:00am today and wake at different times). The Find Health Samples action step also only allows a Start Date to be in day units, so I can’t just have it start 24 hours ago (i.e., set the automation to go off every day at 5pm where it will pull samples from 5pm yesterday to 5pm today, thus making sure it captures last nigh’s sleep data).
I know about Health Auto Export app, but I don’t find it works for this.
I know how to create an Apps Script in my Google Sheet to receive JSON POST data from my Shortcut. The issue is aggregating all the data correctly so I can simply get:
Column A is Date (i.e. date I went to sleep)
Column B is Sleep Start Time
Column C is Sleep End Time
Column D is Total Sleep Duration
Column E is Awake Total Duration
Column F is REM Sleep Total Duration
Column G is Core Sleep Total Duration
Column H is Deep Sleep Total Duration
There’s a Reddit post on this with a link to a shortcut but it’s very complex and finicky:
No but Actions, GizmoBot, and other shortcut Swiss-army knives have Gemerate CSV, just make a dictionary with the keys are set to headers using Actions, for example
I’ve built some shortcuts for compiling the sleep data which could help and I know of methods for logging to Google Sheets as well but never have had a reason to merge the two together
Oh, that’s great! Could you share those shortcuts with me? I might be able to modify them to get them logging into Google Sheets on my own, but I’ll hit you up if I bump into a wall.
Thank you! This setup is the best I’ve used so far.
I know how to use the “Get URL” action to post JSON to my Google Sheet, but I’m struggling to set variables to the values you’ve extracted, like sleep start time, end time, total duration, awake duration, REM, core, and deep duration.
I tried using “Match Text” to isolate each value, but it’s clunky and probably not ideal. I’m not sure exactly where each value sits in your shortcut to set them as variables.
I’ll keep experimenting, but any guidance would be massively appreciated. This setup has been a dream of mine for years!