Help with automation for multiple water sensors

Need some help with how to write the automation script to notify me when the battery is out. I’m ordering a couple more of the Mi water sensor and would like to figure out how to deal with the automation script and learn!

This is what I have now for 1 sensor and I know I can repeat this process for each new one. Ideally would like to have this to work with multiple entities and if at all possible based on which entity is reporting the ‘unavailable’ status, return a different message.

  • alias: Kitchen leak sensor
    trigger:
    platform: state
    entity_id: binary_sensor.water_leak_sensor_158d0001d72c2c
    to: ‘unavailable’
    action:
    • service: notify.eddie
      data:
      message: “Kitchen leak sensor out of power”

Thanks
Eddie

Hi Eddie !! We all love to learn :slight_smile:
You can add extra sensors to the trigger by adding them to the entity_id with a comma between them

entity_id: binary_sensor.water_leak_sensor_158d0001d72c2c, binary_sensor.water_leak_sensor_xxx, binary_sensor.xxx

To get the name automatically in your message, you will need to change ‘data’ to ‘data_template’ and then put a template in you message

- service: notify.eddie
  data_template:
    message: '{{ trigger.to_state.attributes.friendly_name }} leak sensor out of power'
1 Like

Thanks for the help!

To clarify on the data_template, if the sensor reports a “wet” state for the friendly_name “Bathroom” sensor, I would make the message look like this:

message: ‘{{ trigger.to_state.wet.Bathroom }} leak sensor out of power’

Is that correct?

Thanks

message: '{{ trigger.to_state.attributes.friendly_name }} leak sensor out of power'

is all you will need ! :grinning:
In this template, you are asking HA to insert the freindly name of whatever triggered the automation.

Say that the automaton was triggered by sensor.water_leak_sensor_1, and that sensors friendly name was ‘bathroom leak sensor’ the sent message would read “bathroom leak sensor leak sensor out of power”.

We can fix that to read a little better with some more code, but to start, put the above template into your automation and see what message you get back.

I just got the rest of the sensors and tried the data_template, and it’s working great! Thank you very much!

1 Like