Sync next iOS16+ alarm clock in HA (with Shortcuts and companion app)

As a complete noob, I just published this, instead of saving it as a concept… Lets keep it as ‘a work in progress’ for now…

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):

  1. Basic alarm
    Alarm: see Name
    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.

  2. Sleep-schedule alarm (also available from the health app)
    Alarm: see Name
    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. :frowning_face:
    – 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 :upside_down_face: ), 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 to Settings > 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!

  1. Create a new shortcut within the Shortcut app, give it a name/icon/colour.

  2. Within the new shortcut, search for Dictionary and add to the shortcut.
    → Tap Add new item and choose text.
    → Under key enter entity_id
    → Under value enter input_datetime.exampleuse the actual name you gave the input_datetime-helper, created earlier

  3. Search for Adjust date and add to the shortcut.
    → Select the input fields until you get add 1 day to current date

  4. Search for Set variable and add to the shortcut.
    → Under Variable name input tomorrow (or any name you want) and choose adjusted date (under input if not already set).

  5. Search for Get all alarms and add to shortcut.
    → Uncheck Show when run in this action.

  6. 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.

  7. 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.

  8. 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 selecting is under condition, and write Never in the next field. — This needs to be adjusted to your own language. In Dutch it would be Nooit instead for instance.
    *By filtering on Never, we’re checking if we’re dealing with a non-repeating alarm. *

  9. to be continued…

5 Likes

Thanks so much for this post! I have been willing to do that for a while to avoid setting two alarm clocks every day (one on the iPhone, one on HA) but never got to it.
Your post will definitely win me a lot of time. Will try to take advantage of the holidays to give it a try and will let you know how it went

Over time, I’ve seen many people claim to solve this problem but, so far, I haven’t found any that properly deal with all the necessary scenarios. Before I get my hopes up again, can you confirm that all the following scenarios are handled with your shortcut?

  • One-time alarm
  • Repeating alarm
  • Bedtime / sleep schedule alarm
  • Bedtime / sleep schedule override
  • Combinations of each of the above

Yes and no?

No: it depends on how you use your alarms and how you’d like to use them in HA itself. I only ever really use the Bedtime / sleep schedule and created the shortcuts-automation around this. So it happens to take ‘normal’ repeating alarms into account, but not one-time alarms. But again, I don’t use those, so I haven’t thoroughly tested the shortscuts-automation dealing with them.
Furthermore, the way Apple has implemented alarms in iOS and the way the shortcuts-app can access this data, has it’s limitations. Like I mentioned above, it can’t detect you’ve ‘skipped’ a planned alarm and will always send it to HA.

Yes?: you could use names for your ‘normal’ alarms and tweak the shortcuts-automation to filter accordingly to handle these too. It ought to work that way, but I can’t imagine all your ‘necessary scenarios’, so can’t tell you wether this would help or not.

I certainly understand the complexity and limitations at play, as I’ve tried a few times to build a shortcut myself before parking the effort until such time that I had more opportunity to focus on it. At the same time, as I said, I’ve seen a number of people try to solve the problem and not get all the way there. That was the only reason I asked - to see which scenarios you’ve accounted for, which you haven’t, and how easily your solution can be extended for additional scenarios.

Thanks for your response. I’ll be sure to download it and give it a try. Cheers!

I’ve just updated the link to the real ‘last version’. Hope you find it useful and can make it work for your use-case!

I just stick to the bedtime/sleep schedule alarms, I have no use for the normal alarms. Makes it a lot easier :angel:
I need to wake up on time, even on off days, because of my medications. So I wake up anywhere between 6 and 8. For the rare occasion I don’t set my alarm (skipping a planned alarm), I created an override in HA to not trigger the wakeup-light. There is no way to do this within Shortcuts that I’m aware of. So the bedtime/sleep schedule fits my needs perfectly.

I’ve got troubles understanding what happens after the first if-clause, ie what does “Set datetime to Time on Dictionary”. Specifically, what does “datetime” do or mean?

Hey, thank u so so much for this. I think u may be the only one who figured out how to make this.

I have just one issue: I meed the helper to act as a sensor for Wake-up light alarm with sunrise effect

Is that possible?

Thx!

The shortcuts-automation sends the data to HA, but HA only accepts this data in the form of a dictionary.
So the dictionary needs a key (‘datetime’) with a value (‘2023-01-22 12:00’) and an entity where this information needs to be stored (‘input_datetime.example’).

It’s the same as setting a value with yaml in the developer tools:

It seems the blueprint only accepts sensors with a date-time (ISO8601) format. There is no service for the Shortcuts-automation to set the value of a sensor.

But, you could tweak the automation and use the ISO8601 date-time formatting (instead of my custom one) to be send to a input_datetime helper and create a custom sensor within HA that sets a sensor with the same timestamp to be used in the blueprint.

Tank u so much for the fast answer. Since my knowledge of homeassistant is quite little, would u mind explaining more detailed, what i have to do? That would be great! Thx <3