Hi Petro
There is the possibility instead of the number to show the name of the opened window?
Thank You
Hi Petro
There is the possibility instead of the number to show the name of the opened window?
Thank You
I’m using the following template in order to get notified over TTS when I’m leaving:
{% set windowEntities = state_attr('group.windows', 'entity_id') %}
{% set openWindows = states.binary_sensor
| selectattr('entity_id', 'in', windowEntities)
| selectattr('state','eq','on')
| map(attribute='name')
| list %}
{% if openWindows | length == 0 %}
{% set windowMessage = '' %}
{% elif openWindows | length == 1 %}
{% set windowMessage = 'The following window is open: ' + openWindows[0] + '.' %}
{% else %}
{% set windowMessage = 'The following windows are open: ' + openWindows | join(', ') + '.' %}
{% endif %}
{{ windowMessage }}
If you are interested, here is a streamlined version of your template:
{% set openWindows = expand('group.windows')
| selectattr('state','eq','on')
| map(attribute='name')
| list %}
{% set qty = openWindows | length %}
{% set p1 = ' is ' if qty == 1 else 's are ' %}
{{ '' if qty == 0 else 'The following window{}open: {}.'.format(p1, openWindows | join(', ')) }}
Thank you guys!!
remove the entity_id field and the list of entities. entity_id is no longer valid.
what does the error message say?
Sadly I can not tell you that. The ad works in lovelace. Only comes this message
So you can’t tell me what this error message says yet you can read my replies:
Continue your journey by learning to use the „code“ button (</>) of this editor when posting configuration files or log outputs.
Bitte.
ok Thank You
I´m sorry to pull out a 2 year old thread but as I´m currently optmizing my dashboard i found this gem of a template
Now I´m still a noob in templating and need help. Where do I put the “if/else” if I want basically that the template is showing me the amount of opened windows and if all are closed just a “all closed”?
Thanks for your help
{% set number_open = (expand('group.windows') | selectattr('state', 'eq', 'on') | list | count) %}
{% if number_open > 0 %}
{{number_open}}
{% else %}
"all closed"
{% endif %}
You Sir are a legend! Thanks a lot!
This is working perfectly fine for me although I need to do some adjustments and I can’t figure out how to do it.
All my room sensors are called for example “Aqara Sensor Kitchen Contact”, “Aqara Sensor Bathroom Contact”, and so on.
How can I remove the first and last part of the string so that the correct output will be “The following window’s are open: Kitchen, Bathroom”
Use python’s ability to slice a string in order to slice off the ‘Aqara Sensor’ and ‘Contact’ portions.
Or use the split
function to convert the string to a list (using a space character to serve as the delimiter) and then display the list’s third item (list index is 2).
Thanks for pointing me into the right direction.
I played around with split
but couldn’t make it work in this specific code.
replace
did the trick for me. Here is my adjusted code for anyone who is struggling like me.
{% if is_state('binary_sensor.alle_fenster', 'on') %}
{% set openWindows = expand('binary_sensor.alle_fenster')
| selectattr('state','eq','on')
| map(attribute='name')
| list %}
{% set qty = openWindows | length %}
{% set p1 = 'Das' if qty == 1 else 'Die' %}
{% set p2 = 'ist' if qty == 1 else 'sind' %}
{{ '' if qty == 0 else '{} folgende Fenster {} geöffnet:{}.'.format(p1, p2, openWindows | join(',') | replace('Aqara Fenstersensor', '') | replace(' contact', '') | replace('ue', 'ü')) }}
{% else %}
{% endif %}
Another way to do the same thing:
{% if is_state('binary_sensor.alle_fenster', 'on') %}
{% set openWindows = expand('binary_sensor.alle_fenster')
| selectattr('state','eq','on')
| map(attribute='name')
| map('regex_replace', '(Aqara Fenstersensor | contact)', '')
| map('replace', 'ue', 'ü') | list %}
{% set qty = openWindows | length %}
{{ '{} folgende Fenster {} geöffnet:{}.'.format(iif(qty == 1, 'Das', 'Die'), iif(qty == 1, 'ist', 'sind'), openWindows | join(',')) }}
{% else %} {{ '' }}
{% endif %}