While using the Sync iOS 17 Sleep alarm to HA by the amazing M20Lucas. I noticed it wasn’t working properly with few scenario. Since I worked on a total rewrite of that feature and it should now handle on top of his work:
- Different Timezone
- Update with alarm in the same day (past midnight sync)
- Detect the next alarm (with limitation)
- Allow better multi schedule management (with limitation)
Also, his method and this method are technically totally different. Here the main lift and conversion is done through a script in HA instead of a Shortcut in iOS.
I create a new thread to make sure that bug report between the two method are not mixed in one thread.
Pre-setup
For this to work you need the following:
- iPhone running iOS 17, with the following apps installed:
– Clock
– Health
– Shortcuts
– Home Assistant - Setup a sleep alarm cycle
– either through the Clock or Health app – Apple instructions
– ‘regular’ alarms won’t work with this Shortcut (though Apple did make it easier to sort and select these alarms within Shortcuts, but you’ll have to write your own Shortcut) - Create two ‘datetime’ helper within HA )
- One will be for the next alarm
- One will be for the next alarm skipped
– Make sure it is a date and time sensor, not just time or date.
– Not sure how? Read this.
Setup
On to the real stuff…
- Install this blueprint in HA: IOS sleep data receiver · GitHub
- Make a script from this blueprint using the two datetime mentioned earlier
- On your iPhone, download a copy of the Shortcut here .
- Set the HA server and update the entity id of the script to match the one created
Post-Setup
Apple’s way of automating things with Shortcuts differs from how it works in HA. A shortcut like the one you just downloaded, is basically just the ‘action’ part of an automation (or a script) within HA. If you tap on the Shortcut on your iPhone, it runs, but there aren’t any triggers that run the Shortcut automatically.
I personally use two ’triggers’ to run this Shortcut. Either when I close the Health or Clock app (I probably changed the alarm), or ‘When Wind Down starts’. The ‘Wind down option’ is part of the sleep alarm schedule and I’ve set it to 1 hour before my actual bedtime. But there are more options available as triggers.
- Within the Shortcuts-app, go to the Automations tab (at the bottom).
- Create a new Automation, by pressing the + in the top right.
- Two options:
a. ChooseSleep
→Wind Down Begins
+Run Immediatly
→Next
b. ChooseApp
→ Select Clock in the list + uncheckIs Opened
+ selectIs Closed
+Run Immediatly
→Next
- Look for the Shortcut you just downloaded in
My Shortcuts
and select it.
Notes
M20Lucas if you read that message, thanks a lot! If you want me to change this description or post, let me know