Paul's Programming Notes PostsRSSGithub

Home Assistant Leak Notification Automation

The Sonoff SNZB-05P seems like the best Zigbee leak sensor right now. It’s around $20, and its snap-on WLDC200 sensing cable detects water anywhere along the cord, so it isn’t just watching a single spot the water can spread around. I have them in appliance drip pans and under sinks, all feeding one Home Assistant automation that alerts my phone when a sensor trips and sends an all-clear when it dries.

automations.yaml

- id: leak_notifications
  alias: Leak Notifications
  triggers:
  # Wet: the state must hold 15s to filter momentary blips, and not_from
  # stops a sensor coming back from unavailable from re-alerting.
  - trigger: state
    entity_id:
    - binary_sensor.kitchen_sink_leak_sensor
    - binary_sensor.water_heater_leak_sensor
    not_from:
    - unavailable
    - unknown
    to: 'on'
    for:
      seconds: 15
    id: wet
  # Dry: same sensors, opposite transition.
  - trigger: state
    entity_id:
    - binary_sensor.kitchen_sink_leak_sensor
    - binary_sensor.water_heater_leak_sensor
    from: 'on'
    to: 'off'
    id: dry
  actions:
  - if:
    - condition: trigger
      id: wet
    then:
    - action: notify.mobile_app_your_phone
      data:
        title: Leak Detected
        message: 'Device:  has detected water.'
        data:
          # Both branches share a per-sensor tag, so the dry notification
          # overwrites the wet one and your phone shows a single
          # up-to-date entry per sensor instead of a stack.
          tag: leak_
          # Android-specific: alarm_stream plays at alarm volume even
          # during Do Not Disturb (a leak at 3am is worth waking up for),
          # and priority high + ttl 0 deliver it immediately.
          priority: high
          ttl: 0
          channel: alarm_stream
    else:
    # The all-clear is a normal-priority push.
    - action: notify.mobile_app_your_phone
      data:
        title: Leak Dry
        message: 'Device:  is dry.'
        data:
          tag: leak_
  # Parallel so one burst pipe tripping sensors in two rooms alerts for both.
  mode: parallel

To adapt

Swap in your own sensors under both entity_id lists and point the notify actions at your phone’s service. The Android keys are documented in the critical notifications docs and the tag behavior in the basic notification docs. The iOS equivalent of the alarm-stream keys is a critical push:

data:
  push:
    sound:
      name: default
      critical: 1
      volume: 1.0