Created
August 11, 2023 15:31
-
-
Save emanuelpsilva/97c4d2283c6b78ea59794bd7f7bfa827 to your computer and use it in GitHub Desktop.
No interaction detection with battery powered devices & notification
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
# Original reference: https://gist.github.com/sbyx/1f6f434f0903b872b84c4302637d0890 | |
blueprint: | |
name: No interaction detection with battery powered devices & notification | |
description: Battery powered devices are prone to go from 50% battery to no communications without warning (i.e. deffective batteries) This blueprint find devices in your HASS installation were the last interaction is older than a defined threshold | |
domain: automation | |
input: | |
threshold: | |
name: Time since the last interaction | |
description: Amount of time since the last interaction with the device (in seconds) | |
default: 86400 | |
selector: | |
number: | |
min: 3600.0 | |
max: 2592000.0 | |
mode: box | |
step: 3600.0 | |
time: | |
name: Time to run the report | |
description: Report will be sent at this time | |
default: '09:00:00' | |
selector: | |
time: {} | |
day: | |
name: Weekday to send the report | |
description: User can select a specific weekday for the report (defaults to everyday) | |
default: 0 | |
selector: | |
number: | |
min: 0.0 | |
max: 7.0 | |
mode: slider | |
step: 1.0 | |
exclude: | |
name: Excluded devices | |
description: Unwated battery powered devices in the report (i.e. smartphone) | |
default: {entity_id: []} | |
selector: | |
target: | |
entity: | |
device_class: battery | |
actions: | |
name: Actions | |
description: Way to send the report (i.e. notification). Tag {{devices}} represents the list | |
selector: | |
action: {} | |
variables: | |
day: !input 'day' | |
threshold: !input 'threshold' | |
exclude: !input 'exclude' | |
device_list: > | |
{% set result = namespace(devices=[]) %} | |
{% for device in states.sensor |rejectattr('attributes.device_class', 'undefined') | selectattr('attributes.device_class', '==', 'battery') %} | |
{% set age = (as_timestamp(now()) - as_timestamp(device.last_updated)) | int %} | |
{% if not (device.state == 'unavailable') and age > threshold %} | |
{% set result.devices = result.devices + [device.name ~ ' (' ~ (age / 3600) | int ~ 'h)'] %} | |
{% endif %} | |
{% endfor %} | |
{{result.devices|join(', ')}} | |
{% set result = namespace(devices=[]) %} | |
trigger: | |
- platform: time | |
at: !input 'time' | |
condition: | |
- '{{ device_list != '''' and (day | int == 0 or day | int == now().isoweekday()) }}' | |
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