[Feature request] Add 'next_alarm' as entity in Home Assistant

Hi,

Is it at all possible to add the ‘next alarm datetime’ as an entity in Home Assistant, similar to the Android companion app? This would be really convenient to start morning routines before the alarm goes off.

Thanks

Marvin

1 Like

As far as I know, this information is not possible to retrieve on iOS.

If it’s not super important to do things before your alarm goes off, you can do this with the Shortcuts app that is included with iOS by default.

  1. Inside the Shortcuts app is a tab called “Automation”, tap that and then the + button
  2. Create a Personal Automation with the “Alarm” trigger. Select which alarm you want to trigger from (wake-up alarm, or a custom alarm) and how you want to trigger. It can be one of two things, alarm snoozed or stopped.
  3. After hitting next then you select your action. Press “Add Action”, type “Home Assistant” into the search bar, and then pick the “Call Service” action.
  4. Tap the Service text and it will show all available services to pick from. Select automation.trigger and then for the service data put in {"entity_id":"automation.morning_routine"} – or whatever yours is called. Make sure that “Show When Run” is toggled off.
  5. On the next screen make sure that Ask Before Running is toggled off. And hit Done/Save.

Now when your morning alarm goes off and you hit the snooze or stop button on your phone, it will trigger your Home Assistant morning routine.

6 Likes

Thanks for your extensive reply. This is exactly what I am currently doing. However, I would like to perform some actions before the alarm goes off, for example:

  • Triggering my wake up light
  • Heat the bathroom so it’s nice and warm when I get up

Is there any way to achieve this with iOS, without manually syncing alarms to Home Assistant?

1 Like

After switching from android to iOS, that’s the feature I miss the most!
With my current solution I have to delete the earlier (and therefore inactive) alarms, as shortcuts doesn’t differ between active and inactive alarms.

My shortcut looks as follows:

  1. clock > show all alarms
  2. scripts > first object of alarms (this can also be changed to ask which alarm you want to sync)
  3. dictionary >
    entity_id - input_datetime.youralarm (or whatever)
    time - object from list
  4. home assistant > call service input_datetime.set_datetime with data of dictionary

Trigger is closing the clock app.

Screenshots, but in German:

5 Likes

You’re a legend. I am gonna give this a try, thanks!

Thanks @M1ke for the direction! Personally I had to make some adjustments to get it to work; so posting here for the ones having comparable troubles:

  1. clock > show all alarms
  2. scripts > first object of alarms (this can also be changed to ask which alarm you want to sync)
  3. Format date > Format ‘Element from list’.
    3.1 Then click on this variable (within the format time block), and from the selection Menu, change ‘Alarm’ to ‘Time’. If you do not do this, it will use the name of the Alarm as a variable instead of the Time.
    3.2 Select Date notation: none.
    3.3 Select Time notation: short
  4. dictionary >
    entity_id - input_datetime.youralarm (or whatever)
    time - Formatted date
  5. home assistant > call service input_datetime.set_datetime with data of dictionary
  6. AUtomatically run the script to stay up to date. I run it when I open the Clock app, when I close the clock app, when I connect my phone to the charger, and every night at 21:00

Note that when you make an error somewhere and get a wrongly formatted time, the home assistant service call does not succeed. Apprantly it checks whether the field ‘time’ is correctly formatted. To test it out, I called the service with a manual time and added my variable under an extra dictionary entry (‘test’). That case, I could test and call the service until I had the right configuration.

Attached my setup in Dutch:

Hi,

I’m getting errors with the format type and i’m not sure why.
I can see the results before it’s being sent to HA, and it says:
“20:30:00” (medium method)
I’ve also tried the short method i.e. “20:30”.

Both shows up correctly on the shortucts, however when i try to send it to HA i get “wrong api - due to format issues”.

My input variable on home assistant is time format.

So i’m scratching my head and can’t figure out what’s the problem.

Can you maybe show your script in english?

The input_datetime needs to be hours, minutes, seconds eg. 06:00:00. Let me know if you’re still having the api issue and I’ll elaborate on the ios shortcut setup.

has_date: false
has_time: true
editable: true

The issue I’m running into is that when automation runs, the call service requires an approval. Did you have a workaround for that?

I switched from android to iOS, but I wanted to have the “next_alarm” for my light timer back. I used @WiiiLDFARMER example. But I added a choice function to use one of the created alarms and an option to disable all alarms.

It is in German too. Einschalten = Enable, Ausschalten = Disable.

In shortcuts:


Link to the Shortcut

In Automation (disable the alarm in HA):

In Home Assistant:

input_datetime:
  next_alarm:
    name: Nächster Alarm
    has_date: false
    has_time: true
  - platform: template
    sensors:
        alarm_time:
          friendly_name: "Weckzeit"
          value_template: "{{'Aus' if ( states('input_datetime.next_alarm') == '00:00:00' or states('person.admin') != 'home' ) else (state_attr('input_datetime.next_alarm','timestamp')-(60*60))| timestamp_custom('%H:%M Uhr')}}"
          icon_template: "{{'mdi:alarm-off' if ( states('input_datetime.next_alarm') == '00:00:00' or states('person.admin') != 'home' ) else 'mdi:alarm'}}"

grafik

Greeting!