iOS 17.1 push iPhone alarm clock to HA

Hey there, thank you for posting this! I got the shortcut imported just fine and changed the server to my HA server. One issue I am having though is with my config.yaml file. I don’t know much about .yaml yet, so that’s likely the issue and I’m hoping this is a simple fix. Anyways, here’s my config.yaml file (I added your code to the end of my config file):


# Loads default set of integrations. Do not remove.
default_config:

# Load frontend themes from the themes folder
frontend:
  themes: !include_dir_merge_named themes

# Text-to-speech
tts:
  - platform: google_translate

automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml

# Google Assistant Stuff
google_assistant:
    project_id: home-assistant-79758
    service_account: !include SERVICE_ACCOUNT.json
    report_state: true

# ESPresense
sensor: !include mysensors.yaml

# Access temp folder for camera images
homeassistant:
    allowlist_external_dirs:
        - "/config/tmp"

# Wake on LAN for TVs
switch:
  - platform: wake_on_lan
    mac: 1c:30:08:37:c3:39
    name: "Living TV switch"
    turn_off:
      service: media_player.turn_off
      target:
        entity_id: media_player.living_room_tv
            
# Notification Group
notify:
  - platform: group
    name: chris_allie_phone
    services:
      - service: mobile_app_chris_iphone
      - service: mobile_app_iphone_19
      
# Spotify Spotcast HACS
spotcast:
  sp_dc: !secret sp_dc
  sp_key: !secret sp_key
  country: SE #optional, added in 3.6.24

# Get alarms from iPhone
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) }}"

However, the error I see is:

duplicated mapping key (56:1)

 53 |   country: SE #optional, added  ...
 54 |   
 55 | # Get alarms from iPhone
 56 | sensor:
------^
 57 |   - platform: time_date

I thought this was because I have a line of code in my config file that stores my sensors for ESPresence (sensor: !include mysensors.yaml) and tried to move the code over there, but also ran into some issues. Any idea what might be the causing this error?

Thanks!

I love this! The explanations can be pieced together from the various posts. I’ll try to add:

Elements of this project

Shortcuts app on Iphone

Reads next and last alarm set on the iphone and pushes it into homeassistant. We want this to be triggered every time the Clock app on the phone is closed.

  1. Add the shortcut to your iphone Shortcuts app as per link. You only need to change your homeassistant instance
  2. Go to Shortcuts app → Automation → App
    When Clock app is closed run the shortcut we just added via the link.

In homeassistant

In configuration.yaml add the sensors and template as per initial post

Helpers

Variables for us to use are added here. They turn the iphone data into usable entities (?). Like @mrcgrndt94 explained:
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 you

Automation

Now you can add an automation. In my case I want the coffee machine to go on 15min before my first alarm:

alias: Turn On Coffee Machine 15 Minutes Before Next Alarm
description: ""
trigger:
  - platform: template
    value_template: >-
      {{ now() >= today_at(states('input_datetime.first_alarm_example')) -
      timedelta(minutes =15)  }}
condition:
  - condition: state
    entity_id: input_boolean.alarm_example
    state: "on"
action:
  - service: switch.turn_on
    target:
      entity_id:
        - switch.coffee
    data: {}
mode: single


I made sure timezones are correct on my homeassistant and app on the iphone and still had to convert my automation to this timestamp format. Before it was triggered an hour early. Maybe this is helpful

edit: I had date time as helper format and that only updates the time. So only have time on the helper and then I changed the automation…

2 Likes

Hi, seems to be related to your date and time settings on your iPhone.
When I disable the “24-hour Time” the shortcut works smoothly.
But as I like the 24 hour clock I will look into how to solve this issue.

For people running into this error
“Set Dictionary Value failed because Shortcuts couldn’t convert Alarm to Date”
You can use this fix;

Shortcut

Had to manually add hours and minutes to the format date section.

For people running into this error
“Set Dictionary Value failed because Shortcuts couldn’t convert Alarm to Date”
You can use this fix;

Shortcut

Had to manually add hours and minutes to the format date section.

Is there a way to calculate the time remaining until the next alarm?

I can´t figure out how to calculate “times” with these templates

What do you mean by calculating times?
Current time till first alarm?
Or time between alarms?

I was also looking for shortcuts action to get “sleep schedule” instead of just regular alarms. But “Find All Alarm” action doesn’t see the “sleep schedule”.
I found a workaround using “Edit Sleep Alarm” action. You can “Unskip” it or “Toggle” it twice and it will return the currently set “sleep schedule”

So my shortcut and automation goes through but my HA does not get updated. I used the shortcut belikerich provided and made sure to change the HA server to my own. Not sure what to check?

You have two sensor values in your configuration.yaml file, as you highlighted. If you want to use sensor: !include mysensors.yaml then you need to add:

  - platform: time_date
    display_options:
      - "time"

to your mysensors.yaml file, removing “sensor:” but keeping the indentation.

Hello everyone. I am new to this but I have a quick question.
Is it possible to set this automation not for amount of alarms like first and last, but for a specific alarm with description like “Morning alarm”? I am worried if I went to integrate this I would just setup some alarm during the day triggering unwanted automation.

In the iphone shortcut you can add a filter just belove the find Alarm command.
I didn’t try it, but it seems to achieve what you want

Just fyi, if I use this shortcut I get the last alarm set as the first one :smiley:

Love this.

I got it configured so that I see the correct alarm values in HA.

I want to use this to create an automation to open my window shades when my last alarm goes off. I frequently will reset my last alarm for another hour of sleep so would adding a 5 minute delay before opening the shades allow the last alarm to update and then the shades wouldn’t open until the newest last alarm I set?

Is there a way to get the date and time of the alarm? What it I create an alarm for 8:00 am on Mondays only. I would need the date/time for my automations.

is it possible to call up the shortcut automatically when i change an alarm on the iphone?

1 Like

With ios 18 looks like the shortcut doesnt work anymore. Anyone has checked it?

I am looking for the same. Don’t find any option in the triggers list.

So far my solution is to set triggers based on time in a day (midnight and 3AM for now) which calls and executes the shortcut and updates HA.

Can you elaborate a bit on this? Not sure what you mean.

I think I get what you mean. You trigger toggle twice, and it returns the date. Smart.

Can you share your shortcut solution with me?