Notification for sensor group

I have the following automation, which works mostly… problem is, in the notification, I get notified about devices outside of the group as well if they are “open”… is there a way to restrict the notification list to ONLY the devices in my entity_id group? I don’t want just the device that first triggered this… I’d like to get a list of all devices in the group that were open when the automation triggered.

- alias: a_turn_off_thermostat_with_open_contacts
  platform: state
  entity_id: group.outside_contact_windows_doors
  to: 'open'
    minutes: 3
  - service: homeassistant.turn_on
    entity_id: input_boolean.nest_climate_contact_switch
  - service: climate.set_operation_mode
    entity_id: climate.entryway
      operation_mode: 'off'
  - data:
      message: >
        Thermostat turned off because contacts left open.
        Time: {{now().strftime("%a, %d %b %Y %H:%M:%S")}}
        {% for state in states -%}
          {% if state.state == 'open'%}
            {{ }} is open!
          {%- endif -%}
        {% endfor %}
    service: notify.sms

I’m not sure how this works at all. What is domain “all_contacts”?

In any case, you can change the for-loop to:

        {% for state in states|selectattr('entity_id','in',
             |selectattr('state','eq','open') -%}
          {{ }} is open!
        {% endfor %}

But are you sure that the state of these entities is actually ‘open’? Usually the actual state of binary entities is ‘on’, even if they are displayed as ‘open’.

Sorry, that was a bit confusing… I was in the middle of modifying the code to attempt to get it to do what I wanted… so I ended up leaving one of my attempts in there… which was the “states.all_contacts” part… I edited it to reflect what the actual working version is…

Thanks for this! I will give it a shot when I get a minute.

I still don’t have a clear idea of how a lot of these attributes, domains, and states are accessed… I haven’t found any easy to read documentation on the matter, but maybe I am just looking in the wrong place?

Lastly, yes, these are contact sensors, not binary sensors… so they use “open” and “closed” rather than “on” and “off” as the binary ones do.

Have you read these developer docs? Or maybe are you looking for this templating documentation?

You mean in the sensor domain? (I.e., their entity_id’s begin with sensor?) If so, maybe they should be binary sensors. If they only have two values, that’s the point of binary_sensors. Then you can use an appropriate device class. See binary device classes. Just a thought.