]> git.giorgioravera.it Git - homeassistant.git/commitdiff
Exported speech text from script
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 31 Mar 2020 14:51:32 +0000 (16:51 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Tue, 31 Mar 2020 14:51:32 +0000 (16:51 +0200)
script/speech_engine.yaml
templates/speech_message.yaml [new file with mode: 0644]

index bc11f47bf35a26e97a534c13566f3abd7ef8795e..9d4413f264cf4ff26d49fdb0b0abc6fc18e06ccc 100644 (file)
@@ -23,193 +23,7 @@ speech_engine:
         media_player: "{{ media_player }}"
         volume_level: "{{ volume_level }}"
         language: "{{ language }}"
-        message: >-
-          
-          {# *********************************************** #}
-          {# ***************** Check Input ***************** #}
-          {# *********************************************** #}
-          {% if enable_greeting is not defined %}
-            {% set enable_greeting=0 %}
-          {% endif %}
-          {% if enable_status is not defined %}
-            {% set enable_status=0 %}
-          {% endif %}
-          {% if enable_location is not defined %}
-            {% set enable_location=0 %}
-          {% endif %}
-          {% if location_people_start is not defined %}
-            {% set location_people_start=1 %}
-          {% endif %}
-          {% if location_people_num is not defined %}
-            {% set location_people_num=2 %}
-          {% endif %}          
-          {% if enable_car is not defined %}
-            {% set enable_car=0 %}
-          {% endif %}
-          
-          {# *********************************************** #}
-          {# ******************** Macro ******************** #}
-          {# *********************************************** #}
-          
-          {# Greeting Message #}
-          {%- macro greeting() -%}
-            {% if now().strftime('%H')|int >= 7 and now().strftime('%H')|int < 12 %}
-              Buongiorno.
-            {% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %}
-              Buonpomeriggio.
-            {% elif now().strftime('%H')|int >= 17 and now().strftime('%H')|int < 23 %}
-              Buonasera.
-            {% else %}
-              Buonanotte.
-            {% endif %}
-          {%- endmacro -%}
-          
-          {# Time & Date #}
-          {%- macro time_and_date() -%}
-            {% set hour = now().strftime('%H') %}
-            {% set min = now().strftime('%M') %}
-            {% set day = now().strftime('%d') %}
-            {% set mounth = now().strftime('%B') %}
-            {% set year = now().strftime('%Y') %}
-            Sono le {{ hour }} e {{ min }} del {{ day }} {{ mounth }} {{ year }}
-          {%- endmacro -%}
-          
-          {# Door Status #}
-          {%- macro status_door() -%}
-            {% for entity_id in states.group.doors.attributes.entity_id  %}
-              {% set name = entity_id.split('.')[1]|replace('_', ' ') %}
-              {% if is_state(entity_id, 'off') %}
-                La {{ name }} è chiusa.
-              {% else %}
-                La {{ name }} è aperta.
-              {% endif %}
-            {%- endfor %}
-          {%- endmacro -%}
-          
-          {# Lights Status #}
-          {%- macro status_lights() -%}
-            {% for entity_id in states.group.lights.attributes.entity_id  %}
-              {% set name = entity_id.split('.')[1]|replace('_', ' ') %}
-              {% if is_state(entity_id, 'off') %}
-                La {{ name }} è spenta.
-              {% else %}
-                La {{ name }} è accesa.
-              {% endif %}
-            {%- endfor %}
-          {%- endmacro -%}
-          
-          {# Covers Status #}
-          {%- macro status_covers() -%}
-            {% for entity_id in states.group.covers.attributes.entity_id %}
-              {% set name = entity_id.split('.')[1]|replace('_', ' ') %}
-              {% set perc = state_attr(entity_id, 'current_position') %}
-              {% if perc | int < 25 %}
-                La {{ name }} è chiusa.
-              {% else %}
-                La {{ name }} è aperta al {{ perc }} percento.
-              {% endif %}
-            {%- endfor %}
-          {%- endmacro -%}
-          
-          {# Consumption Status #}
-          {%- macro status_consumption() -%}
-          "Il consumo istantaneo è pari a {{ states.sensor.potenza_istantanea.state }} watt"
-          {%- endmacro -%}
-          
-          {# Car Status #}
-          {%- macro status_car() -%}
-            {% if is_state('device_tracker.wdd1760081v167576', state_attr('zone.home', 'friendly_name')) %}
-              {% set car_position = "in garage" %}
-            {% else %}
-              {% set car_position = "fuori" %}
-            {% endif %}
-            {% if is_state('binary_sensor.ff590mr_locked', 'off') %}
-              {% set car_lock = "chiusa" %}
-            {% else %}
-              {% set car_lock = "aperta" %}
-            {% endif %}
-            {% if is_state('binary_sensor.ff590mr_windows_closed_2', 'off') %}
-              {% set car_windows = "chiusi" %}
-            {% else %}
-              {% set car_windows = "aperti" %}
-            {% endif %}
-            La Mercedes si trova {{ car_position }}. è {{ car_lock }} con i finestrini {{ car_windows }}.
-            Il livello del carburante è {{ states('sensor.ff590mr_fuel_level') }} percento.
-            {% if is_state('binary_sensor.ff590mr_warning_brakefluid', 'on') or
-                  is_state('binary_sensor.ff590mr_warning_coolantlevellow', 'on') or
-                  is_state('binary_sensor.ff590mr_warning_washwater', 'on') %}
-              Sono inoltre presenti allarmi.
-            {% endif %}
-          {%- endmacro -%}
-          
-          {# Location Status #}
-          {%- macro status_location(start, num) -%}
-            {% for entity_id in states.group.people.attributes.entity_id %}
-              {% set name = state_attr(entity_id, 'friendly_name') %}
-              {% if is_state(entity_id, 'not_home') %}
-                {% set position = state_attr(entity_id, 'address') %}
-              {% else %}
-                {% set position = states(entity_id) %}
-              {% endif %}
-              
-              {% if (loop.index >= start|int) and (loop.index < num|int+start|int) %}
-                La posizione di {{ name }} è {{ position }}.
-              {% endif %}              
-            {%- endfor %}
-          {%- endmacro -%}
-          
-          {# End Message #}
-          {%- macro end_message() -%}
-            {% if enable_status | int == 1 %}
-              {{ [
-              "Spero che il report ti abbia soddisfatto!",
-              "Il report è concluso.",
-              "Alla prossima!",
-              "Buon proseguimento!",
-              "Non ho altro da comunicare."
-              ] | random }}
-            {% endif %}
-          {%- endmacro -%}
-          
-          {# *********************************************** #}
-          {# ******************* Message ******************* #}
-          {# *********************************************** #}
-          
-          {# Greeting Message #}
-          {% if enable_greeting | int == 1 %}
-            {{ greeting() }}
-          {% endif %}
-          
-          {# Home Status #}
-          {% if enable_status | int == 1 %}
-              
-            {{ time_and_date() }}
-            
-            {{ status_door() }}
-            
-            {{ status_lights() }}
-              
-            {{ status_covers() }}
-            
-            {{ status_consumption() }}
-                            
-          {% endif %}
-          
-          {# Location Info #}
-          {% if (enable_status | int == 1) or (enable_location | int == 1) %}
-            {{ status_location(location_people_start, location_people_num) }}
-          {% endif %}
-          
-          {# Car Status #}          
-          {% if (enable_status | int == 1) or (enable_car | int == 1) %}              
-            {{ status_car() }}
-          {% endif %}
-          
-          {# generic message #}
-          {{ message }}
-          
-          {# end message #}
-          {{ end_message() }}
+        message: !include ../templates/speech_message.yaml
 
 ######################################################################
 # Script: Speech Status
diff --git a/templates/speech_message.yaml b/templates/speech_message.yaml
new file mode 100644 (file)
index 0000000..877564a
--- /dev/null
@@ -0,0 +1,190 @@
+######################################################################\r
+# Speech Engine Message\r
+######################################################################\r
+\r
+>-\r
+  {# *********************************************** #}\r
+  {# ***************** Check Input ***************** #}\r
+  {# *********************************************** #}\r
+  {% if enable_greeting is not defined %}\r
+    {% set enable_greeting=0 %}\r
+  {% endif %}\r
+  {% if enable_status is not defined %}\r
+    {% set enable_status=0 %}\r
+  {% endif %}\r
+  {% if enable_location is not defined %}\r
+    {% set enable_location=0 %}\r
+  {% endif %}\r
+  {% if location_people_start is not defined %}\r
+    {% set location_people_start=1 %}\r
+  {% endif %}\r
+  {% if location_people_num is not defined %}\r
+    {% set location_people_num=2 %}\r
+  {% endif %}          \r
+  {% if enable_car is not defined %}\r
+    {% set enable_car=0 %}\r
+  {% endif %}\r
+  \r
+  {# *********************************************** #}\r
+  {# ******************** Macro ******************** #}\r
+  {# *********************************************** #}\r
+  \r
+  {# Greeting Message #}\r
+  {%- macro greeting() -%}\r
+    {% if now().strftime('%H')|int >= 7 and now().strftime('%H')|int < 12 %}\r
+      Buongiorno.\r
+    {% elif now().strftime('%H')|int >= 12 and now().strftime('%H')|int < 17 %}\r
+      Buonpomeriggio.\r
+    {% elif now().strftime('%H')|int >= 17 and now().strftime('%H')|int < 23 %}\r
+      Buonasera.\r
+    {% else %}\r
+      Buonanotte.\r
+    {% endif %}\r
+  {%- endmacro -%}\r
+  \r
+  {# Time & Date #}\r
+  {%- macro time_and_date() -%}\r
+    {% set hour = now().strftime('%H') %}\r
+    {% set min = now().strftime('%M') %}\r
+    {% set day = now().strftime('%d') %}\r
+    {% set mounth = now().strftime('%B') %}\r
+    {% set year = now().strftime('%Y') %}\r
+    Sono le {{ hour }} e {{ min }} del {{ day }} {{ mounth }} {{ year }}\r
+  {%- endmacro -%}\r
+  \r
+  {# Door Status #}\r
+  {%- macro status_door() -%}\r
+    {% for entity_id in states.group.doors.attributes.entity_id  %}\r
+      {% set name = entity_id.split('.')[1]|replace('_', ' ') %}\r
+      {% if is_state(entity_id, 'off') %}\r
+        La {{ name }} è chiusa.\r
+      {% else %}\r
+        La {{ name }} è aperta.\r
+      {% endif %}\r
+    {%- endfor %}\r
+  {%- endmacro -%}\r
+  \r
+  {# Lights Status #}\r
+  {%- macro status_lights() -%}\r
+    {% for entity_id in states.group.lights.attributes.entity_id  %}\r
+      {% set name = entity_id.split('.')[1]|replace('_', ' ') %}\r
+      {% if is_state(entity_id, 'off') %}\r
+        La {{ name }} è spenta.\r
+      {% else %}\r
+        La {{ name }} è accesa.\r
+      {% endif %}\r
+    {%- endfor %}\r
+  {%- endmacro -%}\r
+  \r
+  {# Covers Status #}\r
+  {%- macro status_covers() -%}\r
+    {% for entity_id in states.group.covers.attributes.entity_id %}\r
+      {% set name = entity_id.split('.')[1]|replace('_', ' ') %}\r
+      {% set perc = state_attr(entity_id, 'current_position') %}\r
+      {% if perc | int < 25 %}\r
+        La {{ name }} è chiusa.\r
+      {% else %}\r
+        La {{ name }} è aperta al {{ perc }} percento.\r
+      {% endif %}\r
+    {%- endfor %}\r
+  {%- endmacro -%}\r
+  \r
+  {# Consumption Status #}\r
+  {%- macro status_consumption() -%}\r
+  "Il consumo istantaneo è pari a {{ states.sensor.potenza_istantanea.state }} watt"\r
+  {%- endmacro -%}\r
+  \r
+  {# Car Status #}\r
+  {%- macro status_car() -%}\r
+    {% if is_state('device_tracker.wdd1760081v167576', state_attr('zone.home', 'friendly_name')) %}\r
+      {% set car_position = "in garage" %}\r
+    {% else %}\r
+      {% set car_position = "fuori" %}\r
+    {% endif %}\r
+    {% if is_state('binary_sensor.ff590mr_locked', 'off') %}\r
+      {% set car_lock = "chiusa" %}\r
+    {% else %}\r
+      {% set car_lock = "aperta" %}\r
+    {% endif %}\r
+    {% if is_state('binary_sensor.ff590mr_windows_closed_2', 'off') %}\r
+      {% set car_windows = "chiusi" %}\r
+    {% else %}\r
+      {% set car_windows = "aperti" %}\r
+    {% endif %}\r
+    La Mercedes si trova {{ car_position }}. è {{ car_lock }} con i finestrini {{ car_windows }}.\r
+    Il livello del carburante è {{ states('sensor.ff590mr_fuel_level') }} percento.\r
+    {% if is_state('binary_sensor.ff590mr_warning_brakefluid', 'on') or\r
+          is_state('binary_sensor.ff590mr_warning_coolantlevellow', 'on') or\r
+          is_state('binary_sensor.ff590mr_warning_washwater', 'on') %}\r
+      Sono inoltre presenti allarmi.\r
+    {% endif %}\r
+  {%- endmacro -%}\r
+  \r
+  {# Location Status #}\r
+  {%- macro status_location(start, num) -%}\r
+    {% for entity_id in states.group.people.attributes.entity_id %}\r
+      {% set name = state_attr(entity_id, 'friendly_name') %}\r
+      {% if is_state(entity_id, 'not_home') %}\r
+        {% set position = state_attr(entity_id, 'address') %}\r
+      {% else %}\r
+        {% set position = states(entity_id) %}\r
+      {% endif %}\r
+      \r
+      {% if (loop.index >= start|int) and (loop.index < num|int+start|int) %}\r
+        La posizione di {{ name }} è {{ position }}.\r
+      {% endif %}              \r
+    {%- endfor %}\r
+  {%- endmacro -%}\r
+  \r
+  {# End Message #}\r
+  {%- macro end_message() -%}\r
+    {% if enable_status | int == 1 %}\r
+      {{ [\r
+      "Spero che il report ti abbia soddisfatto!",\r
+      "Il report è concluso.",\r
+      "Alla prossima!",\r
+      "Buon proseguimento!",\r
+      "Non ho altro da comunicare."\r
+      ] | random }}\r
+    {% endif %}\r
+  {%- endmacro -%}\r
+  \r
+  {# *********************************************** #}\r
+  {# ******************* Message ******************* #}\r
+  {# *********************************************** #}\r
+  \r
+  {# Greeting Message #}\r
+  {% if enable_greeting | int == 1 %}\r
+    {{ greeting() }}\r
+  {% endif %}\r
+  \r
+  {# Home Status #}\r
+  {% if enable_status | int == 1 %}\r
+      \r
+    {{ time_and_date() }}\r
+    \r
+    {{ status_door() }}\r
+    \r
+    {{ status_lights() }}\r
+      \r
+    {{ status_covers() }}\r
+    \r
+    {{ status_consumption() }}\r
+                    \r
+  {% endif %}\r
+  \r
+  {# Location Info #}\r
+  {% if (enable_status | int == 1) or (enable_location | int == 1) %}\r
+    {{ status_location(location_people_start, location_people_num) }}\r
+  {% endif %}\r
+  \r
+  {# Car Status #}          \r
+  {% if (enable_status | int == 1) or (enable_car | int == 1) %}              \r
+    {{ status_car() }}\r
+  {% endif %}\r
+  \r
+  {# generic message #}\r
+  {{ message }}\r
+  \r
+  {# end message #}\r
+  {{ end_message() }}\r