#Condition if any open/close sensor is open

1 messages · Page 1 of 1 (latest)

kind belfry
#

I have a set of window/door sensors all with the same label. I'd like to make a condition in my automation if one or more sensors are reporting "open" state, without having to constantly update the automation if I add new sensors, beyond just adding the label to the sensor. Is there an easy way to set up that condition?
Similarly, for my notification, I'd like to generate a list of open sensor names, so I can send me a notification of any doors/windows left open. (the idea is I press the away button to turn everything off and lock doors, but would be nice if I also get warned if I left anything open as I leave)

ornate salmon
#

Use a helper. Settings -> Devices & services -> Helpers. Create a group.

kind belfry
#

But now I have to also maintain a group in addition to maintaining labels. Toying with just creating a variable that concatenates all open sensors with a specific label, but can't quite get it working yet

kind belfry
#

Here's what I ended up with. Much cleaner than having to maintain both labels and groups:
variables:

    {% set label = 'open_close_sensor' %} {% set list = namespace(devices=[]) %}
    {% for entity in label_entities(label) %}         
      {% if is_state(entity, 'on') %}
        {% set list.devices = list.devices + [device_name(entity).replace(' Sensor','')] %}
      {% endif %}  
    {% endfor %} {{ list.devices }}```
steel oar