Last active
September 26, 2021 10:58
-
-
Save Didgeridrew/8da2b215aab524cedf26417f77676097 to your computer and use it in GitHub Desktop.
Set Alexa alarm from Home Assistant frontend with selectable echo device
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
###PREREQUISITES------------------------- | |
# This function relies on the Alexa Media Player add-on available for install through HACS | |
# | |
# You will need to create the following helpers: | |
# - input_select.alexa_alarm_selector | |
# This selector needs to have a name for every echo device you want to use. | |
# - input_datetime.alexa_alarm_set | |
# | |
# The "alexa_alarm_template" sensor leverages quirks of the English language in order to emulate | |
# a voice command. As such, it will likely not work if your Alexa devices are set to another language. | |
### SCRIPTS ----------------------------- | |
set_alexa_alarm: | |
alias: Set Alexa Alarm | |
sequence: | |
# - service: input_datetime.set_datetime | |
- service: media_player.play_media | |
data_template: | |
entity_id: '{{ states("sensor.alexa_alarm_selector") }}' | |
media_content_id: Set alarm for {{ state_attr("sensor.alexa_alarm_template", "alarm_hour") }}, {{ state_attr("sensor.alexa_alarm_template", "alarm_minute") }} | |
media_content_type: custom | |
cancel_alexa_alarm: | |
alias: Cancel Alexa Alarm | |
sequence: | |
- service: media_player.play_media | |
data_template: | |
entity_id: '{{ states("sensor.alexa_alarm_selector") }}' | |
media_content_id: 'Cancel {{ states(''input_datetime.alexa_alarm_set'') }} alarm' | |
media_content_type: custom | |
###SENSORS ----------------------------- | |
template: | |
sensor: | |
- name: "alexa_alarm_selector" | |
state: >- | |
{%- set room = states("input_select.alexa_alarm_selector") -%} | |
{% set echo_select = dict([ | |
('Kitchen Dot', 'kitchen_dot'), | |
('All', 'everywhere'), | |
('Living Room Dot', 'amanda_s_living_room_dot') | |
]) %} | |
{%- if room in echo_select -%} | |
media_player.{{ echo_select[room] }} | |
{%- endif %} | |
- name: "alexa_alarm_template" | |
state: > | |
Set alarm for {{state_attr("sensor.alexa_alarm_template", "alarm_hour")}} {{state_attr("sensor.alexa_alarm_template", "alarm_minute")}} {{state_attr("sensor.alexa_alarm_template", "am_pm")}} | |
attributes: | |
alarm_hour: > | |
{{ state_attr("input_datetime.alexa_alarm_set", "hour") }} | |
alarm_minute: > | |
{% if state_attr("input_datetime.alexa_alarm_set", "minute")|int <= 1 %} | |
hundred hours | |
{% elif 0 < state_attr("input_datetime.alexa_alarm_set", "minute")|int < 10 %} | |
{% set alarm_minute_post = state_attr("input_datetime.alexa_alarm_set", "minute") %} | |
{% set alarm_minute_pre = "Oh" %} | |
{{ [alarm_minute_pre, alarm_minute_post]|join(' ') }} | |
{% else%} | |
{{ state_attr("input_datetime.alexa_alarm_set", "minute") }} | |
{% endif %} | |
am_pm: > | |
{% if (state_attr("input_datetime.alexa_alarm_set", "hour")|int <= 12) and (state_attr("input_datetime.alexa_alarm_set", "minute")|int > 0)%} | |
in the morning | |
{% endif %} | |
### LOVELACE: Manual Card ----------------------------- | |
# Note: The input_datetime must be in it's own entity card | |
# it will not work if it is put in the "entities" card with the selector and execution buttons | |
type: vertical-stack | |
cards: | |
- type: 'custom:button-card' | |
color_type: label-card | |
color: var(--primary-color) | |
name: Alexa Alarm | |
styles: | |
name: | |
- font-weight: bold | |
- color: var(--primary-background-color) | |
- type: entity | |
entity: input_datetime.alexa_alarm_set | |
name: Enter Alarm Time Here | |
- entities: | |
- entity: input_select.alexa_alarm_selector | |
name: Select Alexa Device | |
- action_name: Set Alarm | |
icon: 'mdi:voice' | |
name: ' ' | |
service: script.set_alexa_alarm | |
type: call-service | |
- action_name: Cancel Alarm | |
icon: 'mdi:voice' | |
name: ' ' | |
service: script.cancel_alexa_alarm | |
type: call-service | |
type: entities |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment