]> git.giorgioravera.it Git - homeassistant.git/commitdiff
Review speech engine
authorGiorgio Ravera <giorgio.ravera@gmail.com>
Thu, 13 Jun 2019 09:31:27 +0000 (11:31 +0200)
committerGiorgio Ravera <giorgio.ravera@gmail.com>
Thu, 13 Jun 2019 09:31:27 +0000 (11:31 +0200)
group/people.yaml
script/speech_engine.yaml

index a44d29ba03e828c3d55cfc4a66082bc2f279cda3..cb115c894d0770149c2bb9f1c8adc87e14853cd3 100644 (file)
@@ -7,8 +7,13 @@ people:
   view: true
   icon: mdi:account-multiple
   entities:
+    # Giorgio
     - device_tracker.google_maps_115265981849847357125
+    # Laura
     - device_tracker.google_maps_103158638433668748797
+    # Anna
     - device_tracker.google_maps_113099283296073047871
-#    - device_tracker.wdd1760081v167576
-#    - device_tracker.google_maps_108517379615429477419
+    # Assunta
+    - device_tracker.google_maps_108517379615429477419
+    # Mercedes
+    - device_tracker.wdd1760081v167576
index e8b971727e398e56af31ef48c3382dd1c410bcbb..1acb5c2c636a46f771db6fc00d4ad708acc1688c 100644 (file)
-######################################################################\r
-# Script: Speech Engine\r
-# Inputs:\r
-# - media_player\r
-# - volume_level\r
-# - message\r
-# - enable_greeting\r
-# - enable_status\r
-#\r
-# Operations:\r
-# - script.notify_voice (greeting + message)\r
-######################################################################\r
-\r
-speech_engine:\r
-  alias: Speech Engine\r
-  sequence: \r
-    - service: script.notify_voice\r
-      data_template:\r
-        media_player: "{{ media_player }}"\r
-        volume_level: "{{ volume_level }}"\r
-        language: "{{ language }}"\r
-        message: >-        \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
-          {# 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
-          {# Car Status #}\r
-          {%- macro status_car() -%}\r
-            {% if is_state('device_tracker.wdd1760081v167576', 'Casa') %}\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
-            {% if is_state('binary_sensor.ff590mr_park_brake_status', 'on') %}\r
-              {% set car_parkbreak = "inserito" %}\r
-            {% else %}\r
-              {% set car_parkbreak = "non inserito" %}\r
-            {% endif %}\r
-            La Mercedes si trova {{ car_position }}. è {{ car_lock }}, con i finestrini {{ car_windows }} e il freno a mano {{ car_parkbreak }}.\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() -%}\r
-            {% if is_state('device_tracker.google_maps_115265981849847357125', 'not_home') %}\r
-              {% set giorgio_position = 'fuori casa' %}\r
-            {% else %}\r
-              {% set giorgio_position = states('device_tracker.google_maps_115265981849847357125') %}\r
-            {% endif %}\r
-            La posizione di Giorgio è {{ giorgio_position }}.\r
-            {% if is_state('device_tracker.google_maps_103158638433668748797', 'not_home') %}\r
-              {% set laura_position = 'fuori casa' %}\r
-            {% else %}\r
-              {% set laura_position = states('device_tracker.google_maps_103158638433668748797') %}\r
-            {% endif %}\r
-            La posizione di Laura è {{ laura_position }}.\r
-          {%- endmacro -%}\r
-          \r
-          {# End Message #}\r
-          {%- macro end_message() -%}\r
-            {% if enable_status is defined %}\r
-              {% if enable_status | int == 1 %}\r
-                {{ [\r
-                "Spero che il report ti abbia soddisfatto!",\r
-                "Il report è concluso.",\r
-                "Alla prossima!",\r
-                "Non ho altro da comunicare."\r
-                ] | random }}\r
-              {% endif %}\r
-            {% endif %}\r
-          {%- endmacro -%}\r
-          \r
-          {# *********************************************** #}\r
-          {# ******************* Message ******************* #}\r
-          {# *********************************************** #}\r
-          \r
-          {# Greeting Message #}\r
-          {% if enable_greeting is defined %}\r
-            {% if enable_greeting | int == 1 %}\r
-              {{ greeting() }}\r
-            {% endif %}\r
-          {% endif %}\r
-          \r
-          {% if enable_status is defined %}\r
-            {% if enable_status | int == 1 %}\r
-              \r
-              {{ time_and_date() }}\r
-              \r
-              {{ status_lights() }}\r
-              \r
-              {{ status_covers() }}\r
-              \r
-              {{ status_location() }}\r
-              \r
-              {{ status_car() }}\r
-              \r
-            {% endif %}\r
-          {% endif %}\r
-          \r
-          {# generic message #}\r
-          {{ message }}\r
-          \r
-          {# end message #}\r
-          {{ end_message() }}\r
-\r
-######################################################################\r
-# Script: Speech Status\r
-#\r
-# Operations:\r
-# - script.speech_engine\r
-######################################################################\r
-\r
-speech_status:\r
-  alias: Stato Casa\r
-  sequence: \r
-    - service: script.speech_engine\r
-      data:\r
-        enable_greeting: 1\r
-        enable_status: 1\r
+######################################################################
+# Script: Speech Engine
+# Inputs:
+# - media_player
+# - volume_level
+# - message
+# - enable_greeting
+# - enable_status
+# - enable_location
+# - location_people_start
+# - location_people_num
+# - enable_car
+#
+# Operations:
+# - script.notify_voice (greeting + message)
+######################################################################
+
+speech_engine:
+  alias: Speech Engine
+  sequence: 
+    - service: script.notify_voice
+      data_template:
+        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 -%}
+            
+          {# 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 -%}
+          
+          {# Car Status #}
+          {%- macro status_car() -%}
+            {% if is_state('device_tracker.wdd1760081v167576', 'Casa') %}
+              {% 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 %}
+            {% if is_state('binary_sensor.ff590mr_park_brake_status', 'on') %}
+              {% set car_parkbreak = "inserito" %}
+            {% else %}
+              {% set car_parkbreak = "non inserito" %}
+            {% endif %}
+            La Mercedes si trova {{ car_position }}. è {{ car_lock }}, con i finestrini {{ car_windows }} e il freno a mano {{ car_parkbreak }}.
+            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_lights() }}
+              
+            {{ status_covers() }}
+                            
+          {% 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() }}
+
+######################################################################
+# Script: Speech Status
+#
+# Operations:
+# - script.speech_engine
+######################################################################
+
+speech_status:
+  alias: Stato Casa
+  sequence: 
+    - service: script.speech_engine
+      data:
+        enable_greeting: 1
+        enable_status: 1