Creating an iOS Alarm Clock w/ Snooze and Awake Actionable Notifications

Hello Everyone!

I’ve been using the Alarm Clock made by @hokagegano for quite some time now and love it but I wanted something that made use of the Actionable Notifications for the iOS App so I added a few things to it and thought I would share it with the rest of you who have iOS.

alarm_clock_screencap

First download and set up the iOS App.

Then add these lines in the appropriate places depending on how you organize your .yaml files.

configuration.yaml

ios:
  push:
    categories:
      - name: alarm clock
        identifier: 'alarmclock'
        actions:
          - identifier: 'AWAKE'
            title: 'Awake'
            destructive: no
          - identifier: 'SNOOZE'
            title: 'Snooze'
            destructive: yes

input_boolean.yaml

alarm_clock_status:
  initial: on

input_number.yaml

alarm_clock_hour:
  name: Hour
  icon: mdi:timer
  initial: 12
  min: 0
  max: 23
  step: 1
  mode: slider
alarm_clock_minutes:
  name: Minutes
  icon: mdi:timer
  initial: 0
  min: 0
  max: 55
  step: 5
  mode: slider

sensors.yaml

platform: template
sensors:
  alarm_clock_hour:
    value_template: '{{ states.input_number.alarm_clock_hour.state | int }}'
  alarm_clock_minutes:
    value_template: '{{ states.input_number.alarm_clock_minutes.state | int }}'
  alarm_clock_time:
    value_template: >-
      {{ states.sensor.alarm_clock_hour.state }}:
      {%- if states.sensor.alarm_clock_minutes.state|length == 1 -%}
        0
      {%- endif -%}
        {{ states.sensor.alarm_clock_minutes.state }}
  alarm_clock_time_long:
    value_template: >-
      {% if states.sensor.alarm_clock_hour.state|length == 1 -%}
        0
      {%- endif -%}
        {{ states.sensor.alarm_clock_hour.state }}:
      {%- if states.sensor.alarm_clock_minutes.state|length == 1 -%}
        0
      {%- endif -%}
        {{ states.sensor.alarm_clock_minutes.state }}

groups.yaml

alarm_clock:
  name: Alarm Clock
  entities:
    - sensor.alarm_clock_time
    - input_number.alarm_clock_hour
    - input_number.alarm_clock_minutes
    - input_boolean.alarm_clock_status

automation.yaml

###### automation for turning on the alarm ######
id: alarm_clock_activated
alias: Alarm Clock Activated
hide_entity: False
trigger:
  platform: template
  value_template: '{{ states.sensor.time.state == states.sensor.alarm_clock_time_long.state }}'
condition:
  condition: state
  entity_id: input_boolean.alarm_clock_status
  state: 'on'
action:
- service: script.turn_on
  entity_id: script.s_alarm_clock_wake_up
- service: notify.ios_3vasi0ns_iphone
  data:
    title: "Alarm Clock"
    message: "It's Time For You To Wake Up!"
    data:
      push:
        sound: "US-EN-Alexa-Good-Morning.wav"
        badge: 0
        category: 'alarmclock'

###### awake actionable notification pushed ######
id: a_alarm_clock_awake_action
alias: alarm clock awake action
initial_state: true
hide_entity: true
trigger:
  platform: event
  event_type: ios.notification_action_fired
  event_data:
    actionName: AWAKE
action:
  service: script.turn_on
  entity_id: script.s_alarm_clock_awake

###### snooze actionable notification pushed ######
id: a_alarm_clock_snooze_action
alias: alarm clock snooze action
initial_state: true
hide_entity: true
trigger:
  platform: event
  event_type: ios.notification_action_fired
  event_data:
    actionName: SNOOZE
action:
  service: script.turn_on
  entity_id: script.s_alarm_clock_snooze

scripts.yaml

###### script for running what happens after awake button is pushed ######
s_alarm_clock_awake:
  sequence:
  - delay: '00:15:00'
  - service: light.lifx_set_state
    data:
      entity_id: light.left_end_table_lamp
      power: false
      transition: '5'
  - service: light.lifx_set_state
    data:
      entity_id: light.right_end_table_lamp
      power: false
      transition: '5' 

###### script for running what happens when snooze button is pushed and for turning on the snooze timer and turning off lights ###### 
s_alarm_clock_snooze:
  sequence:
  - service: script.turn_off
    data:
      entity_id: script.s_alarm_clock_snooze_timer
  - service: light.lifx_set_state
    data:
      entity_id: light.left_end_table_lamp
      power: false
      transition: '5'
  - service: light.lifx_set_state
    data:
      entity_id: light.right_end_table_lamp
      power: false
      transition: '5'
  - service: script.turn_on
    data:
      entity_id: script.s_alarm_clock_snooze_timer

###### script for the snooze timer ######
s_alarm_clock_snooze_timer:
  sequence:
  - delay:
      minutes: 5
  - service: automation.trigger
    data:
      entity_id: automation.alarm_clock_activated

###### script for running what happens when the alarm clock gets turned on ######
s_alarm_clock_wake_up:
  sequence:
  - service: light.lifx_set_state
    data:
      entity_id: light.left_end_table_lamp
      brightness: 255
      color_name: white
      power: true
      transition: 10
  - service: light.lifx_set_state
    data:
      entity_id: light.right_end_table_lamp
      brightness: 255
      color_name: white
      power: true
      transition: 10

If you need any help just ask. I’d be more than happy to do the best I can.
If you have any suggestions or tips that would be awesome and I’d love to hear it!

12 Likes

Nice :slight_smile: i will try this out, thx!

1 Like

Not a problem bud! I have some more pretty cool projects that I wanna share in the next few days. I just gotta sit down and write them up.

1 Like

Nice Alarm clock!! Wil test it out later today :+1:

1 Like

Thanks! Let me know how it works out for you.

this is really cool :smiley: good work!

1 Like

I have been thinking about a way to know when I wake up, this is a good choice! Easier to run automation in the morning.

1 Like

@3vasi0n Great idea, thanks for putting all this together! I just got it implemented last night, and it seems to be working smoothly, in my setup (I’ve got a complicated morning routine). I did want to point out that there’s a few typo’s in the template sensor code above. Here’s the corrected code:

platform: template
sensors:
  alarm_clock_hour:
    value_template: '{{ states.input_number.alarm_clock_hour.state | int }}'
  alarm_clock_minutes:
    value_template: '{{ states.input_number.alarm_clock_minutes.state | int }}'
  alarm_clock_time:
    value_template: >-
      {{ states.sensor.alarm_clock_hour.state }}:
      {%- if states.sensor.alarm_clock_minutes.state|length == 1 -%}
        0
      {%- endif -%}
        {{ states.sensor.alarm_clock_minutes.state }}
  alarm_clock_time_long:
    value_template: >-
      {%- if states.sensor.alarm_clock_hour.state|length == 1 -%}
        0
      {%- endif -%}
        {{ states.sensor.alarm_clock_hour.state }}:
      {%- if states.sensor.alarm_clock_minutes.state|length == 1 -%}
        0
      {%- endif -%}
        {{ states.sensor.alarm_clock_minutes.state }}

I’ve also added another input_number to allow me to set the snooze duration. I’ll post that if anyone’s interested.

I’d be interested!

Also, does your actionable notifications work? For some reason I’m not getting any actions, only a notification?

Have you updated push settings in settings? You need to do that every time you make a new actionable.

1 Like

Didn’t realize you had to drag the notification down to get the buttons :slight_smile:

1 Like

sorry for the late response. glad you got it figured out though!

The snooze time sounds like a pretty good idea! I’m not seeing any differences between the code that I posted and what you posted though. Do you mind pointing those out for me?

The snooze duration isn’t posted above, the above just fixed a small typo I found.

I’ll post the snooze code later this evening.

I added a ifttt to call my phone when the alarm goes off.

I mean’t what was the typo you found? I don’t see any differences in the codes

My mistake, there aren’t. When I originally implemented the code, I think there was one too few ‘{’ but it looks good now. Anyways, i’ll dig out the snooze duration code, stand by.

1 Like

So I’ve implemented @3vasi0n code, as illustrated above, but made a few changes along the way…
I’ve added an additional input_number for alarm clock snooze duration, as well as one for fade in duration. So now I can adjust the snooze duration, and the amount of time it takes for the lights to fade-in.

instead of posting only the changes I’ve made, I found it easier to post the configuration, in it’s entirety

Here’s what it looks like (please note, I’m using a theme, so your colors may be different)
alarm-clock

The code:

configuration.yaml:

config:
sun:
map:
ios:
  push:
    categories:
      - name: alarm clock
        identifier: 'alarmclock'
        actions:
          - identifier: 'AWAKE'
            title: 'Awake'
            destructive: no
          - identifier: 'SNOOZE'
            title: 'Snooze'
            destructive: yes

input_boolean.yaml:

alarm_clock_status:
  name: Alarm Clock Status
  initial: on
  icon: mdi:alarm

input_number.yaml:

  alarm_clock_hour:
    name: "Hour"
    icon: mdi:timer
    min: 0
    max: 23
    step: 1
    mode: slider

  alarm_clock_minute:
    name: "Minutes"
    icon: mdi:timer
    min: 0
    max: 55
    step: 5
    mode: slider

  alarm_clock_snooze:
    name: "Snooze"
    icon: mdi:alarm-snooze
    min: 0
    max: 30
    step: 1
    mode: slider

  morning_lights_fadein:
    name: "Fade-in Minutes"
    icon: mdi:lightbulb-on-outline
    min: 5
    max: 30
    step: 1
    mode: slider
    initial: 10

sensors.yaml:

  - platform: template
    sensors:
      alarm_clock_hour:
        friendly_name: "Alarm Clock Hour"
        value_template: '{{ states.input_number.alarm_clock_hour.state | int }}'
      alarm_clock_minute:
        friendly_name: "Alarm Clock Minute"
        value_template: '{{ states.input_number.alarm_clock_minute.state | int }}'
      alarm_clock_snooze:
        friendly_name: "Alarm Clock Snooze"
        value_template: '{{ states.input_number.alarm_clock_snooze.state | int }}'
      alarm_clock_time:
        friendly_name: "Alarm Clock Time"
        value_template: >-
          {{ states.sensor.alarm_clock_hour.state }}:
          {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
            0
          {%- endif -%}
            {{ states.sensor.alarm_clock_minute.state }}
      alarm_clock_time_long:
        friendly_name: "Alarm Clock Time"
        value_template: >-
          {%- if states.sensor.alarm_clock_hour.state|length == 1 -%}
            0
          {%- endif -%}
            {{ states.sensor.alarm_clock_hour.state }}:
          {%- if states.sensor.alarm_clock_minute.state|length == 1 -%}
            0
          {%- endif -%}
            {{ states.sensor.alarm_clock_minute.state }}

groups.yaml:

alarm_clock:
  name: Alarm Clock
  icon: mdi:alarm
  entities:
    - input_boolean.alarm_clock_status
    - sensor.alarm_clock_time
    - input_number.alarm_clock_hour
    - input_number.alarm_clock_minute
    - sensor.alarm_clock_snooze
    - input_number.alarm_clock_snooze
    - sensor.morning_lights_fadein
    - input_number.morning_lights_fadein

automations.yaml:

# Alarm Clock
- id: alarm_clock_activated
  alias: Alarm Clock Activated
  hide_entity: False
  trigger:
  - platform: template
    value_template: '{{ states.sensor.time.state == states.sensor.alarm_clock_time_long.state }}'
  condition:
    condition: and
    conditions:
    - condition: state
      entity_id: input_boolean.alarm_clock_status
      state: 'on'
    - condition: state
      entity_id: group.presence
      state: 'home'
  action:
  - service: script.turn_on   # iOS Push Notification
    entity_id: script.alarm_clock_awake_pushed

# I entirely removed the "Alarm Clock Awake Pushed" automation, because if I clicked "Awake", it just dismissed the notification, and I didn't need to perform an action based on this (I was awake, the lights were already on).

# Alarm Clock Snooze Pushed
- id: alarm_clock_snooze_action
  alias: alarm clock snooze action
  initial_state: true
  hide_entity: true
  trigger:
  - platform: event
    event_type: ios.notification_action_fired
    event_data:
      actionName: SNOOZE
  action:
    service: script.turn_on
    entity_id: script.alarm_clock_snooze_button

scripts.yaml:
(Please keep in mind, I’ve done a lot of customization here, specific to my setup, your data_template will, and should be very different; I always try and account for every possible situation, weekdays, weekends, holidays, etc.)

#Awake
  alarm_clock_awake_pushed:
    alias: 'Alarm Clock Awake'
    sequence:
      - service: script.turn_on
        data_template:
          entity_id: >-
            {%- if states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%}
              script.morning_lights_weekday
            {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'on' and states.calendar.work.state == 'off' -%}
              script.morning_lights_weekend
            {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'on' -%}
              script.morning_lights_weekend
            {%- elif states.binary_sensor.workday_sensor.state == 'off' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%}
              script.morning_lights_weekend
            {%- else -%}
              script.morning_lights_weekend
            {%- endif -%}
      - service: notify.ios_jon_iphone
        data:
          title: "Alarm Clock"
          message: "Time To Wake Up!"
          data:
            push:
              sound: "US-EN-Alexa-Good-Morning.wav"
              badge: 0
              category: alarmclock

# Alarm Clock Snooze Button -> Timer
  alarm_clock_snooze_button:
    alias: 'Alarm Clock Snooze Button'
    sequence:
      - service: light.turn_off
        data:
          entity_id: group.bedroom_lights
      - service: switch.turn_off
        entity_id: switch.n7x1_screen
      - service: switch.turn_off
        entity_id: switch.n7x2_screen
      - service: light.turn_off
        data:
          entity_id: light.hall_light
      - service: light.turn_off
        data:
          entity_id: light.bathroom_light
      - service: light.turn_off
        data:
          entity_id: group.kitchen_lights
      - service: script.turn_off
        data_template:
          entity_id: >-
            {%- if states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%}
              script.morning_lights_weekday
            {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'on' and states.calendar.work.state == 'off' -%}
              script.morning_lights_weekend
            {%- elif states.binary_sensor.workday_sensor.state == 'on' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'on' -%}
              script.morning_lights_weekend
            {%- elif states.binary_sensor.workday_sensor.state == 'off' and states.input_boolean.vacation.state == 'off' and states.input_boolean.company.state == 'off' and states.calendar.holidays_in_united_states.state == 'off' and states.calendar.work.state == 'off' -%}
              script.morning_lights_weekend
            {%- else -%}
              script.morning_lights_weekend
            {%- endif -%}
      - service: script.turn_on
        data:
          entity_id: script.alarm_clock_snooze_timer

# Alarm Clock Snooze Timer
  alarm_clock_snooze_timer:
    alias: 'Alarm Clock Snooze Timer'
    sequence:
      - delay: '{{ (states.sensor.alarm_clock_snooze.state | int * 60 ) }}'
      - service: automation.trigger
        data:
          entity_id: automation.alarm_clock_activated

# Morning Lights Weekday
  morning_lights_weekday:
    alias: 'Morning Lights Weekday'
    sequence:
      - service: light.turn_on
        data:
          entity_id: group.bedroom_lights
          brightness: 1
          color_temp: 358
      - delay:
          seconds: 1
      - service: light.turn_on
        data_template:
          entity_id: group.bedroom_lights
          brightness: 100
          transition: >
            {{ states.input_number.morning_lights_fadein.state | int * 60  }}
      - service: switch.turn_on
        entity_id: switch.n7x1_screen
      - service: switch.turn_on
        entity_id: switch.n7x2_screen
      ...

# Morning Lights Weekend
  morning_lights_weekend:
    alias: 'Morning Lights Weekend'
    sequence:
      - service: light.turn_on
        data:
          entity_id: group.bedroom_lights
          brightness: 1
          color_temp: 358
      - delay:
          seconds: 1
      - service: light.turn_on
        data_template:
          entity_id: group.bedroom_lights
          brightness: 100
          transition: >
            {{ states.input_number.morning_lights_fadein.state | int * 60 }}
      - service: switch.turn_on
        entity_id: switch.n7x1_screen
      - service: switch.turn_on
        entity_id: switch.n7x2_screen
      ...

Logic:
(fairly complicated, but works wonderfully)
If the alarm clock is ON, when the current time matches that of the alarm clock time, the following happens:

  1. Push notification to phone, with Alexa voice saying “Good Morning”
  2. Lights begin to fade in (for fade-in duration)
    a. Depending on the day
    b. Fire the following script (one or the other, not both):
    1. morning_lights_weekend
    2. morning_lights_weekday
  • Awake button - Simply dismisses the notification
  • Snooze button - Perform the following:
  1. Snoozes for the alarm_clock_snooze duration
    a. Turns off any and all lights, or screens that were turned on previously
    b. Sleep for additional alarm_clock_snooze duration!
  2. Cycle starts over…

Please let me know if anything doesn’t make sense, I accidentally left something out, or you’d like some more details, or clarification. Credit for the alarm clock should go to @3vasi0n, all I did was tweak it a little for my setup.

If anyone’s interested in how I’m controlling the tablet screens, please check out my other post

2 Likes

Looks nice man! I just got done reading your write up about the Fully Kiosk and the timing couldn’t have been better on that! I was literally getting ready to start working with that app when I noticed you replied to my question about the typo. Appreciate you saving me a lot of time with research on Fully Kiosk and I like what you did with the additions to the alarm clock. Since the time that I wrote this I have made a lot of changes to my own personal one and was planning on updating the article. I’ll make sure to give you credit on the snooze and light duration in the update!

1 Like

Thanks man, glad you liked the Fully post. It’s a really powerful application, with a ton of great features! I love that you can control so much of the tablet, with a single application; really makes Fully an extension of HA, not just another piece.

Thanks again for writing up the original alarm clock; without that we probably wouldn’t be having this conversation. I’m anxious to see what improvements you’ve done, on your own.

I’ve been thinking about implementing some kind of media player, into the alarm clock, to play some kind of peaceful alarm, with a fade-in duration to match the lights. First step for me is, figuring out the hardware, the rest is fairly easy. If I make some traction on that, I’ll be sure and let you know!

Anyways, keep up the great work! I really enjoy seeing things like the alarm clock, building something awesome out of what we already use within HA (without having to add unnecessary hardware).

1 Like