Created
November 19, 2025 22:51
-
-
Save blizzrdof77/d518f6c21f5170be7b2f2817b3525b60 to your computer and use it in GitHub Desktop.
Unavailable entity detection & notification
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
| # Forked from https://github.com/gmlupatelli/blueprints_repo/blob/master/unavailable_entities_notification/unavailable_entities_notification.yaml | |
| blueprint: | |
| name: Unavailable entity detection & notification | |
| description: > | |
| Regularly test all entities' status to check for unavailability. | |
| Supports exclusion by entities, devices, areas, and labels for flexible filtering. | |
| domain: automation | |
| source_url: https://github.com/gmlupatelli/blueprints_repo/blob/master/unavailable_entities_notification/unavailable_entities_notification.yaml | |
| # === BLUEPRINT INPUTS === | |
| # Configure when and how to check for unavailable entities | |
| input: | |
| time: | |
| name: Time to test on | |
| description: Test is run at configured time | |
| default: '10:00:00' | |
| selector: | |
| time: {} | |
| # === WEEKDAY SCHEDULE CONFIGURATION === | |
| # Select which days of the week to run the unavailable entity check | |
| monday_enabled: | |
| name: 'Monday' | |
| description: 'Run test on Monday' | |
| default: True | |
| selector: | |
| boolean: | |
| tuesday_enabled: | |
| name: Tuesday | |
| description: 'Run test on Tuesday' | |
| default: True | |
| selector: | |
| boolean: | |
| wednesday_enabled: | |
| name: Wednesday | |
| description: 'Run test on Wednesday' | |
| default: True | |
| selector: | |
| boolean: | |
| thursday_enabled: | |
| name: Thursday | |
| description: 'Run test on Thursday' | |
| default: True | |
| selector: | |
| boolean: | |
| friday_enabled: | |
| name: Friday | |
| description: 'Run test on Friday' | |
| default: True | |
| selector: | |
| boolean: | |
| saturday_enabled: | |
| name: Saturday | |
| description: 'Run test on Saturday' | |
| default: True | |
| selector: | |
| boolean: | |
| sunday_enabled: | |
| name: Sunday | |
| description: 'Run test on Sunday' | |
| default: True | |
| selector: | |
| boolean: | |
| # === EXCLUSION CONFIGURATION === | |
| # Define which entities to exclude from unavailability monitoring | |
| exclude: | |
| name: Excluded Entities | |
| description: Entities (e.g. smartphone) to exclude from detection. Entities, devices, areas, and labels are supported! | |
| default: {} | |
| selector: | |
| target: | |
| # === NOTIFICATION ACTIONS === | |
| # Define what happens when unavailable entities are detected | |
| actions: | |
| name: Actions | |
| description: Notifications or similar to be run. {{entities}} is replaced with a formated list of the names of unavailable entities. {{unformatted_entities}} is also available as an unformatted list for advanced templating. | |
| selector: | |
| action: | |
| # === VARIABLES === | |
| # Store user inputs as variables for easier reference throughout the automation | |
| variables: | |
| # Weekday schedule variables | |
| monday_enabled: !input 'monday_enabled' # Run on Monday? | |
| tuesday_enabled: !input 'tuesday_enabled' # Run on Tuesday? | |
| wednesday_enabled: !input 'wednesday_enabled' # Run on Wednesday? | |
| thursday_enabled: !input 'thursday_enabled' # Run on Thursday? | |
| friday_enabled: !input 'friday_enabled' # Run on Friday? | |
| saturday_enabled: !input 'saturday_enabled' # Run on Saturday? | |
| sunday_enabled: !input 'sunday_enabled' # Run on Sunday? | |
| current_day: '{{ now().weekday() | int }}' # Current day of week (0=Monday, 6=Sunday) | |
| # Entity monitoring configuration | |
| exclude: !input 'exclude' # Exclusion input from blueprint | |
| # === UNAVAILABLE ENTITY DETECTION WITH EXCLUSION LOGIC === | |
| # Build a list of unavailable entities, excluding those specified by the user | |
| # Exclusion supports entities, devices, areas, and labels for maximum flexibility | |
| unformatted_entities: >- | |
| {% set result = namespace(includedEntities=[], excludedEntities = []) %} | |
| {# === ENTITY EXCLUSION === #} | |
| {# Exclude specific entities directly by entity_id #} | |
| {% if exclude.entity_id is defined %} | |
| {% set result.excludedEntities = result.excludedEntities + ([exclude.entity_id] if exclude.entity_id is string else exclude.entity_id) %} | |
| {% endif %} | |
| {# === DEVICE EXCLUSION === #} | |
| {# Exclude all entities belonging to specified devices #} | |
| {% if exclude.device_id is defined %} | |
| {% if exclude.device_id is not list %} | |
| {% set device_id_list = [exclude.device_id] %} | |
| {% else %} | |
| {% set device_id_list = exclude.device_id %} | |
| {% endif %} | |
| {% for device_id in device_id_list %} | |
| {% set result.excludedEntities = result.excludedEntities + device_entities(device_id) %} | |
| {% endfor %} | |
| {% endif %} | |
| {# === LABEL EXCLUSION === #} | |
| {# Exclude entities, areas, and devices associated with specified labels #} | |
| {% if exclude.label_id is defined %} | |
| {% if exclude.label_id is not list %} | |
| {% set label_id_list = [exclude.label_id] %} | |
| {% else %} | |
| {% set label_id_list = exclude.label_id %} | |
| {% endif %} | |
| {% for label_id in label_id_list %} | |
| {% set result.excludedEntities = result.excludedEntities + label_entities(label_id) %} | |
| {% for area in label_areas(label_id) %} | |
| {% set result.excludedEntities = result.excludedEntities + area_entities(area) %} | |
| {% for device in area_devices(area) %} | |
| {% set result.excludedEntities = result.excludedEntities + device_entities(device) %} | |
| {% endfor %} | |
| {% endfor %} | |
| {% for device in label_devices(label_id) %} | |
| {% set result.excludedEntities = result.excludedEntities + device_entities(device) %} | |
| {% endfor %} | |
| {% endfor %} | |
| {% endif %} | |
| {# === AREA EXCLUSION === #} | |
| {# Exclude all entities and devices in specified areas #} | |
| {% if exclude.area_id is defined %} | |
| {% if exclude.area_id is not list %} | |
| {% set area_id_list = [exclude.area_id] %} | |
| {% else %} | |
| {% set area_id_list = exclude.area_id %} | |
| {% endif %} | |
| {% for area_id in area_id_list %} | |
| {% set result.excludedEntities = result.excludedEntities + area_entities(area_id) %} | |
| {% for device in area_devices(area_id) %} | |
| {% set result.excludedEntities = result.excludedEntities + device_entities(device) %} | |
| {% endfor %} | |
| {% endfor %} | |
| {% endif %} | |
| {# === UNAVAILABLE SENSOR DETECTION === #} | |
| {# Find all unavailable sensors, excluding those in exclusion list #} | |
| {% for state in states | selectattr('state', 'eq', 'unavailable') %} | |
| {% if state.state == 'unavailable' and not state.entity_id in result.excludedEntities and (not device_id(state.entity_id) or not device_attr(device_id(state.entity_id), 'disabled_by')) %} | |
| {% set result.includedEntities = result.includedEntities + [state.name] %} | |
| {% endif %} | |
| {% endfor %} | |
| {# Return the list of entities for checking #} | |
| {{ result.includedEntities }} | |
| # Format entities for notification template | |
| entities: >- | |
| {{"- "}}{{unformatted_entities|join('\n- ')}} | |
| # === AUTOMATION TRIGGERS === | |
| # Run at the specified time each day | |
| trigger: | |
| - platform: time | |
| at: !input 'time' | |
| # === AUTOMATION CONDITIONS === | |
| # Only run if it's a selected weekday and there are unavailable entities | |
| condition: | |
| # Check if automation should run on the current weekday | |
| - condition: template | |
| value_template: >- | |
| {{ | |
| (current_day == 0 and monday_enabled) or | |
| (current_day == 1 and tuesday_enabled) or | |
| (current_day == 2 and wednesday_enabled) or | |
| (current_day == 3 and thursday_enabled) or | |
| (current_day == 4 and friday_enabled) or | |
| (current_day == 5 and saturday_enabled) or | |
| (current_day == 6 and sunday_enabled) | |
| }} | |
| # Only proceed if there are actually unavailable entities to report | |
| - condition: template | |
| value_template: >- | |
| {{ unformatted_entities | length > 0 }} | |
| # === AUTOMATION ACTIONS === | |
| # Execute user-defined actions when unavailable entities are detected | |
| action: | |
| - choose: [] | |
| default: !input 'actions' | |
| # === AUTOMATION CONFIGURATION === | |
| # Prevent multiple instances and handle overflow gracefully | |
| mode: single | |
| max_exceeded: silent |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment