Persistent alarming, alerting for leak sensor

I’d like to share a solution that I came up with for an automation. I was looking for a straight forward method to trigger an alarm and continuously play a TTS message on my Echo Pop whenever a water leak sensor was wet. I wanted the automation to continue until I cleared the wet state of the sensor. I wanted one automation that would work for multiple sensors, in different areas and I wanted the Echo to announce which area the leak was detected. I found multiple ways online to accomplish this i.e. the Alert integration, but I’m new to HA and to writing automations and I wasn’t comfortable using that method because it required editing the configuration.yaml file. What I came up with meets all my needs and was easy for me to configure using the UI. I’m sharing it in case someone else is looking for a similar solution.

The automation is triggered by one of four different sensors (I’m using Sonoff leak sensors) placed in different areas. If any one of them detects water a siren sounds. I’m just using a Reolink camera that I have that has a siren function but if anyone knows of a good zigbee or zwave siren/alarm please suggest it. I’m then using the choose to determine which sensor triggered by using the trigger ID. Each option then plays a TTS message (different message for each area) waits 7 seconds and then repeats. It will repeat the message until the sensor is dry. Once dry the automation continues down through and turns off the siren.

I’m not sure if there is another way to share the automation other than just pasting the yaml here. If there’s a better way please let me know. I’m sure there is probably a more elegant way to solve this problem but this method was in my wheelhouse and it works. I’m trying to learn so I’m open to better methods if you want to share.

alias: Leak Detectors
description: ""
triggers:
  - type: moist
    device_id: 1eae889d136536088eb9151084d40ce8
    entity_id: cd4b083c39dd8d204abfad18b11ca6a9
    domain: binary_sensor
    trigger: device
    id: utility tub
  - type: moist
    device_id: 78512da1c640ffc8251469f0ebdd5307
    entity_id: fb4dd2364ff3fc53d118f4ecf1d9c8b4
    domain: binary_sensor
    trigger: device
    id: water heater
  - type: moist
    device_id: 358543251a7f86521099ddd4d3fa1100
    entity_id: e4eb6e5f0bfe488363be5a97a51bee89
    domain: binary_sensor
    trigger: device
    id: laundry room
  - type: moist
    device_id: 5e58a748c3389ffbd88d5f5ed46ae2c7
    entity_id: dc67baffdc56d536a927025eacdec100
    domain: binary_sensor
    trigger: device
    id: kitchen sink
conditions: []
actions:
  - action: siren.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: siren.reolink_1_siren
    enabled: true
  - choose:
      - conditions:
          - condition: trigger
            id:
              - utility tub
        sequence:
          - repeat:
              until:
                - type: is_not_moist
                  condition: device
                  device_id: 1eae889d136536088eb9151084d40ce8
                  entity_id: cd4b083c39dd8d204abfad18b11ca6a9
                  domain: binary_sensor
              sequence:
                - action: notify.alexa_media_echo_pop
                  metadata: {}
                  data:
                    message: leak detected, utility tub area
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 7
                    milliseconds: 0
      - conditions:
          - condition: trigger
            id:
              - water heater
        sequence:
          - repeat:
              until:
                - type: is_not_moist
                  condition: device
                  device_id: 78512da1c640ffc8251469f0ebdd5307
                  entity_id: fb4dd2364ff3fc53d118f4ecf1d9c8b4
                  domain: binary_sensor
              sequence:
                - action: notify.alexa_media_echo_pop
                  metadata: {}
                  data:
                    message: leak detected, water heater area
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 7
                    milliseconds: 0
      - conditions:
          - condition: trigger
            id:
              - laundry room
        sequence:
          - repeat:
              until:
                - type: is_not_moist
                  condition: device
                  device_id: 358543251a7f86521099ddd4d3fa1100
                  entity_id: e4eb6e5f0bfe488363be5a97a51bee89
                  domain: binary_sensor
              sequence:
                - action: notify.alexa_media_echo_pop
                  metadata: {}
                  data:
                    message: leak detected, laundry room
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 7
                    milliseconds: 0
      - conditions:
          - condition: trigger
            id:
              - kitchen sink
        sequence:
          - repeat:
              until:
                - type: is_not_moist
                  condition: device
                  device_id: 5e58a748c3389ffbd88d5f5ed46ae2c7
                  entity_id: dc67baffdc56d536a927025eacdec100
                  domain: binary_sensor
              sequence:
                - action: notify.alexa_media_echo_pop
                  metadata: {}
                  data:
                    message: leak detected, kitchen sink area
                - delay:
                    hours: 0
                    minutes: 0
                    seconds: 7
                    milliseconds: 0
  - action: siren.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: siren.reolink_1_siren
mode: single

Good job!

Do you know about the built-in alert integration?

Some recommendations for you:

  1. Rather use state triggers and conditions, instead of the device ones. It’s more robust should you need to replace devices and makes a for a cleaner config.
  2. Use timers if you want this to be robust against an HA restart. Your automation would start a timer instead (one for each device). When it lapses, notify and restart the timer (another automation). A third automation would stop the timer once the issue is resolved.
  3. Your automation runs in single mode, so if you have the scenario where two sensors are triggered, this won’t work as expected. I would set it to parallel.
1 Like

Thanks for the suggestions. I do know about the Alert integration but as I said I was a little uncomfortable using it because it isn’t totally clear to me how. I will look into it further though.

With the suggestion to use state triggers, would I put multiple entities in the one trigger? Is that the reason it is better?

I’ll check out the use of timers. It sounds like this would require multiple automations?

Thanks again for the suggestions. There are so many ways to skin a cat with automations. I’m just scratching the surface. I wish someone would create a cookbook. I’d pay for that.

The main reason is to avoid device IDs, but you can definitely put it all under one trigger as a list of entities. It’s equivalent to separate triggers.

Yes, that is the tradeoff for the additional robustness. Timers can be restored after a restart.

Oh, I just remembered this one too: Alert2 - a new alerting component.