In this post, I will cover off how to set up a simple alarm clock using Home Assistant and Alexa. For this, you will need the following: a reliable internet connection, a Home Assistant server, an Alexa-enabled device, and some basic knowledge of YAML scripting. First, we will walk through installing and configuring Home Assistant on your server. Then, we will show you how to integrate Alexa with your Home Assistant setup. Finally, we will create an automation script using YAML to set up your alarm clock. By the end of this guide, you will have a fully functional alarm clock that you can control using Alexa voice commands.
Don’t forget, you will need:
Home Assistant
an Alexa Device
The Alexa Media Player integration (https://github.com/alandtse/alexa_media_player)
fold-entity-row from HACS (https://github.com/thomasloven/lovelace-fold-entity-row)
First we need to add some input booleans in our configuration.yaml:
input_boolean:
wakeup_weekend:
name: "Weekend"
icon: mdi:power
initial: on
wakeup_monday:
name: Monday
icon: mdi:calendar
initial: on
wakeup_tuesday:
name: Tuesday
icon: mdi:calendar
initial: on
wakeup_wednesday:
name: Wednesday
icon: mdi:calendar
initial: on
wakeup_thursday:
name: Thursday
icon: mdi:calendar
initial: on
wakeup_friday:
name: Friday
icon: mdi:calendar
initial: on
wakeup_saturday:
name: Saturday
icon: mdi:calendar
initial: off
wakeup_sunday:
name: Sunday
icon: mdi:calendar
initial: off
alarmweekday:
name: Weekdays Only
initial: off
icon: mdi:alarm
alarm_clock_status:
initial: on
Next, we need to add some input selects in the same file:
input_select:
alarm_clock_hour:
name: Hour
options:
- "00"
- "01"
- "02"
- "03"
- "04"
- "05"
- "06"
- "07"
- "08"
- "09"
- "10"
- "11"
- "12"
- "13"
- "14"
- "15"
- "16"
- "17"
- "18"
- "19"
- "20"
- "21"
- "22"
- "23"
icon: mdi:clock-time-four-outline
alarm_clock_minute:
name: Minute
options:
- "00"
- "05"
- "10"
- "15"
- "20"
- "25"
- "30"
- "35"
- "40"
- "45"
- "50"
- "55"
icon: mdi:clock-time-four-outline
Finally, lets add some templated sensors:
sensor:
- platform: template
sensors:
alarm_clock_hour:
value_template: "{{ states('input_select.alarm_clock_hour') | int }}"
alarm_clock_minute:
value_template: "{{ states('input_select.alarm_clock_minute') | int }}"
alarm_clock_time:
value_template: "{{ states('sensor.alarm_clock_hour') }}:{% if
states('sensor.alarm_clock_minute')|length == 1 %}0{% endif %}{{
states('sensor.alarm_clock_minute') }}"
alarm_clock_time_long:
value_template: "{% if states('sensor.alarm_clock_hour')|length == 1 %}0{% endif
%}{{ states('sensor.alarm_clock_hour') }}:{% if
states('sensor.alarm_clock_minute')|length == 1 %}0{% endif %}{{
states('sensor.alarm_clock_minute') }}"
Save and restart Home Assistant
Next lets add the card to your dashboard, this is how it should look:
and when expanded:
Add a card, and edit the code so it looks like this:
type: vertical-stack
title: Alarm Clock
cards:
- type: entities
entities:
- entity: sensor.alarm_clock_time
name: Alarm Time
- type: custom:fold-entity-row
head:
type: section
label: Set Alarm Time
entities:
- entity: input_select.alarm_clock_hour
name: Set Hour
- entity: input_select.alarm_clock_minute
name: Set Minute
- entity: input_boolean.alarm_clock_status
name: Alarm Enabled
- type: horizontal-stack
cards:
- type: button
entity: input_boolean.wakeup_sunday
name: Sun
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
- type: button
entity: input_boolean.wakeup_monday
name: Mon
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
- type: button
entity: input_boolean.wakeup_tuesday
name: Tue
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
- type: button
entity: input_boolean.wakeup_wednesday
name: Wed
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
- type: button
entity: input_boolean.wakeup_thursday
name: Thu
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
- type: button
entity: input_boolean.wakeup_friday
name: Fri
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
- type: button
entity: input_boolean.wakeup_saturday
name: Sat
icon: mdi:calendar
show_state: false
tap_action:
action: toggle
Great, so now we need to bring it all together – let’s use an automation for that
Create a new automation, and change to YAML mode:
alias: Bedroom Alarm
description: ""
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"
- condition: template
value_template: >-
{{ is_state('input_boolean.wakeup_' ~
['monday','tuesday','wednesday','thursday','friday','saturday','sunday'][now().weekday()],
'on') }}
action:
- data:
data:
type: announce
message: Good Morning, it's time to get up
action: notify.alexa_media_master_bedroom
mode: single
Change the alias to whatever you want, the message in bold will be what Alexa reads out and the second to last line “notify.alexa_media_master_bedroom” – insert your alexa media player entity here instead.
That’s it! You can set the Alarm time and days from the UI and be woken up every day with the message of your choice. Imagine starting your day with a cheerful greeting tailored to you! Additionally, you could also configure the action to start your favorite radio station instead, ensuring you wake up to your preferred tunes every morning. This way, you have full control over your wake-up routine and can customize it to fit your preferences perfectly. Enjoy a personalized and pleasant wake-up experience daily with these simple adjustments!
Example automation to play a radio station instead (BBC Radio 1):
alias: Bedroom Alarm
description: ""
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"
- condition: template
value_template: >-
{{ is_state('input_boolean.wakeup_' ~
['monday','tuesday','wednesday','thursday','friday','saturday','sunday'][now().weekday()],
'on') }}
action:
- action: media_player.play_media
target:
entity_id: media_player.big_echo
data:
media_content_id: bbc radio 1
media_content_type: custom
metadata: {}
mode: single