I want to setup automation so that when my Water Leak Sensor group detects a leak that it can actually tell which water leak sensor in the group is activated in the message output of the notification?
What have you tried?
tried?? nothing, im not sure what to even type in HA community to find what I’m looking for. its a template I’m guessing but templating is still a struggle for me… any tips on what to search for??
automation:
- alias: 'Water Leak Notification'
trigger:
platform: state
entity_id: group.binary_sensor.total_water_leak_group
to: 'on'
action:
service: notify.notify
data_template:
message: 'The {{ trigger.to_state.name }} sensor is on.'
I doubt your group is called “group.binary_sensor.total_water_leak_group” because that’s not a valid entity_id. You need to get that sorted out first.
I took the liberty of guessing what the correct group id should be in the below code. If I was wrong then substitute the correct id.
so that said, try this:
action:
service: notify.notify
data:
message: >
'{% set sensors_on = expand('group.total_water_leak_group') | selectattr('state', 'eq', 'on') | map(attribute='attributes.friendly_name') | join(',') %}
{% if expand('group.total_water_leak_group') | selectattr('state', 'eq', 'on') | list | count > 1 %}
"The {{ sensors_on |replace(',' , " and ") }} sensors are on.
{% else %}
"The {{ sensors_on }} is on.
{% endif %}
Thanks works a treat!!
1 Like