Skip to content

Instantly share code, notes, and snippets.

@bbbenji
Last active December 7, 2025 15:49
Show Gist options
  • Select an option

  • Save bbbenji/d4d1fe1856ec54370a422508c8963f2a to your computer and use it in GitHub Desktop.

Select an option

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
@jaspov
Copy link

jaspov commented Dec 7, 2025

Getting an error recently: Template variable error: 'None' has no attribute 'attributes'
when rendering '{{ trigger.event.data.new_state.attributes.device_class == "moisture" }}'

chatgpt tells me:
The error 'None' has no attribute 'attributes' happens when trigger.event.data.new_state is None. This can happen if a sensor is deleted, unavailable, or for some reason the event doesn’t include a new_state.

In Home Assistant, a safe way to handle this is to check that new_state exists before accessing its attributes. You can change your condition to:

and proposes this fix

- condition: template value_template: > {% if trigger.event.data.new_state %} {{ trigger.event.data.new_state.attributes.device_class == 'moisture' }} {% else %} false {% endif %}

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