From 7b387a35167d7b1815465b2e235499767768c50b Mon Sep 17 00:00:00 2001 From: ccostan Date: Wed, 6 Jun 2018 19:20:59 -0400 Subject: [PATCH] Had to shelve some of the cool code but this is still an improvement to the speech engine. --- ...ml => speech_helper_sensors.yaml.disabled} | 0 config/script/speech_engine.yaml | 39 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) rename config/packages/{speech_helper_sensors.yaml => speech_helper_sensors.yaml.disabled} (100%) diff --git a/config/packages/speech_helper_sensors.yaml b/config/packages/speech_helper_sensors.yaml.disabled similarity index 100% rename from config/packages/speech_helper_sensors.yaml rename to config/packages/speech_helper_sensors.yaml.disabled diff --git a/config/script/speech_engine.yaml b/config/script/speech_engine.yaml index 85da7506..cb25b00b 100755 --- a/config/script/speech_engine.yaml +++ b/config/script/speech_engine.yaml @@ -75,27 +75,28 @@ speech_engine: Outside, it is going to be {{ states('sensor.dark_sky_minutely_summary') }} {%- endmacro -%} - {%- macro friendly_list(list) -%} - {%- set temp = list|replace('_',' ')|replace(' ,',',')|replace(',',', ')|trim|title -%} - {%- if list.split(',')|length > 1 -%} - {%- set temp = temp+'^' -%} - {%- set lastitem = temp.split(',')|last -%} - {{ temp|replace(lastitem, ' and' + lastitem)|replace('^','') }} - {%- else -%} - {{ temp }} - {%- endif -%} - {%- endmacro -%} - {%- macro light_check() -%} - {%- if states.sensor.lights_on.state|length != 0 -%} - {%- set lights_on_count = states.sensor.lights_on.state.split(',')|length -%} - {%- set lights_on_friendly = friendly_list(states.sensor.lights_on.state|replace('light.','')|replace('switch.','')|replace('light','')|replace('lamp','')) -%} - {%- if lights_on_count == 1 -%} - The {{ lights_on_friendly }} light is on. - {%- else -%} - There are {{ lights_on_count }} lights on right now. - The {{ lights_on_friendly }} lights are on. + {% if states.group.all_lights.state != 'off' -%} + There are + {% for state in states.light if state.state == 'on' -%} + {%- if loop.last -%} + {{ loop.index }} {%- endif -%} + {%- endfor %} + lights on right now. + {% set comma = joiner(', ') %} + The + {% for group in states.group|groupby('state') -%} + {%- for entity in group.list if entity.state == 'on' + and entity.name.split(' ')[1]|lower == 'lights' + and entity.name.split(' ')[0]|lower != 'all' + and entity.name.split(' ')[0]|lower != 'interior' + -%} + {{ 'and' if loop.last and not loop.first else comma() }} + {{ entity.name|replace('Lights','')}} + {%- endfor -%} + {%- endfor -%} + lights are on. {%- endif -%} {%- endmacro -%}