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)
#Condition if any open/close sensor is open
1 messages · Page 1 of 1 (latest)
Use a helper. Settings -> Devices & services -> Helpers. Create a group.
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
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 }}```
No need for a for-loop:
{{
label_entities('open_close _sensor')
| select('is_state', 'on')
| map('device_name')
| map('replace', ' Sensor', '')
| list
}}