How to say in message which windows are open?

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:

'1536739215145':
  alias: Check if windows are open while leaving
  sequence:
  - 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 %}
{{entities}}

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?

Yep:

{{ 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!

Hie Tom

I have a light group named “group.allhouse” and a switch group named group.allhouse_switch. I have made an automation for HA to warn me if any switch or light is open. I have tried your code with changes but it gives error. Where am I wrong ?

service: notify.telegrambot
data:
  title: Open Lights
  message: Bugün {{ states|selectattr('entity_id', 'in', state_attr('group.allhouse ', 'entity_id'))|selectattr('state', 'equalto', 'on')|map(attribute='name')|join(', ')}}

That is a two year old post and no longer the best way to do this now that we have expand().

See:

Also it helps if you show the error you received.