Skip to content

Instantly share code, notes, and snippets.

@TheQue42
Last active December 7, 2021 15:47
Show Gist options
  • Save TheQue42/4ab6f46bbda899d9f0b81efd2bfff28a to your computer and use it in GitHub Desktop.
Save TheQue42/4ab6f46bbda899d9f0b81efd2bfff28a to your computer and use it in GitHub Desktop.
Home assistant blueprint for detecting sensors of type "problem" with an error state, such as firealarm sensors, overheat sensors on sockets etc
blueprint:
name: System wide problem detector for Iot sensors of device class "problem"
description: Regularly test all sensors with device-class 'problem' to detect if anyone indicates an error.
domain: automation
input:
repetition:
name: How often to run
description: Test is run at this intervall, in minutes. You MUST use the slash notation; 0-59 minutes.
default: '/45'
selector:
text:
multiline: false
exclude:
name: Excluded Sensors
description: >
There are some weird sensors out there, we might want to ignore.
Only entities are supported, devices must be expanded
default: {entity_id: []}
selector:
target:
entity:
device_class: problem
debug_mode:
name: Debug Mode
description: Make blueprint list entities that are "off", instead of "on".
default: false
selector:
boolean:
entity_only:
name: Entities only
description: >
The 'sensors' list will only contain entity_id's instead of a combined string of name and id.
default: false
selector:
boolean:
actions:
name: Actions
description: 'Notifications or similar to be run. {{sensors}} is replaced with the names[] of devices indicating a problem.'
selector:
action: {}
variables:
exclude: !input 'exclude'
debug: !input 'debug_mode'
entity_id_only: !input 'entity_only'
sensors: >-
{%- set result_on = namespace(sensors=[]) -%}
{%- set result_off = namespace(sensors=[]) -%}
{%- for state in states.binary_sensor | selectattr('attributes.device_class', '==', 'problem') %}
{%- if state.state == true and not state.entity_id in exclude.entity_id -%}
{%- if not entity_id_only -%}
{% set result_on.sensors = result_on.sensors + [state.name ~ ' (id: ' ~ state.entity_id ~ ' )'] %}
{%- else -%}
{% set result_on.sensors = result_on.sensors + [state.entity_id] %}
{%- endif -%}
{%- elif not state.entity_id in exclude.entity_id -%}
{%- if not entity_id_only -%}
{% set result_off.sensors = result_off.sensors + [state.name ~ ' (id: ' ~ state.entity_id ~ ' )'] %}
{%- else -%}
{% set result_off.sensors = result_off.sensors + [state.entity_id] %}
{%- endif -%}
{%- endif -%}
{%- endfor -%}
{%- if not debug -%}
{{result_on.sensors}}
{%- else -%}
{{result_off.sensors}}
{%- endif -%}
trigger:
- platform: time_pattern
minutes: !input 'repetition'
condition:
- '{{ sensors|length != 0 }}'
action:
- choose: []
default: !input 'actions'
mode: single
@TheQue42
Copy link
Author

TheQue42 commented Dec 7, 2021

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