Skip to content

Instantly share code, notes, and snippets.

@TheQue42
Last active December 11, 2021 12:05
Show Gist options
  • Save TheQue42/7e1a39faffa593a10b6c808bebcdd3de to your computer and use it in GitHub Desktop.
Save TheQue42/7e1a39faffa593a10b6c808bebcdd3de to your computer and use it in GitHub Desktop.
Home assistant blueprint for detecting over_load and over_heat sensors that are NOT defined with a device_class "problem"
blueprint:
name: System wide problem detector for Iot sensors with entity_id matching '_over'.
description: Regularly test all overload and overheat sensors, NOT classified as device_class=problem
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:
domain: binary_sensor
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 and state.entity_id is search("_over") -%}
{%- 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 and state.entity_id is search("_over")-%}
{%- 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