How to create the alarm clock in HASS?

If you have an Android then you can use the app Hassalarm which will send your alarm time from the phone to HA.

Not sure if that solves your problem but it’s a different way to get an alarm time in HA.

1 Like

oh but i use iOS not Android, thank for you help, you have any solution? :smiley:

Have you tried searching the community forum for how to create an alarm clock?

https://community.home-assistant.io/search?q=alarm%20clock

There are many existing solutions and perhaps one of them suits your requirements.

Oh, i searched, read a lot of them, but it’s for older Hass (spacing and Dash very unstable). Cant work for me :smiley:

YAML formatting rules haven’t changed.

Post the code you tried and the error messages and we can help you fix it.

2 Likes

oh, i can fix it, add sensor.time to fix it, unbelive that, i think it included in Hass System

Try below code, and add sensor to your config (if spliting files, add this to sensors.yaml)

sensor:
  - platform: time_date
    display_options:
      - 'time'
      - 'date'
      - 'date_time'
      - 'date_time_utc'
      - 'date_time_iso'
      - 'time_date'
      - 'time_utc'
      - 'beat'

I misread your post; I didn’t notice that you had copy-pasted it from another thread. The question at the bottom of the post isn’t your question, it’s someone else’s question. My mistake.

1 Like

If you’re interested, I streamlined the example you provided. This version is more compact than the original.

1. Input_Booleans and Input_Numbers

My version uses the same input_booleans and input_numbers as in the original example:

Click to reveal details
#configuration.yaml
input_boolean:
  wakestatus_1:
    name: Alarm 1
    icon: mdi:alarm
  wakeweekday_sun_1:
    name: Sunday
    icon: mdi:calendar
  wakeweekday_mon_1:
    name: Monday        
    icon: mdi:calendar
  wakeweekday_tue_1:
    name: Tuesday        
    icon: mdi:calendar
  wakeweekday_wed_1:
    name: Wednesday       
    icon: mdi:calendar
  wakeweekday_thu_1:
    name: Thursday       
    icon: mdi:calendar
  wakeweekday_fri_1:
    name: Friday        
    icon: mdi:calendar
  wakeweekday_sat_1:
    name: Saturday        
    icon: mdi:calendar

input_number:
  wakehour_1:
    name: Hour
    min: 00
    max: 23
    step: 1
    icon: mdi:alarm
  wakeminutes_1:
    name: Minutes
    min: 00
    max: 59
    step: 1

2. Sensors

It uses far fewer sensors:

#sensor:
- platform: template
  sensors:
    wake_time_1:
      friendly_name: 'Wake Time 1'
      value_template: "{{'{:02d}:{:02d}'.format(states('input_number.wakehour_1') | int, states('input_number.wakeminutes_1') | int) }}"

- platform: time_date
  display_options:
    - 'time'

3. Automation

Its automation is substantially more compact:

#automation:
- id: 'alarm_clock_123'
  alias: Wake 1
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == states('sensor.wake_time_1') }}"
  condition:
    condition: template
    value_template: >
      {% set today = 'input_boolean.wakeweekday_' ~ now().strftime("%a") | lower ~ '_1' %}
      {{ is_state('input_boolean.wakestatus_1', 'on') and is_state(today, 'on') }}
  action:
    service: switch.turn_on
    entity_id: switch.office_1

I found no need for the original example’s group, or some of its sensors, so they are not included here.

4. Lovelace UI

Finally, I used a combination of cards to create the following UI:

Screenshot from 2020-07-07 11-44-03

Click to reveal Lovelace card configuration
type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_boolean.wakestatus_1
        name: Mode
      - entity: sensor.wake_time_1
        name: Wake Time
      - entity: input_number.wakehour_1
      - entity: input_number.wakeminutes_1
    title: Alarm Clock 1
    show_header_toggle: false
  - type: horizontal-stack
    cards:
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_sun_1
        name: Sun
        icon_height: 40px
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_mon_1
        name: Mon
        icon_height: 40px
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_tue_1
        name: Tue
        icon_height: 40px
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_wed_1
        name: Wed
        icon_height: 40px
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_thu_1
        name: Thu
        icon_height: 40px
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_fri_1
        name: Fri
        icon_height: 40px
      - type: button
        tap_action:
          action: toggle
        hold_action:
          action: none
        show_icon: true
        show_name: true
        entity: input_boolean.wakeweekday_sat_1
        name: Sat
        icon_height: 40px
14 Likes

Oh, unbelievable, your config so nice and very very very DETAIL for newbie in Hass (me).

I don’t know how to say thank you because by word not enough. Thank you. I’m gonna fix my config,
thank you again! <3

1 Like

I think i need to learn writing in Scripts.Yaml, i want to set loop action because the xiaomi gateway only ring 1 times (about 3 seconds not enough for me to wakeup), i need to more and more loop to more and more sound to get me out of my bed. :smiley:

You can always repete the action in the automation.

Hello @Hellis81, how can i do it? :smiley: thanks

Are you using GUI or code to make your automations?

Im using code to do action in automation :smiley:
My code based on @123,
My code is

  alias: Wake 1
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == states('sensor.wake_time_1') }}"
  condition:
    condition: template
    value_template: >
      {% set today = 'input_boolean.wakeweekday_' ~ now().strftime("%a") | lower ~ '_1' %}
      {{ is_state('input_boolean.wakestatus_1', 'on') and is_state(today, 'on') }}
  action:
  - data:
      gw_mac: 00:00:00:00:00:00
      ringtone_id: 10
      ringtone_vol: 100
    service: xiaomi_aqara.play_ringtone

Then I will assume :

  alias: Wake 1
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == states('sensor.wake_time_1') }}"
  condition:
    condition: template
    value_template: >
      {% set today = 'input_boolean.wakeweekday_' ~ now().strftime("%a") | lower ~ '_1' %}
      {{ is_state('input_boolean.wakestatus_1', 'on') and is_state(today, 'on') }}
  action:
  - data:
      gw_mac: 00:00:00:00:00:00
      ringtone_id: 10
      ringtone_vol: 100
    service: xiaomi_aqara.play_ringtone
  - delay: 5 #????
  - data:
      gw_mac: 00:00:00:00:00:00
      ringtone_id: 10
      ringtone_vol: 100
    service: xiaomi_aqara.play_ringtone

Should do what you did and add a five second delay and do it again.
Keep in mind that HA will not wait for one action to finish before it does the next so add a delay between the sounds.
(At least that is how it works in Node RED, not sure about HA automation)

1 Like

Here is a more sophisticated version that includes a repeating alarm action that can be easily silenced using a button (in the UI).

Compared to the previous version, this one also has:

  • a timer, for repeating the alarm:
    • timer.wake_1
  • another input_boolean, for indicating when the alarm is activated:
    • input_boolean.wakeactivated_1
  • three additional automations, for managing the timer:
    • automation.wake_1_activated
    • automation.wake_1_timer_started
    • automation.wake_1_timer_finished
  • a Conditional card with a Button card to silence the alarm.

1. Timer, Input_Booleans and Input_Numbers

This version uses a 10-second timer for repeating the alarm action. Change the timer’s duration to whatever you prefer. There is also an additional input_boolean to indicate when the alarm is activated.

Click to reveal details
#configuration.yaml
timer:
  wake_1:
    duration: '00:00:10'

input_boolean:
  wakeactivated_1:
    name: Alarm 1 Activated
    icon: mdi:alarm
  wakestatus_1:
    name: Alarm 1
    icon: mdi:alarm
  wakeweekday_sun_1:
    name: Sunday
    icon: mdi:calendar
  wakeweekday_mon_1:
    name: Monday        
    icon: mdi:calendar
  wakeweekday_tue_1:
    name: Tuesday        
    icon: mdi:calendar
  wakeweekday_wed_1:
    name: Wednesday       
    icon: mdi:calendar
  wakeweekday_thu_1:
    name: Thursday       
    icon: mdi:calendar
  wakeweekday_fri_1:
    name: Friday        
    icon: mdi:calendar
  wakeweekday_sat_1:
    name: Saturday        
    icon: mdi:calendar

input_number:
  wakehour_1:
    name: Hour
    min: 00
    max: 23
    step: 1
    icon: mdi:alarm
  wakeminutes_1:
    name: Minutes
    min: 00
    max: 59
    step: 1

2. Sensors

The sensors remain the same as in the previous version.

Click to reveal details
#sensor:
- platform: template
  sensors:
    wake_time_1:
      friendly_name: 'Wake Time 1'
      value_template: "{{'{:02d}:{:02d}'.format(states('input_number.wakehour_1') | int, states('input_number.wakeminutes_1') | int) }}"

- platform: time_date
  display_options:
    - 'time'

3. Automation

In this version, there are three additional automations to handle the timer’s events. You must customize the action of automation.wake_1_alarm_activated to suit your needs. In this example, the action simply posts a persistent notification (visible in Home Assistant’s UI) every ten seconds (i.e. the timer’s duration).

Click to reveal details
- id: 'wake_1_detect_time'
  alias: Wake 1
  description: 'Detect specified wake time'
  trigger:
    platform: template
    value_template: "{{ states('sensor.time') == states('sensor.wake_time_1') }}"
  condition:
    condition: template
    value_template: >
      {% set today = 'input_boolean.wakeweekday_' ~ now().strftime("%a") | lower ~ '_1' %}
      {{ is_state('input_boolean.wakestatus_1', 'on') and is_state(today, 'on') }}
  action:
    service: input_boolean.turn_on
    entity_id: input_boolean.wakeactivated_1

- id: 'wake_1_alarm_activated'
  alias: 'Wake 1 Activated'
  trigger:
    platform: state
    entity_id: input_boolean.wakeactivated_1
    from: 'off'
    to: 'on'
  action:
    service: timer.start
    entity_id: timer.wake_1

- alias: 'Wake 1 Timer Started'
  trigger:
    platform: event
    event_type: timer.started
    event_data:
      entity_id: timer.wake_1
  condition:
    condition: state
    entity_id: input_boolean.wakeactivated_1
    state: 'on'
  action:
    service: persistent_notification.create
    data_template:
      title: 'Wake 1 Activated'
      message: 'Wake 1 activated at: {{now()}}'

- alias: 'Wake 1 Timer Finished'
  trigger:
    platform: event
    event_type: timer.finished
    event_data:
      entity_id: timer.wake_1
  condition:
    condition: state
    entity_id: input_boolean.wakeactivated_1
    state: 'on'
  action:
    service: timer.start
    entity_id: timer.wake_1

4. Lovelace UI

When no alarm is activated, this is its appearance in the UI (same as the previous version):

Screenshot from 2020-07-07 14-15-58

When an alarm is activated, a button appears below the alarm clock allowing you to silence the alarm. When you tap the button it will toggle the state of input_boolean.wakeactivated_1 (thereby preventing additional notifications) and the button will disappear from the UI.

Screenshot from 2020-07-07 14-17-29

Click to reveal Lovelace card configuration
cards:
  - entities:
      - entity: input_boolean.wakestatus_1
        name: Mode
      - entity: sensor.wake_time_1
        name: Wake Time
      - entity: input_number.wakehour_1
      - entity: input_number.wakeminutes_1
    show_header_toggle: false
    title: Alarm Clock 1
    type: entities
  - cards:
      - entity: input_boolean.wakeweekday_sun_1
        hold_action:
          action: none
        icon_height: 40px
        name: Sun
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
      - entity: input_boolean.wakeweekday_mon_1
        hold_action:
          action: none
        icon_height: 40px
        name: Mon
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
      - entity: input_boolean.wakeweekday_tue_1
        hold_action:
          action: none
        icon_height: 40px
        name: Tue
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
      - entity: input_boolean.wakeweekday_wed_1
        hold_action:
          action: none
        icon_height: 40px
        name: Wed
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
      - entity: input_boolean.wakeweekday_thu_1
        hold_action:
          action: none
        icon_height: 40px
        name: Thu
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
      - entity: input_boolean.wakeweekday_fri_1
        hold_action:
          action: none
        icon_height: 40px
        name: Fri
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
      - entity: input_boolean.wakeweekday_sat_1
        hold_action:
          action: none
        icon_height: 40px
        name: Sat
        show_icon: true
        show_name: true
        tap_action:
          action: toggle
        type: button
    type: horizontal-stack
  - type: conditional
    conditions:
      - entity: input_boolean.wakeactivated_1
        state: 'on'
    card:
      type: button
      tap_action:
        action: toggle
      hold_action:
        action: none
      show_icon: true
      show_name: true
      entity: input_boolean.wakeactivated_1
      name: Silence Alarm
      icon: 'mdi:alarm-off'
      icon_height: 50px
type: vertical-stack

NOTE

My personal preference would be to replace the two input_numbers (Hour and Minutes) and sensor (Wake Time) with a single input_datetime. The result of that choice means you must use your phone/tablet’s onscreen keyboard to set the time. I don’t mind the aesthetics of that but others might so that’s why I retained the original example’s use of input_numbers.

17 Likes

oh woa, very detail and you descibe very detail in per codes, Its help for me to know how it’s work, thank you for helping me :blush:. I gonna do its now, thank you very much @123

Hello @123,

Your config very effective for me. It’s wake me up right time to start my day.

But now im update my Hassio to 0.113, and i see it’s have so many code: Single, Queued, Parallel and Restart. Now, All my script don’t work, its only have sequence Red - Blue - Alarm 1 - Alarm 2 and turn off by themself, only do 1 sequence, not repeat. How can i fix that?

And i try using queued but it don’t work

Below is my code:

Thank for your help ^^

xiaomi_alarm1:
  sequence:
  - data:
      gw_mac: 7C:49:EB:1B:AA:52
      ringtone_id: 13
      ringtone_vol: 50
    service: xiaomi_aqara.play_ringtone
  - delay: '[object Object]'
  - service: script.xiaomi_alarm2
  mode: queued
  max: 10
xiaomi_alarm2:
  sequence:
  - data:
      gw_mac: 7C:49:EB:1B:AA:52
      ringtone_id: 13
      ringtone_vol: 75
    service: xiaomi_aqara.play_ringtone
  - delay: '[object Object]'
  - service: script.xiaomi_alarm1
  mode: queued
  max: 10
flash_gateway1:
  alias: Flash Gateway On Red
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.gateway_light_7c49eb1baa52
      color_name: red
      brightness: 255
  - delay:
      milliseconds: 600
  - service: light.turn_off
    data:
      entity_id: light.gateway_light_7c49eb1baa52
  - service: script.flash_gateway2
flash_gateway2:
  alias: Flash Gateway On Blue
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.gateway_light_7c49eb1baa52
      color_name: blue
      brightness: 255
  - delay:
      milliseconds: 600
  - service: light.turn_off
    data:
      entity_id: light.gateway_light_7c49eb1baa52
  - service: script.flash_gateway1

What is that? It should be a time value.

For example, a 2 second delay can be created like this:

  - delay: '00:00:02'

or like this:

  - delay:
      seconds: 2
1 Like

Oh i change to

  - delay:
      seconds: 2
But it not a loop, i think it's come from new action for scipt (single, restart, parallel and Queued