Last active
February 14, 2025 19:37
-
-
Save Geek-MD/67b32e59eebca724d2d9c85bb5464484 to your computer and use it in GitHub Desktop.
This file contains 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: "New Device Notificator" | |
description: "Executes custom actions when new devices are discovered. If detection occurs outside the scheduled time, actions run at the next start time. Includes a list of discovered devices." | |
domain: automation | |
author: "Edison Montes @_GeekMD_" | |
input: | |
start_time: | |
name: Start Time | |
description: Time from which the automation will be active. | |
default: "08:00:00" | |
selector: | |
time: {} | |
end_time: | |
name: End Time | |
description: Time until which the automation will be active. | |
default: "22:00:00" | |
selector: | |
time: {} | |
actions: | |
name: Actions to Execute | |
description: Actions to perform when new devices are detected. Use `{{ new_devices }}` to list them. | |
selector: | |
action: {} | |
variables: | |
# Capture new device names from the event | |
new_devices: >- | |
{% if trigger.event and trigger.event.event_type == 'device_registry_updated' and trigger.event.data.action == 'create' %} | |
{% set device_id = trigger.event.data.device_id %} | |
{% set device = states.device_tracker | selectattr('attributes.device_id', 'eq', device_id) | first %} | |
{% if device %} | |
[{{ device.attributes.friendly_name | default('Unnamed Device') }}] | |
{% else %} | |
['Unnamed Device'] | |
{% endif %} | |
{% else %} | |
[] | |
{% endif %} | |
mode: single | |
trigger: | |
# Trigger when a new device is detected | |
- platform: event | |
event_type: device_registry_updated | |
event_data: | |
action: create | |
id: new_device_detected | |
# Trigger at the start of the defined schedule | |
- platform: time | |
at: !input start_time | |
id: start_time_trigger | |
condition: | |
- condition: or | |
conditions: | |
# Condition 1: Execute if detected within the schedule | |
- condition: and | |
conditions: | |
- condition: trigger | |
id: new_device_detected | |
- condition: time | |
after: !input start_time | |
before: !input end_time | |
# Condition 2: Execute at start time if detected outside hours | |
- condition: and | |
conditions: | |
- condition: trigger | |
id: start_time_trigger | |
- condition: template | |
value_template: > | |
{% set last_run = state_attr(this.entity_id, 'last_triggered') %} | |
{{ last_run is not none and | |
(now() - last_run).total_seconds() < 86400 }} | |
action: | |
- choose: [] | |
default: !input actions | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment