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:
- 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):
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.
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.