From e1a628ad6974f6d04a0bbbae34af3b7965cb6551 Mon Sep 17 00:00:00 2001 From: Giorgio Ravera Date: Sun, 21 Apr 2019 12:00:14 +0200 Subject: [PATCH] Added lights to speech and fix minor changes --- automation/speech.yaml | 6 ++--- script/speech_engine.yaml | 47 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/automation/speech.yaml b/automation/speech.yaml index 28e487b0..829f5187 100644 --- a/automation/speech.yaml +++ b/automation/speech.yaml @@ -83,7 +83,7 @@ "Sento un interferenza nella Forza! " ~ name + " è qui", "Menomale che sei qui " ~ name + "! Mi sentivo solo", "Menomale che sei qui " ~ name + "! La casa è vuota senza di te!", - "Ciao " ~ name + "! Casa è sempre la casa!", + "Ciao " ~ name + "! Casa è sempre la casa!" ] | random }} {%- endmacro -%} {{ greeting_sentence(name) }} @@ -113,5 +113,5 @@ - service: script.speech_engine data_template: message: >- - {% set ora = now().strftime('%H') %} - "Sono le {{ ora }} e tutto va bene." + {% set hour = now().strftime('%H') %} + "Sono le {{ hour }} e tutto va bene." diff --git a/script/speech_engine.yaml b/script/speech_engine.yaml index 903b5fba..6b1328aa 100644 --- a/script/speech_engine.yaml +++ b/script/speech_engine.yaml @@ -36,12 +36,34 @@ speech_engine: 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 = states(entity_id) %} + {% set perc = state_attr(entity_id, 'current_position') %} {% if perc | int < 25 %} La {{ name }} è chiusa. {% else %} @@ -97,6 +119,20 @@ speech_engine: 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 ******************* #} {# *********************************************** #} @@ -110,18 +146,25 @@ speech_engine: {% 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 -- 2.47.3