From 4daa60d782a1669ad82c0d28fc8160f6d94b613e Mon Sep 17 00:00:00 2001 From: Georgi Gardev Date: Sun, 8 Mar 2020 02:16:38 +0200 Subject: [PATCH] Improve speech. Group lights and windows --- packages/functions/lighting.yaml | 11 +++++++---- packages/functions/speech.yaml | 19 ++++++++----------- packages/routines/coming_home.yaml | 23 +++++++++++++++-------- packages/routines/waking_up.yaml | 5 +++-- packages/sensors/windows.yaml | 7 +++++++ templates/partials/light_check.yaml | 10 +++++----- templates/partials/time.yaml | 3 +++ templates/partials/window_check.yaml | 15 +++++++++------ 8 files changed, 57 insertions(+), 36 deletions(-) create mode 100644 templates/partials/time.yaml diff --git a/packages/functions/lighting.yaml b/packages/functions/lighting.yaml index 38e9167..e5084de 100644 --- a/packages/functions/lighting.yaml +++ b/packages/functions/lighting.yaml @@ -12,12 +12,15 @@ light: - platform: group name: Living room all lights entities: - - light.living_room_1 - - light.living_room_2 - - light.living_room_3 - - light.living_room_4 + - light.living_room_main_lights - light.pc + - platform: group + name: All lights + entities: + - light.living_room_all_lights + - light.bedside_light + homeassistant: customize: light.living_room_1: diff --git a/packages/functions/speech.yaml b/packages/functions/speech.yaml index 3ac3a24..a21b2ef 100644 --- a/packages/functions/speech.yaml +++ b/packages/functions/speech.yaml @@ -4,16 +4,6 @@ input_boolean: icon: mdi:chat script: - talk_with_partials: - alias: Speech - Talk with combined partials - sequence: - - service: script.talk - data_template: - message: >- - {%- for partial in partials -%} - {{ partial }}{{ " " }} - {%- endfor -%} - talk: alias: Speech - Talk sequence: @@ -22,7 +12,14 @@ script: state: "off" - service: script.say_discretely data_template: - message: "{{ message }}" + message: >- + {%- if partials is defined -%} + {%- for partial in partials -%} + {{ partial }} + {% endfor %} + {%- else -%} + {{ message }} + {%- endif -%} say_discretely: alias: Speech - Say discretely diff --git a/packages/routines/coming_home.yaml b/packages/routines/coming_home.yaml index 484ed8c..7b880f7 100644 --- a/packages/routines/coming_home.yaml +++ b/packages/routines/coming_home.yaml @@ -41,15 +41,22 @@ script: entity_id: media_player.master_bedroom data: volume_level: 0.5 - - service: script.talk_with_partials + - service: script.talk data_template: partials: - !include ../../templates/partials/greeting.yaml + - !include ../../templates/partials/time.yaml + - "Here's the current status:" - !include ../../templates/partials/window_check.yaml - - >- - {{ - [ - "I'll play some music.", - "Here's some music." - ] | random - }} + - delay: "00:00:02" + - service: script.talk + data_template: + message: >- + + {{ + [ + "I'll put some music on.", + "I'll play some music.", + "Here's some music." + ] | random + }} diff --git a/packages/routines/waking_up.yaml b/packages/routines/waking_up.yaml index 11ffcb4..0efceb1 100644 --- a/packages/routines/waking_up.yaml +++ b/packages/routines/waking_up.yaml @@ -21,11 +21,12 @@ script: - service: media_player.volume_set entity_id: media_player.master_bedroom data: - volume_level: 0.3 - - service: script.talk_with_partials + volume_level: 0.5 + - service: script.talk data_template: partials: - !include ../../templates/partials/greeting.yaml + - !include ../../templates/partials/time.yaml - >- {{ [ diff --git a/packages/sensors/windows.yaml b/packages/sensors/windows.yaml index 3290f3f..2a41c81 100644 --- a/packages/sensors/windows.yaml +++ b/packages/sensors/windows.yaml @@ -38,3 +38,10 @@ homeassistant: sensor.bedroom_right_window_power: friendly_name: Bedroom window battery + +group: + all_windows: + name: "All windows" + entities: + - binary_sensor.living_room_right_window_on_off + - binary_sensor.bedroom_right_window_on_off diff --git a/templates/partials/light_check.yaml b/templates/partials/light_check.yaml index d3dbfcd..1fb922f 100644 --- a/templates/partials/light_check.yaml +++ b/templates/partials/light_check.yaml @@ -1,11 +1,11 @@ >- - {%- if is_state('light.living_room_all_lights', 'on') -%} - There are + {%- if is_state('light.all_lights', 'on') -%} + There are {%- for state in states.light if state.state == 'on' -%} - {%if loop.last %} {{ loop.index }} {% endif %} + {% if loop.last %} {{ loop.index }} {% endif %} {%- endfor -%} - lights on right now. + lights turned on right now. {%- else -%} - There are no lights on right now. + There are no lights turned on right now. {%- endif -%} diff --git a/templates/partials/time.yaml b/templates/partials/time.yaml new file mode 100644 index 0000000..39cbdf9 --- /dev/null +++ b/templates/partials/time.yaml @@ -0,0 +1,3 @@ +>- + + The time is {{ now().hour }} {{ "%0.02d" | format(now().strftime("%-M") | int) }}. diff --git a/templates/partials/window_check.yaml b/templates/partials/window_check.yaml index 99b32f3..229f0de 100644 --- a/templates/partials/window_check.yaml +++ b/templates/partials/window_check.yaml @@ -1,9 +1,12 @@ >- - {%- 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. + {%- 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 -%} + {%- else -%} + All windows are closed. {%- endif -%}