Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@bbbenji
Last active March 14, 2024 00:14
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 24 You must be signed in to fork a gist
  • Save bbbenji/d4d1fe1856ec54370a422508c8963f2a to your computer and use it in GitHub Desktop.
Save bbbenji/d4d1fe1856ec54370a422508c8963f2a to your computer and use it in GitHub Desktop.
blueprint:
name: Leak detection & notifier
description: Send a notification when any configured moisture sensor becomes moist
domain: automation
input:
notify_device:
name: Notify device
description: "The device where the notification should be sent to."
selector:
device:
integration: mobile_app
trigger:
- event_data: {}
event_type: state_changed
platform: event
condition:
- condition: template
value_template: '{{ trigger.event.data.new_state.attributes.device_class == "moisture" }}'
- condition: template
value_template: '{{ trigger.event.data.new_state.state == "on" }}'
action:
domain: mobile_app
type: notify
device_id: !input notify_device
message: "{{ trigger.event.data.new_state.attributes.friendly_name }} has detected a leak."
title: "Leak detected!"
mode: single
@bbbenji
Copy link
Author

bbbenji commented Jul 7, 2021

Thanks for the typo fix @the1snm!

As for the !input error you’re are getting, I have no idea why… It’s a valid tag and required for it to be configurable. See: Blueprint tutorial - Home Assistant 10

@djbr22
Copy link

djbr22 commented Aug 24, 2021

Just wanted to say thanks for the great blueprint! It works perfectly on all my water sensors. I also included a link to it at the bottom of guide here as a way to say thanks. :) I just refreshed the cache on the page so hopefully it shows up for you. https://smarthomepursuits.com/add-a-blinking-leak-sensor-card-to-home-assistant/

@Ljiddou
Copy link

Ljiddou commented Dec 23, 2021

Thanks for the blueprint and its working perfectly. I'm trying to add critical push alert for IOS but its not working. I'm adding it at the end of the blueprint but no luck. This is what I have:

action:
domain: mobile_app
type: notify
device_id: !input notify_device
message: "{{ trigger.event.data.new_state.attributes.friendly_name }} has detected a leak."
title: "Leak detected!"
push:
sound:
name: "default"
critical: 1
volume: 1.0
Sorry I'm all new to home assistant and still learning.

@SergeantPup
Copy link

Hello, I just came here to say thank you and that it works perfectly. I was sweating the conversion from hubitat with 30 leak sensors because they have an easy tool that does this. It indicates the sensor name in the notification which was crucial. This was the first leak solution I found and actually the first blueprint I used and it was an easy/awesome experience.

I'm just saying this to josh ya, but did you have to use the word moist? lol "Send a notification when any configured moisture sensor becomes moist"
Again, thank you for the excellent leak aggregator.

@TurtleFX
Copy link

Thanks for the blueprint!
I've forked it and modified, to make customizable actions. If someone interested, its here.

@jaspov
Copy link

jaspov commented Dec 8, 2022

I installed this a long time ago, works great.
However noticed an error in my logs:
Also unsure if I automatically get updates to a blueprint AFTER an automation has been made?

Template variable error: 'None' has no attribute 'attributes' when rendering '{{ trigger.event.data.new_state.attributes.device_class == "moisture" }}'
09:57:21 – (ERROR) helpers/template.py

@Mike144007
Copy link

Is it possible to have the alert sent to more than one device - and a combination of iphones and alexas ?
I have tried to adapt in the yaml file, but when I test, no notifications are sent. I have checked the notification group I have set up, and this appears to work.
My config is as follows (not sure whether formatting works here):

blueprint:
  name: Leak detection & notifier
  description: Send a notification when any configured moisture sensor becomes moist
  domain: automation
  input:
    notify_device:
      name: Notify device
      description: The device where the notification should be sent to.
      selector:
        device:
          integration: mobile_app
          multiple: false
  source_url: https://gist.github.com/bbbenji/d4d1fe1856ec54370a422508c8963f2a
trigger:
- event_data: {}
  event_type: state_changed
  platform: event
condition:
- condition: template
  value_template: '{{ trigger.event.data.new_state.attributes.device_class == "moisture"
    }}'
- condition: template
  value_template: '{{ trigger.event.data.new_state.state == "on" }}'
action:
  - service: notify.mobiles_plus_alexas
    message: >-
      {{ trigger.event.data.new_state.attributes.friendly_name }} has detected a leak.
    title: Leak detected!
mode: single

@morikplay
Copy link

life (and money) saver! Just trying to understand class hierarchy via haas documentation was rough. I do have a question. @bbbenji's code would trigger at every event to match against the AND conditions listed under condition. I'm rather unfamiliar with the trigger framework (reading up on it) but would it be possible to only trigger when device_class == "moisture" and then apply condition of new_state.state == "on"?
Thank you for this effort!

@stellarhopper
Copy link

Very new to blueprints, I love this - but I want to be able to exclude a few leak sensors that I want to use for a different purpose. Any pointers on how I'd go about adding an exclude list? I see how to declare them here: https://gist.github.com/sbyx/1f6f434f0903b872b84c4302637d0890 but not sure how I'd eventually use that list.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment