From: Giorgio Ravera Date: Thu, 13 Jun 2019 09:31:27 +0000 (+0200) Subject: Review speech engine X-Git-Url: http://git.giorgioravera.it/?a=commitdiff_plain;h=6e16a89afdc155622d4d9136c33778e8d4900159;p=homeassistant.git Review speech engine --- diff --git a/group/people.yaml b/group/people.yaml index a44d29ba..cb115c89 100644 --- a/group/people.yaml +++ b/group/people.yaml @@ -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 diff --git a/script/speech_engine.yaml b/script/speech_engine.yaml index e8b97172..1acb5c2c 100644 --- a/script/speech_engine.yaml +++ b/script/speech_engine.yaml @@ -1,182 +1,211 @@ -###################################################################### -# Script: Speech Engine -# Inputs: -# - media_player -# - volume_level -# - message -# - enable_greeting -# - enable_status -# -# 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: >- - {# *********************************************** #} - {# ******************** 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() -%} - {% if is_state('device_tracker.google_maps_115265981849847357125', 'not_home') %} - {% set giorgio_position = 'fuori casa' %} - {% else %} - {% set giorgio_position = states('device_tracker.google_maps_115265981849847357125') %} - {% endif %} - La posizione di Giorgio è {{ giorgio_position }}. - {% if is_state('device_tracker.google_maps_103158638433668748797', 'not_home') %} - {% set laura_position = 'fuori casa' %} - {% else %} - {% set laura_position = states('device_tracker.google_maps_103158638433668748797') %} - {% endif %} - La posizione di Laura è {{ laura_position }}. - {%- endmacro -%} - - {# End Message #} - {%- macro end_message() -%} - {% if enable_status is defined %} - {% if enable_status | int == 1 %} - {{ [ - "Spero che il report ti abbia soddisfatto!", - "Il report è concluso.", - "Alla prossima!", - "Non ho altro da comunicare." - ] | random }} - {% endif %} - {% endif %} - {%- endmacro -%} - - {# *********************************************** #} - {# ******************* Message ******************* #} - {# *********************************************** #} - - {# Greeting Message #} - {% if enable_greeting is defined %} - {% if enable_greeting | int == 1 %} - {{ greeting() }} - {% endif %} - {% endif %} - - {% if enable_status is defined %} - {% if enable_status | int == 1 %} - - {{ time_and_date() }} - - {{ status_lights() }} - - {{ status_covers() }} - - {{ status_location() }} - - {{ status_car() }} - - {% endif %} - {% 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 +###################################################################### +# 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