How to create the alarm clock in HASS?

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

Iā€™m not suggesting you change to a 2-second delay only that you correct the delay you already have in your script because this is invalid:
delay: '[object Object]'

Regarding the mode option, if you do not include it in a script, according to the documentation, the script will default to using mode: single.

1 Like

Oh i read infomations change in 0.113. Itā€™s have advanced for coding (Included 4 mode for Automation & Action, and Somes changes in Automation, to fix code can run on 0.113. We need to fix:

In Automation (Change method to Call Script in action)

#(For 0.113 or later)  
action:   
    - service: script.turn_on 
      entity_id:
      - script.flash_gateway1
      - script.xiaomi_alarm1

Describe: In 0.112 or previous Version, we call script directly, like below (DONT DO BELOW CODE FOR 0.113 OR LATER)

Action: 
    - service: script.xiaomi_alarm1
    - service: script.flash_gateway1

This mean, after run script.xiaomi_alarm1 done, it will do continue flash_gateway1.

But Script script.xiaomi_alarm1 is a infinity loops. Itā€™s cant be done, and cant continue script flash_gateway1.

In new config we need to call it thourgh on service script turn on. Itā€™s will run 2 scripts same time (not wait script 1 done (end) and will do script 2).

I donā€™t known 4 new mode for script and automation, but i try per mode one by one. And Parallel is work. And option max for Parralel to do maxium loops. I using 90 for sound and 1000 for light. I think it right for me. (depend on you)

In Script (Using Parallel mode)

xiaomi_alarm1:
  sequence:
  - data:
      gw_mac: ####
      ringtone_id: 13
      ringtone_vol: 50
    service: xiaomi_aqara.play_ringtone
  - delay:
      seconds: 6
  - service: script.xiaomi_alarm2
  mode: parallel
  max: 90

xiaomi_alarm2:
  sequence:
  - data:
      gw_mac: ####
      ringtone_id: 13
      ringtone_vol: 75
    service: xiaomi_aqara.play_ringtone
  - delay:
      seconds: 6
  - service: script.xiaomi_alarm1
  mode: parallel
  max: 90


flash_gateway1:
  alias: Flash Gateway On Red
  sequence:
  - data:
      brightness: 255
      color_name: red
      entity_id: light.gateway_light_####
    service: light.turn_on
  - delay:
      milliseconds: 600
  - data:
      entity_id: light.gateway_light_####
    service: light.turn_off
  - service: script.flash_gateway2
  mode: parallel
  max: 1000

flash_gateway2:
  alias: Flash Gateway On Blue
  sequence:
  - data:
      brightness: 255
      color_name: blue
      entity_id: light.gateway_light_####
    service: light.turn_on
  - delay:
      milliseconds: 600
  - data:
      entity_id: light.gateway_light_####
    service: light.turn_off
  - service: script.flash_gateway1
  mode: parallel
  max: 1000

And now, itā€™s work. Thank you very much, @123

Hi, I try to implement your configuration but snoozing doesnā€™t seem to work. Can you please share you entire code please?
Thanks Chris.

I will post it after my school day, 3pm GMT +7, pls remind me ^^

Ok Thanks a lot.

This is my script, so many scripts, because i devided it to make another automation (sercurity alarm)

xiaomi_alarm3:
  sequence:
  - repeat:
      count: 180
      sequence:
      - data:
          gw_mac: 7C:49:EB:1B:AA:52
          ringtone_id: 13
          ringtone_vol: 90
        service: xiaomi_aqara.play_ringtone
      - delay:
          seconds: 6
  mode: restart
flash_gateway3:
  alias: Flash Gateway On Blue and Red
  sequence:
  - repeat:
      count: 600
      sequence:
      - data:
          brightness: 255
          color_name: blue
          entity_id: light.gateway_light_7c49eb1baa52
        service: light.turn_on
      - delay:
          seconds: 1
      - data:
          brightness: 255
          color_name: red
          entity_id: light.gateway_light_7c49eb1baa52
        service: light.turn_on
      - delay:
          seconds: 1
  mode: restart

alarm_off:
  alias: Alarm was disarmed
  sequence:
  - service: script.turn_off
    data:
      entity_id:
      - script.flash_gateway3
      - script.xiaomi_alarm3

green_light_safe:
  alias: Green light for safe
  sequence:
  - service: light.turn_on
    data:
      entity_id: light.gateway_light_7c49eb1baa52
      color_name: green
      brightness: 100
  - delay:
      seconds: 5
  - service: light.turn_off
    data:
      entity_id: light.gateway_light_7c49eb1baa52

alarm_off_greenlight:
  alias: Alarm was disarmed & Green light on
  sequence:
  - service: script.turn_on
    data:
      entity_id:
      - script.alarm_off
      - script.green_light_safe

alarm_snooze:
  alias: Alarm was Snooze
  sequence:
  - service: script.alarm_off
  - service: light.turn_on
    data:
      entity_id: light.gateway_light_7c49eb1baa52
      color_name: purple
      brightness: 100
  - delay:
      seconds: 5
  - service: light.turn_off
    data:
      entity_id: light.gateway_light_7c49eb1baa52
  - delay:
      seconds: 300
  - service: script.turn_on
    entity_id:
    - script.flash_gateway3
    - script.xiaomi_alarm3
  - delay:
      seconds: 300
  - service: script.turn_on
    entity_id:
    - script.alarm_off

And my automation. like above but custom script turn on to run 2 scripts.

  action:
  - service: script.turn_on
    entity_id:
    - script.flash_gateway3
    - script.xiaomi_alarm3

Great thanks. Maybe your lovelace?
I tried 123 code it works to start but not the snooze

My lovelace using HA-Card (Custom Component)

  - content: |
      # Alarm System
    style:
      .: |
        ha-card {
          background-color: transparent !important;
          box-shadow: none !important;
        }
      ha-markdown:
        $: |
          h1 {
            font-size: 25px;
            font-weight: bold;
            text-align: center;
            letter-spacing: '-0.01em';
           }
    type: markdown
  - entities:
      - entity: input_boolean.wakestatus_1
        name: Mode
      - entity: sensor.time
        name: The Time Now
      - entity: sensor.wake_time_1
        name: Wake Time
      - entity: input_number.wakehour_1
      - entity: input_number.wakeminutes_1
    show_header_toggle: false
    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
  - cards:
      - entity: script.alarm_off_greenlight
        hold_action:
          action: toggle
        icon: 'mdi:alarm-off'
        icon_height: 50px
        name: Silence Alarm
        show_icon: true
        show_name: true
        show_state: false
        tap_action:
          action: more-info
        type: button
      - entity: script.alarm_snooze
        hold_action:
          action: more-info
        icon: 'mdi:alarm-snooze'
        icon_height: 50px
        name: Snooze !!!
        show_icon: true
        show_name: true
        show_state: false
        tap_action:
          action: toggle
        type: button
    type: horizontal-stack
type: vertical-stack
1 Like

I work with package. Here is my complete 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
    
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) }}"

script:
  xiaomi_alarm1:
    sequence:
    - data:
        gw_mac: 'macadress'
        ringtone_id: 13
        ringtone_vol: 50
      service: xiaomi_aqara.play_ringtone
    - delay:
        seconds: 6
    - service: script.xiaomi_alarm2
    mode: parallel
    max: 10

  xiaomi_alarm2:
    sequence:
    - data:
        gw_mac: 'macadress'
        ringtone_id: 13
        ringtone_vol: 75
      service: xiaomi_aqara.play_ringtone
    - delay:
        seconds: 6
    - service: script.xiaomi_alarm1
    mode: parallel
    max: 10

xiaomi_alarm3:
  sequence:
  - repeat:
      count: 180
      sequence:
      - data:
          gw_mac: 'macadress'
          ringtone_id: 13
          ringtone_vol: 40
        service: xiaomi_aqara.play_ringtone
      - delay:
          seconds: 6
  mode: restart

alarm_snooze:
  alias: Alarm was Snooze
  sequence:
  - service: script.alarmclock_off
  - delay:
      seconds: 300
  - service: script.turn_on
    entity_id:
    - script.xiaomi_alarm3
  - delay:
      seconds: 300
  - service: script.turn_on
    entity_id:
    - script.alarmclock_off

alarmclock_off:
  alias: Alarm was disarmed
  sequence:
  - service: script.turn_off
    data:
      entity_id:
      - script.xiaomi_alarm3


automation:
  - 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
    action:   
      service: script.turn_on 
      entity_id:
      - script.xiaomi_alarm1

  - 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```
1 Like

And Here is my lovelace card

cards:
  - entities:
      - entity: input_boolean.wakestatus_1
        name: Mode
      - entity: sensor.time
        name: Heure Actuelle
      - entity: sensor.wake_time_1
        name: Heure RĆ©veil
      - entity: input_number.wakehour_1
        name: Heure
      - entity: input_number.wakeminutes_1
    show_header_toggle: false
    title: RĆ©veil
    type: entities
  - cards:
      - entity: input_boolean.wakeweekday_sun_1
        hold_action:
          action: none
        icon_height: 40px
        name: Dim
        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: Lun
        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: Mar
        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: Mer
        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: Jeu
        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: Ven
        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: Sam
        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: more-info
      show_icon: true
      show_name: true
      show_state: false
      entity: script.alarm_snooze
      name: Snooze
      icon: 'mdi:alarm-off'
      icon_height: 50px
1 Like

EDIT Nevermind. :slight_smile: I Realised I shouldnā€™t edit the yaml like that, but instead click the ā€œAdd cardā€ button, and then choose to add a custom card manually. Thank yo for the code, works perfect! :smiley:


Hi,
I really like the example you have here! I hope you can help me detect what Iā€™ve done wrong though with regards to the lovelace card.

In the Overview of Home Assistant, I click to edit my dashboard, click the 3 dot dropdown menu, and then click: ā€œRaw configuration editorā€.

I then put your lovelace configuration card code at the bottom, but I cannot get it to show on the dashboard. Can you see what Iā€™m doing wrong? This is my code:

title: Home
views:
  - path: default_view
    title: Home
    badges: []
    cards:
      - type: entities
        entities:
          - entity: light.stuen_spots_zha_group_0x0002
            name: Spots
          - entity: cover.gardin_balkon_window_covering
          - entity: cover.gardin_stue_window_covering
        title: Stuen
      - type: entities
        entities:
          - entity: light.loftlys_sovevarelset_level_light_color_on_off
            name: Loftlys
          - entity: cover.gardin_1_window_covering
          - entity: cover.gardin_2_window_covering
          - entity: switch.ikea_of_sweden_tradfri_control_outlet_aeea6afe_on_off
            name: Mikkels natlampe
          - entity: switch.ikea_of_sweden_tradfri_control_outlet_1c7f72fe_on_off
            name: Barboras natlampe
        title: SovevƦrelset
      - type: entities
        entities:
          - entity: light.loftlys_gangen_level_light_color_on_off
            name: Loftlys
          - entity: binary_sensor.lumi_lumi_sensor_motion_aq2_ias_zone
          - entity: binary_sensor.lumi_lumi_sensor_motion_aq2_2ded4c05_ias_zone
        title: Gangen
      - type: entities
        entities:
          - entity: light.loftlys_hyggerummet_level_light_color_on_off
            name: Loftlys
        title: Hyggerummet
      - type: entities
        entities:
          - entity: light.klaedeskabet_spots_zha_group_0x0006
            name: Spots
        title: KlƦdeskabet
      - type: entities
        entities:
          - entity: light.loftlys_kontoret_level_light_color_on_off
            name: Loftlys
        title: Kontoret
      - type: entities
        entities:
          - entity: light.loftlys_koekken_level_light_color_on_off
            name: Loftlys
          - entity: cover.gardin_kokken_window_covering
        title: KĆøkkenet
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

Hello thanks for this alarm i got i working and like so much that i will like more of them .
if i want this i 2 different cards ? can you help me what to change because copy them will
not work i changes i both alarms i tried to change some of the 1 to 2 but no luck ,as you can gues
i`m not a coder at all , can some one help ?

You need to duplicate the entities used in your existing, functional alarm clock in order to create a second, independent instance of the alarm clock. Changing the names of the duplicated entities (such as by changing _1 to _2) is definitely required. If it didnā€™t work then you must have either overlooked to rename one of the entities or within the automation itself. Review it carefully, check the automationā€™s trace for errors, check the log for errors and youā€™ll get it working eventually.

Hey! I used your code to trigger my irrigation system and it works like a charmā€¦ until I added a new sensor to my yaml and now yours seems to be problematic :frowning:

Error loading /config/configuration.yaml: while parsing a block collection in "/config/sensors.yaml", line 15, column 3 expected <block end>, but found '<block mapping start>' in "/config/sensors.yaml", line 27, column 4

I can only think (but Iā€™m the first to admit that I donā€™t really know) that it has to do with the fsensor using a legacy nomenclature. Could definitely use help from anyone having a clue of what could be wrong here :frowning:

Thank you!

Here is my sensors.yaml starting line 15

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

  - 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) }}"

Have you noticed that there are multiple, very obvious, indentation errors in the sensors.yaml you posted?

Is that literally how it appears or just due to a copy-paste error when you posted it on the forum?

Thanks for this @123, your instructions are really good.
I agree with you about using a single input_datetime but I havenā€™t been able to get it to work. Iā€™m really bad at templates and havenā€™t worked out how to create a sensor for the input_datetime. How would you implement this?
Thanks!

I donā€™t recall an input_datetime entity in the example. Are you referring to the Template Sensor called sensor.wake_time_1?

You should know that the example was created over two years ago. A lot has changed since then and itā€™s highly likely there are now better ways to implement an alarm clock.

Apologies, I realised my question probably didnā€™t make senseā€¦
What I meant by the input_datetime sensor is a replacement for the sensor.wake_time_1. So instead of using the sliders for the hour/ minutes Iā€™d prefer entering the wake time using the number keys on the phone/PC. and what I donā€™t understand is how do I replace the hours/minutes with a manual time entry. Do I use a input_number helper? if yes I donā€™t know how to use the value_template to create the sensor.wake_time_1 or if I even need to?
Sorry, my yaml/ templating skills are poor and I havenā€™t been able to find another decent alarm clock :slight_smile:

I see. You want to modify the alarm clockā€™s design to use input_datetime instead of input_number.

Unfortunately I donā€™t have the time to adapt it to meet new requirements. Someone else will need to help you with it. Good luck.