Last active
July 30, 2020 13:34
-
-
Save Brunty/df7c0c9afae703cf0f16dc3ddfb9d244 to your computer and use it in GitHub Desktop.
Message announcement in HA
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
# https://github.com/snarky-snark/home-assistant-variables | |
var: | |
media_volume_living_room: | |
friendly_name: "Living Room Media Volume" | |
initial_value: 0 | |
media_volume_matt_office: | |
friendly_name: "Matt Office Media Volume" | |
initial_value: 0 |
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
cards: | |
- entities: | |
- entity: input_select.announce_to | |
name: Announce to? | |
- entity: input_number.announcement_volume | |
name: Volume | |
# https://github.com/gadgetchnnel/lovelace-text-input-row | |
- entity: input_text.home_announcement_message | |
name: Message | |
type: 'custom:text-input-row' | |
- action_name: Announce it | |
icon: 'mdi:voice' | |
icon_height: 60px | |
name: ' ' | |
service: script.announce_message | |
type: call-service | |
type: entities | |
title: null | |
type: 'custom:vertical-stack-in-card' |
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
'announce_message': | |
alias: Announce message | |
sequence: | |
# Store the current volumes of the media players | |
- service: var.set | |
entity_id: 'var.media_volume_living_room' | |
data: | |
entity_id: 'var.media_volume_living_room' | |
value_template: "{{ state_attr('media_player.living_room_mini_speaker', 'volume_level')|float }}" | |
- service: var.set | |
entity_id: 'var.media_volume_matt_office' | |
data: | |
entity_id: 'var.media_volume_matt_office' | |
value_template: "{{ state_attr('media_player.matt_office_mini_speaker', 'volume_level')|float }}" | |
- service: media_player.volume_set | |
data_template: | |
entity_id: > | |
{%- if is_state('input_select.announce_to', 'Everywhere') -%} | |
media_player.living_room_mini_speaker, media_player.matt_office_mini_speaker | |
{%- elif is_state('input_select.announce_to', 'Living Room') -%} | |
media_player.living_room_mini_speaker | |
{%- elif is_state('input_select.announce_to', 'Matt Office') -%} | |
media_player.matt_office_mini_speaker | |
{%- endif -%} | |
volume_level: "{{ states('input_number.announcement_volume')|float }}" | |
- data_template: | |
cache: false | |
message: "{{ states('input_text.home_announcement_message') }}" | |
entity_id: > | |
{%- if is_state('input_select.announce_to', 'Everywhere') -%} | |
media_player.living_room_mini_speaker, media_player.matt_office_mini_speaker | |
{%- elif is_state('input_select.announce_to', 'Living Room') -%} | |
media_player.living_room_mini_speaker | |
{%- elif is_state('input_select.announce_to', 'Matt Office') -%} | |
media_player.matt_office_mini_speaker | |
{%- endif -%} | |
service: tts.google_translate_say | |
- delay: 00:00:10 | |
# Set volumes back to what they were before | |
- service: media_player.volume_set | |
data_template: | |
entity_id: media_player.living_room_mini_speaker | |
volume_level: "{{ states('var.media_volume_living_room')|float }}" | |
- service: media_player.volume_set | |
data_template: | |
entity_id: media_player.matt_office_mini_speaker | |
volume_level: "{{ states('var.media_volume_matt_office')|float }}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment