#Trigger on any state change of any sensor that starts with 'binary_sensor.water_leak_sensor'

1 messages · Page 1 of 1 (latest)

soft fern
#

I have 10 water leak sensor around my home and I want to be notified if any of the sensors status change from Dry to wet. I'd rather not create 10 seperate automation if I can do just one with a catchall. All of the sensors start with 'binary_sensor.water_leak_sensor' and then the location (ex. 'binary_sensor.water_leak_sensor_guest_bathroom, or 'binary_sensor.water_leak_sensor_sump_pump. How can I get the sensors into a group I guess.

I asked chatGPT and I got This error Message malformed: Entity {{ leak_sensor }} is neither a valid entity ID nor a valid UUID for dictionary value

lost ibex
#

Create a binary sensor group and alert on it

#

You find the groups under the helpers

soft fern
#

hmm ok let me research that. good suggestion

grizzled wind
#

If you don’t plan to add/remove/change your leak sensors, you can just create a group once manually and be done with it.

I mess around with my setup fairly often (adding and removing sensors) so I created a script that generates a leak sensor group based on the entity names. I created an automation to run the script every time HA starts up. And then of course I have an automation to alert me when the group state changes from off to on.

#
alias: Leak Sensor Group Creation
sequence:
  - data_template:
      object_id: leak_sensors
      entities: >
        {{ (states.binary_sensor |
        selectattr('entity_id','search','_leak$|_leak_detected')) |
        map(attribute='entity_id') | join(', ') }}
    action: group.set
mode: restart
icon: mdi:water-alert
grizzled wind
#

You could use this for a template:

{{ (states.binary_sensor |
        selectattr('entity_id','search','^binary_sensor.water_leak_sensor')) |
        map(attribute='entity_id') | join(', ') }}