|
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 names of the lights that were turned off using the switch |
|
selector: |
|
action: {} |
|
|
|
variables: |
|
ignored: !input ignored |
|
excluded: !input excluded |
|
|
|
# ๐น All unavailable lights |
|
all_unavailable_lights: > |
|
{{ states.light | selectattr('state','eq','unavailable') | list }} |
|
|
|
# ๐น All unavailable groups |
|
all_unavailable_groups: > |
|
{{ states.group |
|
| selectattr('state','eq','unavailable') |
|
| selectattr('attributes.entity_id', 'defined') |
|
| list }} |
|
|
|
# ๐น Groups that contain unavailable lights |
|
groups_with_unavailable_lights: > |
|
{% set unavailable_light_ids = all_unavailable_lights | map(attribute='entity_id') | list %} |
|
{% set matched_groups = namespace(groups=[]) %} |
|
{% for group in all_unavailable_groups %} |
|
{% set group_lights = group.attributes.entity_id %} |
|
{% if group_lights | select('in', unavailable_light_ids) | list | count > 0 %} |
|
{% set matched_groups.groups = matched_groups.groups + [ group ] %} |
|
{% endif %} |
|
{% endfor %} |
|
{{ matched_groups.groups }} |
|
|
|
# ๐น Entities to Notify: group names + standalone lights |
|
entities: > |
|
{% set notified_light_ids = groups_with_unavailable_lights | map(attribute='attributes.entity_id') | sum(start=[]) %} |
|
{% set notified_light_ids = notified_light_ids | unique %} |
|
{% set standalone_lights = all_unavailable_lights | rejectattr('entity_id', 'in', notified_light_ids) | list %} |
|
{% set group_names = groups_with_unavailable_lights | map(attribute='attributes.friendly_name') | list %} |
|
{% set light_names = standalone_lights | map(attribute='attributes.friendly_name') | list %} |
|
{{ (group_names + light_names) | sort }} |
|
|
|
has_unavailable: "{{ entities | count > 0 }}" |
|
|
|
trigger: |
|
# ๐น Detecta cambios en luces unavailable |
|
- platform: template |
|
value_template: "{{ states.light | selectattr('state', 'eq', 'unavailable') | list | count > 0 }}" |
|
for: |
|
minutes: !input delay |
|
|
|
# ๐น Se dispara al inicio del horario |
|
- 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 |