How to create the alarm clock in HASS?

OK. No worries.

Thanks

Hello. Please help, what needs to be changed in the code so that the alarm clock turns on 1 hour before the set time?

Do you know what the idea of an alarm is??

Itā€™s the first time that i misunderstanding something on HAā€¦ I lost the ballā€¦ :rofl:

So, i want an Alarm Clock like this:

but after all this code dosenā€™t work for me even with (card-mod installed) itā€™s give me a completly error on card:

  - 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

I did the below:

CONFIGURATION.YAML

#Alarm Clock
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) }}"

  - platform: time_date
    display_options:
    - 'time'

AUTOMATIONS.YAML

- 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

LOVELACE UI CARD (i want the above card but only this card but worked)

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

and after all getting error on the card.

What i miss?

After these I want to play a custom .mp3 file from /loca/ on a media_player (Google Nest Audio)
Thanks!

Sorry for long time reply, you miss this, sensor.yaml in platform template, here:

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

Hello, because of all these time gap I delete the hole code. Can you provide all the working code for this:

Thanks.

Here is mine

1. Config.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. Automation.yaml

- id: alarm_clock_123
  alias: (System) - Wake 1
  description: ''
  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: script.turn_on
    entity_id:
    - script.flash_gateway3
    - script.xiaomi_alarm3
    - script.alarm_wake_up
  mode: single

3. Sensor.yaml

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

4. Lovelace.yaml

cards:
  - 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
      - show_name: true
        show_icon: true
        entity: script.alarm_snooze
        icon: mdi:alarm-snooze
        icon_height: 50px
        name: Snooze!!!!
        show_state: false
        type: button
        tap_action:
          action: call-service
          service: script.turn_on
          target:
            entity_id: script.alarm_snooze
          data: {}
    type: horizontal-stack
type: vertical-stack

5. Scripts.yaml

xiaomi_alarm3:
  sequence:
  - repeat:
      count: 180
      sequence:
      - data:
          gw_mac: 7C
          ringtone_id: 13
          ringtone_vol: 100
        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_a52
        service: light.turn_on
      - delay:
          seconds: 1
      - data:
          brightness: 255
          color_name: red
          entity_id: light.gateway_light_a52
        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_a52
      color_name: green
      brightness: 100
  - delay:
      seconds: 5
  - service: light.turn_off
    data:
      entity_id: light.gateway_light_a52
  mode: single

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
  - service: media_player.volume_set
    data:
      volume_level: 0.35
    target:
      entity_id: media_player.speaker
  - service: script.turn_off
    data: {}
    target:
      entity_id: script.alarm_snooze
  mode: single

alarm_snooze:
  alias: Alarm was Snooze
  sequence:
  - service: script.alarm_off
  - service: light.turn_on
    data:
      entity_id: light.gateway_light_7c
      color_name: purple
      brightness: 100
  - delay:
      seconds: 5
  - service: light.turn_off
    data:
      entity_id: light.gateway_light_7c
  - 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
  mode: single

alarm_wake_up:
  sequence:
  - parallel:
    - service: light.turn_on
      target:
        entity_id: light.
      data:
        brightness: 255
    - service: switch.turn_on
      data: {}
      target:
        entity_id: switch.zb_l2
    - service: spotcast.start
      data:
        force_playback: true
        start_volume: 100
        uri: spotify:playlist:7aRaMXFZjLWxJHftydI626
        random_song: true
        repeat: context
        shuffle: true
        entity_id: media_player.speaker
  mode: single
  alias: Alarm Wake up
2 Likes

Thanks but I think you messed up with your code for alarm clock with home alarm scriptsā€¦
Iā€™m trying to fix the snooze and silence alarm button with right code for alarm clock.

PS in config you missed the input_boolean: before wakeactivated_1 and I was tried to figure it outā€¦ after a lot of time I copy my code from above and saw that.

I think it will be better to make someone from HA a integration with an alarm clock and make it more easy for a lot of people.

Anyway thanks.

If anyone can help to make snooze and silence buttons works it will be perect! :grin:

Yah, sorry for my mistake, i put many codes in dir /config, and not clean up this, matrix of codes bruhhh.

Snooze and slience alarm i think just turn off the script? Right? In first code of @123,
just enable the script turn on,
I seperate many script because i have another automation using this script in here, and devide code to many scripts make me dont create too much same scripts again.

And you have problem with silence or snooze? (Snooze just dupilicate from silence and delay in time to run wake up script again).

so, whatā€™s the final working variant?)

Here:

thanks, i got it configured for me.

Is it possible to automate the time the alarm clock is set based on Calendar entries?
ie. Set set the alarm to 1hr 30min before calendar.work is ā€˜Onā€™.

Iā€™d like to turn something on 10 minutes before my alarm goes off. Iā€™m using this template to trigger the alarm. I copied it from somebody but canā€™t remember where and I know nothing about templating. Does anyone know how to change this so it triggers 10 minutes before the alarm set time?

trigger:
    - platform: template
      value_template:
        '{% set dow = now().strftime("%A")|lower %} {% set input = "input_datetime."~dow~"_alarm"
        %} {{ now() >= today_at(states(input)) }} '

I keep getting a Bad indentation error for the sensors portion. Is anyone lese having this?

How do I create the sensors portion of this?

When I try to copy\past this into my configuration.yalm I receive an error on the first line saying @end of the stream of a document separator is expected?

Is there a way to get the wake_time sensor with the actual next Date?

Example:
17. February 2024 at 18:25

I am relatively new to HA and very grateful for Help :slight_smile:

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

Hello, for long time to back to this community,

do you still need my help? Please describe your question here, pleasure to help you!

Hi Kayden,

How will a stitch all this code. Where will a copy all this code in HA?

Robin

Here: How to create the alarm clock in HASS? - #47 by Kayden919

Any question?