Amateur radio and embedded systems

Water leak app notification in Home Assistant

Home Assistant is an extremely flexible home automation solution that does not come in a magic locked-down box. The flexibility comes with difficulty figuring out how to actually do things because of so many options and different approaches (just like with Linux overall).

I installed some Zigbee water leak sensors and needed a simple feature - notify me via the app when there is a leak. A quick Google search returned lots of results, forum posts, blueprints and no obvious solution so I decided to "click around" and find out how it can be done.

Setting up Home Assistant, TLS certificates, port forwarding and the mobile app is out of the scope of this post. I will only focus on the notification aspect. I bought Aqara water leak sensors (also known as Xiaomi SJCGQ11LM) and added them to Zigbee2MQTT. They were automatically detected by Home Assistant.

Setting up the notifications

  1. Go to Settings
  2. Select Automation and scenes
  3. Select Automations at the top
  4. Press CREATE AUTOMATION (bottom right blue button)
  5. Pick Start with an empty automation (don't use blueprints)
  6. Press ADD TRIGGER (button at the top)
  7. Select Device
  8. Find the name of you leak sensor (you assign it for example in Zigbee2MQTT during joining)
  9. The trigger field should automatically populate with name of your sensor and "becomes moist"
  10. Repeat ADD TRIGGER for all your sensors (you can always add or remove them later), all triggers are logically ORed
  11. Press ADD ACTION (button at the bottom)
  12. Pick Call service
  13. Press the three dots on the right next to the "Call service" row and select Edit in YAML
  14. Paste
service: notify.notify
  title: Water leak detected
  message: Water leak in {{ trigger.to_state.name }}

Finally, press SAVE (bottom right blue button) and put in the name (eg. "Leak start notification").

Done. You can also create an almost identical automation to notify when the sensors become dry. I was very positively surprised by the responsivness. The notifications are nearly instant, just 2-3 seconds after dipping a sensor in the water. They look just like every other iOS notifications. It may also make sense to add the leak sensors to a dashboard to view their state.

This is how the automation should look: Screenshot1