Skip to content

Instantly share code, notes, and snippets.

@Geek-MD
Last active February 19, 2025 20:35
Show Gist options
  • Save Geek-MD/2895b410c0315c9de9be232af8ea4f50 to your computer and use it in GitHub Desktop.
Save Geek-MD/2895b410c0315c9de9be232af8ea4f50 to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Unavailable Lights Notificator
blueprint:
name: Unavailable Lights Notificator
description: Notify when a light has been turned off using the switch
domain: automation
author: Edison Montes @_GeekMD_
homeassistant:
min_version: 2024.6.0
input:
delay:
name: Time Delay
description: Minutes awaited by the automation before notifying when a light has been turned off using the switch
default: 10
selector:
number:
min: 0
max: 60
unit_of_measurement: minutes
start_time:
name: Start Time
description: The notification will be executed after this time
default: "08:00:00"
selector:
time:
end_time:
name: End Time
description: The notification will be executed until this time
default: "22:00:00"
selector:
time:
ignored:
name: Ignored Lights
description: Lights that should be ignored
selector:
entity:
domain: light
multiple: true
excluded:
name: Ignore Individual Entities within a Group
description: Ignore individual entities when they are part of a group
default: true
selector:
boolean:
actions:
name: Actions
description: Notifications or similar to be run. Remember to include {{ entities }} in the message, which is replaced with the name of lights that were turned off using the switch
selector:
action: {}
variables:
ignored: !input ignored
excluded: !input excluded
all_lights: >
{{ states.light | selectattr("state","eq","unavailable") | map(attribute='entity_id') | list }}
grouped: >
{% if excluded %}
{% set groups = integration_entities('group') %}
{% set grouped_entities = namespace(items=[]) %}
{% for group in groups %}
{% set grouped_entities.items = grouped_entities.items + expand(group) | selectattr('state', 'defined') | map(attribute='entity_id') | list %}
{% endfor %}
{{ grouped_entities.items }}
{% else %}
{{ [] }}
{% endif %}
entities: >
{% set filtered = all_lights | reject('in', ignored) | reject('in', grouped) | list %}
{{ filtered }}
has_unavailable: "{{ entities | count > 0 }}"
trigger:
# 🔹 Se activa cada vez que cambia la lista de luces 'unavailable'
- platform: template
value_template: "{{ states.light | selectattr('state','eq','unavailable') | list | count > 0 }}"
for:
minutes: !input delay
# 🔹 Se activa cuando empieza el horario si hay luces 'unavailable'
- platform: time
at: !input start_time
condition:
- condition: template
value_template: "{{ has_unavailable }}"
- condition: time
after: !input start_time
before: !input end_time
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