Skip to content

Instantly share code, notes, and snippets.

@Geek-MD
Last active May 25, 2025 23:21
Show Gist options
  • Save Geek-MD/bfe782e055772ac08e8204220c48cbc9 to your computer and use it in GitHub Desktop.
Save Geek-MD/bfe782e055772ac08e8204220c48cbc9 to your computer and use it in GitHub Desktop.
blueprint:
name: Unavailable Device Notificator
description: Execute actions when any non-light device becomes unavailable, with time restrictions and optional first change ignore.
domain: automation
author: Edison Montes @_GeekMD_
homeassistant:
min_version: 2024.6.0
input:
start_time:
name: Start Time
description: The start time when notifications are allowed.
default: "08:00:00"
selector:
time:
end_time:
name: End Time
description: The end time when notifications are allowed.
default: "22:00:00"
selector:
time:
ignore_first_change:
name: Ignore First Change
description: Ignore the first unavailable event after Home Assistant restart or automation reload.
default: true
selector:
boolean:
actions:
name: Actions
description: Actions to perform when a device becomes unavailable. You can use {{ message }} or {{ entities }}.
selector:
action:
variables:
entity_id: "{{ trigger.event.data.entity_id }}"
domain: "{{ entity_id.split('.')[0] }}"
old_state: "{{ trigger.event.data.old_state }}"
new_state: "{{ trigger.event.data.new_state }}"
friendly_name: >
{% set name = state_attr(entity_id, 'friendly_name') %}
{{ name if name else entity_id }}
entities: "{{ [friendly_name] }}"
count: "{{ entities | count }}"
plural: "{{ 'device' if count == 1 else 'devices' }}"
message: >
The following {{ plural }} became unavailable:
{{ entities | join(', ') }}
trigger:
- platform: event
event_type: state_changed
condition:
- condition: template
value_template: "{{ new_state is not none and new_state.state == 'unavailable' }}"
- condition: template
value_template: "{{ domain != 'light' }}"
- condition: time
after: !input start_time
before: !input end_time
- condition: template
value_template: >
{% set ignore = (new_state is not none and new_state.state == 'unavailable' and (now() - as_datetime(new_state.last_changed)).total_seconds() < 30) %}
{{ (not ignore) or (not (inputs.ignore_first_change | default(true))) }}
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