iOS 17.1 push iPhone alarm clock to HA

Hi!

Here is a guide to get your iPhone alarm clocks into Home Assistant. I followed some examples I found here and on Reddit and created my own iOS shortcut. This is my first shortcut so I hope I did everything right, but wanted to share anyway, because I haven’t found a working alternative for this. Any feedback is welcome :).

The shortcut will loop through all your alarms and will create a list of the alarms that are enabled. It will only grab the first and last alarm set. If no alarm is set it will turn the input boolean off.

For the first alarm, last alarm and the boolean I set up a helper in Home Assistant. Additionally I added this to my configuration.yaml:

sensor:
  - platform: time_date
    display_options:
      - "time"

template:
  - sensor:
      - name: "Alarm set"
        state: "{{ states('input_boolean.alarm_example') }}"
  - sensor:
      - name: "First alarm"
        state: "{{ state_attr('input_datetime.first_alarm_example', 'timestamp') | timestamp_custom('%H:%M', None) }}"
  - sensor:
      - name: "Last alarm"
        state: "{{ state_attr('input_datetime.last_alarm_example', 'timestamp') | timestamp_custom('%H:%M', None) }}"

This will result in their values looking like this:

The shortcut can be found here

To finalize: add this shortcut to a new automation on your iPhone so it runs every time you close the ‘clock app’ on your iPhone. It may be necessary to run the shortcut in the shortcuts app for the first time to allow all the prompts (make sure you have at least two active enabled alarms, so all the prompts show up).

I hope this helps someone :slight_smile:

8 Likes

Thanks
Curious though what helpers you created and how you named them, do they really have the name alarm_example?
Or doesn’t it Matter what name you use?

Figured out some things already .
the addition example is there in the workflow.
i edited the names for my own use.
important that if you use the workflow, rename the server to the name of your own HA instance.

another thing i noticed is that there was a difference in time set on my phone and the one in HA.
I managed to work around that one by adjusting the template and add local=True:

sensor:
      - name: "Last alarm"
        state: "{{ state_attr('input_datetime.last_alarm', 'timestamp') | timestamp_custom('%H:%M',local=True, None) }}"

last thing to mention is that you have to create the automation on your phone to call the script or flow when you close the clock app.
see the last automation in the attached screenshots.

Last thing to mention : when you are using Health and the sleeping schedule to wake you id does not see it als an alarm although it is in the clock app.

For the first alarm, last alarm and the boolean I set up a helper in Home Assistant.

How do you do that?

Hello, nice thing. I have transferred everything 1:1, unfortunately only the last alarm and the boolean switch are transferred correctly. The first alarm remains at 0:00

What could be the reason for this? Unfortunately I’m not so familiar with the shortcuts and it’s not so great on the small phone displays either

@Plouf34
In the Settings section select automations & scenes. There you also find Helpers where you can create the helpers.
Most easy to name them:

alarm_example
first_alarm_example
last_alarm_example

that way you don’t have to adjust the IOS script/shortcut

@niemehrarbeiten
it could be that the first alarm is one of health (ie sleepcycle) that seems to be another kind of alarm. I haven’t figured out how to use that yet.

Sorry
I don’t understand where to find/create “There you also find Helpers where you can create the helpers.”

@Plouf34
I hope this wil help. it explains what helpers are en hoe to create them.

https://youtu.be/V-EjjWejyv4?feature=shared

Thanks, but it doesn’t help me.

In my case I wanted my home to do some wild stuff to improve alarm effectiveness. I added an input_button to HA and created an automation in shortcuts with the following configuration:
When: When the alarm is activated
Action:
Dictionary: entity_id: input_button.alarm_clock
Home Assistant Call input_button.press with data dictionary.
I then trigger my HA automations when the input_button is pressed, and only stop the house madness when I manually turn on a light in the kitchen

Hey,

maybe this helps to better understand how it works:

the iOS shortcut will put your alarm values via the Home Assistant app on your phone to 3 specific helpers. The template in the configuration.yaml is reading these helper values and converts it into sensor entities.
Now, how to configure the helper? This is being done in Settings - Devices and Services - and then at the top select Helpers. With the “+ create helpers” button on the lower right helpers can be added. You need to configure 3 helpers.

  • 1x type Toggle, this is for the detection if an alarm has been set or not. The iOS shortcut will change the toggle state for you. To keep it simple, name the toggle “alarm_example” since this will exactly match the config in the iOS shortcut.

  • 2x type Date and/or time. Here your iOS shortcut will publish the time value of your alarms to. Like above, convenient naming for these two would be first_alarm_example and last_alarm_example.
    Now you can run your iOS shortcut. By clicking on your created helper you should be able to see the values coming in. Works like a charm for me! Thanks @Milofow for this :slight_smile:

2 Likes


I am stuck at this place with this error message: “Set Dictionary Value failed because Shortcuts couldn’t convert Alarm to Date”
It seems that the issue is related to the fact that an Alarm object can’t go into the dictionary…
Anyone who has an idea for a solution?

Note: The Alarm set boolean works just fine and gets set in Home Assistant.

how does your dictionary look like?
missing information to see what and or where it stalls

I have the exact same error at the same spot. All my settings are by your default names and the Dictonary just says entity_id and then the 2 items are:
input_datetime.first_alarm_example and input_boolean.alarm_example

Hope that helps a little bit more.

Works like a charm, THX. Could you pls add to shorcut the days, when is alarm on? Now I dont know, if is the alarm is for today.

Hello, I had the problem that the alarm data was not transferred correctly.
I have found the error but I am having problems implementing the solution.
My better half has several alarm clocks that are always activated. Due to different working hours, she has alarms that only ring on Tuesday or Friday or Saturday, for example. These are not transmitted to HA. She has now been ill and therefore had all of them off. She once set a “normal” alarm clock and the data was transferred correctly.
In my opinion, this means that the shortcut should include a query for the current day of the week and then transmit the alarm time for this day. The alarm time is transmitted daily at 2.00 am.
Could someone please help me solve this problem?

Changing the server in the homeassistant calls (in the shortcut) and setting up the helpers (as described by @mrcgrndt94) was all it took.

Now I am able to turn on the lights on the first alarm :wink: Thanks a lot for sharing.

Hello,
the shortcut works great! Thank you very much!!
I just have the problem that when I set my alarm for 10 AM or 11 AM, the time in HA is set to 22 or 23 hours.
It seems to be related to the formatting of the date or time, but unfortunately, I can’t find the solution.
My location is Germany, maybe there is a different setting for Germany?

Hello,

I have exactly the same issue (from NL). Very strange. If anyone has any idea, that would be much appreciated! :pray: