From 4c30687ee9f449683e24894a4217c6544d7c461c Mon Sep 17 00:00:00 2001 From: Georgi Gardev Date: Sun, 8 Mar 2020 12:31:24 +0200 Subject: [PATCH] Tweak speech. Add a separate music function --- packages/functions/music.yaml | 14 ++++++++++++++ packages/functions/speech.yaml | 12 ++++++++++-- packages/functions/system.yaml | 1 + packages/routines/coming_home.yaml | 21 +++++++++------------ packages/routines/waking_up.yaml | 9 ++------- templates/partials/window_check.yaml | 8 ++------ 6 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 packages/functions/music.yaml diff --git a/packages/functions/music.yaml b/packages/functions/music.yaml new file mode 100644 index 0000000..0064b3b --- /dev/null +++ b/packages/functions/music.yaml @@ -0,0 +1,14 @@ +script: + music_play: + alias: "Music - Play" + sequence: + - service: media_player.volume_set + entity_id: media_player.master_bedroom + data: + volume_level: 0.3 + - service: media_player.select_source + entity_id: media_player.master_bedroom + data: + source: "Evening Chill" + - service: fan.turn_off + entity_id: fan.philips_airpurifier diff --git a/packages/functions/speech.yaml b/packages/functions/speech.yaml index 2145c67..b829174 100644 --- a/packages/functions/speech.yaml +++ b/packages/functions/speech.yaml @@ -7,9 +7,11 @@ script: say: alias: Speech - Say sequence: + # Don't talk while in sleep mode. - condition: state entity_id: input_boolean.sleep_mode state: "off" + # Combine partials for speech message. - service: script.say_discretely data_template: message: >- @@ -24,6 +26,7 @@ script: say_discretely: alias: Speech - Say discretely sequence: + # Figure out whether to talk or send a text. - service_template: > {% if is_state('media_player.master_bedroom', 'playing') or is_state('input_boolean.speech_notifications', 'off') @@ -47,8 +50,13 @@ script: sequence: - service: media_player.volume_set entity_id: media_player.master_bedroom - data: - volume_level: 0.5 + data_template: + volume_level: >- + {% if now().strftime('%H')|int < 6 and now().strftime('%H')|int > 1 %} + 0.2 + {% else %} + 0.5 + {% endif %} - service: tts.amazon_polly_say data_template: entity_id: media_player.master_bedroom diff --git a/packages/functions/system.yaml b/packages/functions/system.yaml index 7d81f0d..712dd64 100644 --- a/packages/functions/system.yaml +++ b/packages/functions/system.yaml @@ -11,6 +11,7 @@ automation: platform: homeassistant event: start action: + - delay: 00:00:06 - service: script.say data: message: "Hey! I was out for a bit, but I'm back online!" diff --git a/packages/routines/coming_home.yaml b/packages/routines/coming_home.yaml index f60dc6c..d2b59f8 100644 --- a/packages/routines/coming_home.yaml +++ b/packages/routines/coming_home.yaml @@ -8,25 +8,22 @@ script: routine_coming_home: alias: Routine - Coming home sequence: + # Enter home mode. - service: script.security_camera_off - service: light.turn_on entity_id: light.living_room_all_lights + + # Check if welcome home is enabled, proceed with welcome routine. - condition: state entity_id: input_boolean.routine_welcome_home state: "on" - - delay: 00:00:03 - - service: script.coming_home_say_welcome - # TODO: Add condition for time - don't blast music late at night :) - - delay: 00:00:03 - - service: media_player.shuffle_set - entity_id: media_player.master_bedroom - data: - shuffle: true - - service: media_player.select_source - entity_id: media_player.master_bedroom - data: - source: Evening Chill + # Wait a while for me to enter before welcoming. + - delay: 00:00:02 + + - service: script.coming_home_say_welcome + - delay: 00:00:13 + - service: script.music_play coming_home_say_welcome: alias: Routine - Coming home - Say welcome diff --git a/packages/routines/waking_up.yaml b/packages/routines/waking_up.yaml index ef2bfcc..baebd3e 100644 --- a/packages/routines/waking_up.yaml +++ b/packages/routines/waking_up.yaml @@ -3,17 +3,12 @@ script: alias: Routine - Waking up sequence: - service: script.routine_morning_briefing - - delay: 00:00:25 + - delay: 00:00:35 - service: script.say data: message: "Here's some music to start the day!" - delay: 00:00:02 - - service: media_player.select_source - entity_id: media_player.master_bedroom - data: - source: "Evening Chill" - - service: fan.turn_off - entity_id: fan.philips_airpurifier + - service: script.music_play routine_morning_briefing: alias: Routine - Morning Briefing diff --git a/templates/partials/window_check.yaml b/templates/partials/window_check.yaml index 229f0de..6facbc6 100644 --- a/templates/partials/window_check.yaml +++ b/templates/partials/window_check.yaml @@ -1,12 +1,8 @@ >- {%- if is_state('group.all_windows', 'on') -%} - {%- if is_state('binary_sensor.living_room_right_window_on_off', 'on') -%} - The living room window is opened. - {%- endif -%} - {%- if is_state('binary_sensor.bedroom_right_window_on_off', 'on') -%} - The master bedroom window is opened. - {%- endif -%} + {%- if is_state('binary_sensor.living_room_right_window_on_off', 'on') -%} The living room window is opened. {% endif %} + {%- if is_state('binary_sensor.bedroom_right_window_on_off', 'on') -%} The master bedroom window is opened. {%- endif -%} {%- else -%} All windows are closed. {%- endif -%}