On iOS17? Read this instead…
As iOS16 is ‘old news’, I won’t be updating (or better, finishing) this post. I’ve added notes in the iOS17 shortcut that hopefully answers previous asked questions.
For all of those with an iPhone, looking to sync their alarm clock with HA, I’d like to share my solution. It started with the desire to create a ‘wakeup-light’ with HA (30 min before my actual alarm), but ended up being useful beyond that initial idea.
I’ve never shared anything like this before, but have found bits and pieces of information on here that helped me along and I wanted to help others. I’m not a programmer, and it took me for-ev-er. Especially working with the Shortcuts-app, nearly drove me mad. With the help of ‘show result’ during each step, I figured out how everything worked and how it fits together. I’ve created multiple ‘shortcuts’ to make it work, but this is my final solution. For now… So here goes…
This is mainly about the Shortcuts-app (and creating an alarm-syncing-shortcut) and less about any of the automations in HA I created to go with it.
Before I start explaining the automation, a bit of information:
the iOS alarms and their properties (available to use in the Shortcuts-app):
-
Basic alarm
→Alarm
: seeName
→Time
: date always set to 01-01-2001 and same time as in alarm.
→Repeat
: either Never (non-repeating) or the names of the days the alarm is set to.
→Name
: uses either the time as the name or if set in the alarm, its label. -
Sleep-schedule alarm (also available from the health app)
→Alarm
: seeName
→Time
: date and time of the set alarm(s).
→Repeat
: either Never (non-repeating) or the names of the days the alarm is set to.
→Name
: these alarms are always called Bedtime.
What will it do?
-
In the shortcuts-app:
– Trigger the shortcut-automation at a set (but flexible) time. — I use the ‘bedtime’ option & when clock-app is closed & when someone arrives/leave home -
shortcut-automation:
– Checks all the alarms, pick the upcoming one. — Unfortunately, upcoming alarms that are set to be skipped on your iPhone, will still get picked. This is a limitation within Shortcuts.
– Makes sure the date and time are formatted correctly (depending on kind of alarm).
– Sends it to HA through companion-app.
– From here on on, it’s up to you and your creativity…
What happens next?
After it sends my upcoming alarm (time & date) to HA, I’ve set up an automation that calculates other different times to be used by a whole bunch of other automations. There is Night-time, Sleep-time (1&2), Wakeup-light-time (for me, my boyfriend and the ceiling-light ), Alarm-time and and all depending on who is home or not, if the alarm is set before 6:00 or after and how much the difference is between our initial alarms. But I digress…
What is needed?
-
On your iPhone:
– Shortcuts app
– Home Assistant companion app
– One or more alarms set with ‘sleep schedules’. — It works with a one time modified scheduled alarm as well, but NOT with non-repeating alarms. They lack a date and can’t be used. A possible workaround could be to use names when setting those kind of alarms and filter those within the shortcuts-automation. -
Within HA:
– An input_datetime helper: create one within HA by going toSettings > Devices & Services > Helpers > Create Helper > Date and/or time
. Give it an easy to remember name and choose ‘date and time’ and press create.
If your interested/impatience; this is the latest version of the shortcut (2.3) I’m using. It’s best opened on an iPhone and don’t forget to change the name of your helper in step 2.
Let’s create a shortcut!
-
Create a new shortcut within the Shortcut app, give it a name/icon/colour.
-
Within the new shortcut, search for Dictionary and add to the shortcut.
→ Tap Add new item and choose text.
→ Under key enterentity_id
→ Under value enterinput_datetime.example
— use the actual name you gave the input_datetime-helper, created earlier
-
Search for Adjust date and add to the shortcut.
→ Select the input fields until you getadd 1 day to current date
-
Search for Set variable and add to the shortcut.
→ Under Variable name inputtomorrow
(or any name you want) and chooseadjusted date
(under input if not already set). -
Search for Get all alarms and add to shortcut.
→ Uncheck Show when run in this action.
-
Search for Repeat with each and add to shortcut.
→ The shortcuts-app will add Alarms automatically. If not, (magic) choose Alarms and check the properties of Alarm by tapping it. Make sure it’s Type is Alarm.
-
Search for Repeat with each (yes, again).
→ It needs to be added within the first repeat. Drag and drop the second repeat inside the first one, so it’s nested between Repeat with each item in Alarms and End repeat.
→ Tap on Repeat Item (in the second Repeat with each). Make sure the Type is Alarm and Repeat. — This is to check whether an alarm is set once (named Never ) or are repeated (named by the day of the week.
-
Search for If and add to shortcut.
→ Drag and drop If inside the second Repeat with each.
→ Select the variable Repeat Item 2, make sure type is Text and set the option to Name.
→ Finish the If by selectingis
under condition, and writeNever
in the next field. — This needs to be adjusted to your own language. In Dutch it would beNooit
instead for instance.
*By filtering onNever
, we’re checking if we’re dealing with a non-repeating alarm. *
-
to be continued…