Had to shelve some of the cool code but this is still an improvement to the speech engine.

This commit is contained in:
ccostan 2018-06-06 19:20:59 -04:00
parent 488309d610
commit 7b387a3516
2 changed files with 20 additions and 19 deletions

View File

@ -75,27 +75,28 @@ speech_engine:
Outside, it is going to be {{ states('sensor.dark_sky_minutely_summary') }} Outside, it is going to be {{ states('sensor.dark_sky_minutely_summary') }}
{%- endmacro -%} {%- 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() -%} {%- macro light_check() -%}
{%- if states.sensor.lights_on.state|length != 0 -%} {% if states.group.all_lights.state != 'off' -%}
{%- set lights_on_count = states.sensor.lights_on.state.split(',')|length -%} There are
{%- set lights_on_friendly = friendly_list(states.sensor.lights_on.state|replace('light.','')|replace('switch.','')|replace('light','')|replace('lamp','')) -%} {% for state in states.light if state.state == 'on' -%}
{%- if lights_on_count == 1 -%} {%- if loop.last -%}
The {{ lights_on_friendly }} light is on. {{ loop.index }}
{%- else -%}
There are {{ lights_on_count }} lights on right now.
The {{ lights_on_friendly }} lights are on.
{%- endif -%} {%- 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 -%} {%- endif -%}
{%- endmacro -%} {%- endmacro -%}