Skip to content

Instantly share code, notes, and snippets.

@fabiosoft
Created February 10, 2022 00:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiosoft/728a4494db805cd2c28cbb3d461e8c45 to your computer and use it in GitHub Desktop.
Save fabiosoft/728a4494db805cd2c28cbb3d461e8c45 to your computer and use it in GitHub Desktop.
blueprint:
name: Detect water and notify
description: detect 'moisture' device-class and if so execute an action.
domain: automation
input:
actions:
name: Actions
description: Notifications or similar to be run. {{sensors}} is replaced with the names of sensors.
selector:
action: {}
variables:
sensors: >-
{% set result = namespace(sensors=[]) %}
{% for state in states.sensor | selectattr('attributes.device_class', '==', 'moisture') %}
{% set result.sensors = result.sensors + [state.name ~ ' (' ~ state.state ~ ' %)'] %}
{% endfor %}
{% for state in states.binary_sensor | selectattr('attributes.device_class', '==', 'moisture') | selectattr('state', '==', 'on') %}
{% set result.sensors = result.sensors + [state.name] %}
{% endfor %}
{{result.sensors|join(', ')}}
trigger:
- type: moist
platform: device
action:
- choose: []
default: !input 'actions'
mode: single
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment