Forked from Tahutipai/report_zigbee_zwave_devices_gone_offline.yaml
Last active
May 15, 2025 20:17
-
-
Save Ltek/0c9cecf632b9c32915130680d834bcf7 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Offline Devices Report
This file contains hidden or 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: Offline Devices Report by LTek | |
description: > | |
Outputs list of Offline Devices | |
- Format options: Friendly Name, Entity ID, Friendly Name (Entity ID) | |
- Notification options for Persistent UI and Mobile | |
- Exclude entities : specific and/or by string (text) | |
Author: LTek | |
Version: 2025.05.10.16b (syntax fixes and code optimizations) | |
special thanks to Petro for the help! | |
source_url: https://gist.github.com/Ltek/0c9cecf632b9c32915130680d834bcf7 | |
domain: automation | |
input: | |
time: | |
name: Time of Day | |
description: Run at this time of the day | |
default: '6:00:00' | |
selector: | |
time: {} | |
day: | |
name: Week Day to Run Report | |
description: '0 = Daily ... 1 = Monday to 7 = Sunday' | |
default: 0 | |
selector: | |
number: | |
min: 0 | |
max: 7 | |
mode: slider | |
step: 1 | |
exclude_entities: | |
name: Exclude Individual Entities (optional) | |
description: Select specific entities to exclude from the list (one per line, e.g. "switch.phone_battery") | |
default: [] | |
selector: | |
entity: | |
multiple: true | |
domain: | |
- sensor | |
- binary_sensor | |
- switch | |
exclude_strings: | |
name: Exclude entities with this Text (optional) | |
description: Excludes the Entity from the list if text appears anywhere in the Entity ID (one per line, e.g. "battery" will exclude ALL entities with that text anywhere) | |
default: "" | |
selector: | |
text: | |
multiline: true | |
format_option: | |
name: Display Format | |
description: Choose how to display entities in the report | |
default: friendly_name | |
selector: | |
select: | |
options: | |
- label: "Friendly Names" | |
value: friendly_name | |
- label: "Entity IDs" | |
value: entity_id | |
- label: "Friendly Names (Entity IDs)" | |
value: combined | |
enable_mobile_notifications: | |
name: Enable Mobile Notifications | |
description: Send notifications to your mobile device | |
default: true | |
selector: | |
boolean: {} | |
mobile_notification_services: | |
name: Mobile Notification Services | |
description: Services to use for mobile notifications (e.g., notify.mobile_app_mydevice), one per line | |
default: notify.mobile_app_EditMe | |
selector: | |
text: | |
multiline: true | |
enable_persistent_notifications: | |
name: Enable Persistent Notifications in the UI | |
description: Show persistent notifications in Home Assistant UI | |
default: true | |
selector: | |
boolean: {} | |
actions: | |
name: Additional Actions | |
description: Additional actions to run when offline devices are detected | |
default: [] | |
selector: | |
action: {} | |
variables: | |
day: !input day | |
exclude_entities: !input exclude_entities | |
exclude_strings: !input exclude_strings | |
format_option: !input format_option | |
enable_mobile_notifications: !input enable_mobile_notifications | |
mobile_notification_services: !input mobile_notification_services | |
enable_persistent_notifications: !input enable_persistent_notifications | |
_offline_devices: > | |
{% set exclude_entities = exclude_entities if exclude_entities is iterable else [exclude_entities] %} | |
{% set exclude_regex = exclude_strings.split('\n') | map('trim') | reject('eq', '') | list | join('|') if exclude_strings is defined and exclude_strings else 'abcdefghijklmnopqrstuvwxyz' %} | |
{% set entities = states | map(attribute='entity_id') | reject('search', 'cloud') | reject('in', exclude_entities) | reject('search', exclude_regex) | list %} | |
{% set sensors = entities | select('search', '^(sensor|binary_sensor)') | list %} | |
{% set battery_entities = sensors | select('is_state_attr', 'device_class', 'battery') | reject('has_value') | list %} | |
{% set switches = entities | select('search', '^switch') | reject('has_value') | list %} | |
{% set offline_entities = (battery_entities + switches) | unique %} | |
{% if format_option == 'friendly_name' %} | |
{{ offline_entities | map('state_attr', 'friendly_name') | list }} | |
{% elif format_option == 'entity_id' %} | |
{{ offline_entities | list }} | |
{% elif format_option == 'combined' %} | |
[ | |
{%- for e in offline_entities %} | |
'{{ state_attr(e, "friendly_name") }} ({{ e }})'{% if not loop.last %},{% endif %} | |
{%- endfor %} | |
] | |
{% else %} | |
['Wrong Input'] | |
{% endif %} | |
offline_devices: > | |
{% if _offline_devices | length > 0 %} | |
{{ _offline_devices | map('string') | list | sort | join('\n- ') }} | |
{% else %} | |
No offline devices detected. | |
{% endif %} | |
offline_devices_count: > | |
{{ _offline_devices | length }} | |
trigger: | |
- platform: time | |
at: !input time | |
condition: | |
- condition: template | |
value_template: "{{ offline_devices != 'No offline devices detected.' and (day == 0 or day == now().isoweekday()) }}" | |
action: | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ enable_persistent_notifications }}" | |
sequence: | |
- service: persistent_notification.create | |
data: | |
title: "Offline Devices Report" | |
message: > | |
{{ offline_devices_count }} Total: | |
- | |
{{ offline_devices }} | |
default: [] | |
- choose: | |
- conditions: | |
- condition: template | |
value_template: "{{ enable_mobile_notifications }}" | |
sequence: | |
- repeat: | |
for_each: > | |
{% set services = mobile_notification_services.split('\n') | map('trim') | reject('eq', '') | list %} | |
{{ services }} | |
sequence: | |
- service: "{{ repeat.item }}" | |
data: | |
title: "Offline Devices Report" | |
message: > | |
{{ offline_devices_count }} Total: | |
- | |
{{ offline_devices }} | |
data: | |
tag: offline_devices_report | |
default: [] | |
- alias: "Run additional actions" | |
sequence: !input actions | |
mode: single |
FYI, I tried using Copilot and ChatGPT one Sunday afternoon for hours and although both platforms reckoned they found out why labels weren't working, 12 iterations later, nothing worked. Now I'm a hardware guy and know diddly about code but this is working to reject labels in one of my mushroom cards. Is that remotely relevant?
secondary: |-
{{ states.light
| rejectattr('entity_id', 'in', label_entities('Group'))
| rejectattr('entity_id', 'in', label_entities('Dummylight'))
| selectattr('state', 'eq', 'on')
| list
| count }}
You can try it. Give the AI the base code and tell it to use the
rejectattr function when updating the code to exclude labels. See what
happens.
…On Mon, Mar 17, 2025, 2:23 AM xbmcnut ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
FYI, I tried using Copilot and ChatGPT one Sunday afternoon for hours and
although both platforms reckoned they found out why labels weren't working,
12 iterations later, nothing worked. Now I'm a hardware guy and know diddly
about code but this is working to reject labels in one of my mushroom
cards. Is that remotely relevant?
secondary: |-
{{ states.light
| rejectattr('entity_id', 'in', label_entities('Group'))
| rejectattr('entity_id', 'in', label_entities('Dummylight'))
| selectattr('state', 'eq', 'on')
| list
| count }}
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/Ltek/0c9cecf632b9c32915130680d834bcf7#gistcomment-5498206>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAMNFMQRWARHMS54BAMFWWD2U2BATBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTGNRYGI4DANJZU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I fixed what existed: specifying individual entities. I have not been able to get labels to work.