How to say in message which windows are open?

Tags: #<Tag:0x00007fc3d18c9dc0>

Hello! I am a little bit struggling with script which would check if any window is open and if it is - send me a message with friendly name of the entity (or names if there are several open windows)

So, here is the basic part of the script:

  alias: Check if windows are open while leaving
  - condition: state
    entity_id: binary_sensor.door_window_sensor_158d0002bfc936
    state: 'off'

And now I need to check my group.all_windows and find out which ones are open

May I get help on that?

Have a look at the “Useful Templates, Template to get a list of entities” here:

Cool, I got it working with all devices, but I only need 5 which are in group. Here is what I tried and did not succeed:

{% set domain = 'group.all_real_lights' %}
{% set entities = states[domain] | map(attribute='entity_id') | list %}

I am just getting error in template editor

And even with list of needed entities I don’t really know how to get states of them and include in message only opened ones

Try this in the template editor:

{{ states|selectattr('entity_id', 'in', state_attr('group.all_windows ', 'entity_id'))|selectattr('state', 'equalto', 'on')|map(attribute='entity_id')|join(', ')}}

It should list all windows in the group all_windows that are open.

Ok, that worked, thanks. And is there a way to get friendly names of that entities, not entity_id?


{{ states|selectattr('entity_id', 'in', state_attr('group.all_windows ', 'entity_id'))|selectattr('state', 'equalto', 'on')|map(attribute='name')|join(', ')}}

Oh, that looks so obvious now. Thank you!