Last active
December 7, 2021 15:47
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on the very useful https://gist.github.com/sbyx/1f6f434f0903b872b84c4302637d0890