alias: Trigger Switch Notification
sequence:
- alias: Iterate through switch notifications
repeat:
count: "{{ device_ids | count }}"
sequence:
- variables:
device_id: "{{ device_ids[repeat.index - 1] }}"
- event: LOGBOOK_ENTRY
event_data:
type: issue_all_led_effect
domain: zha
device_id: "{{device_id}}"
effect_type: Pulse
color: 80
level: 100
duration: 3
- type: issue_all_led_effect
domain: zha
device_id: "{{device_id}}"
effect_type: Pulse
color: 80
level: 100
duration: 3
variables:
device_ids: |-
{% set result = namespace(ids=[]) %} {% for state in states.light %}
{% if device_attr(state.entity_id, 'model') == 'VZM31-SN' %}
{% set result.ids = result.ids + [device_id(state.entity_id)] %}
{% endif %}
{% endfor %} {{result.ids}}
mode: single
icon: mdi:bell
I have been attempting to write a script that issues a command to all switches with the same model number so I can cause their led bar to light up. I can confirm the device_ids
variable is being populated correctly. I can also confirm that the repeat block is going through all of the ids. I can see this through the logbook event when viewing the traces after the script is run. However, my attempts to template the device_id
for the led action do not appear to be working. If I hard code the id to one of the switches it does work as expected. So the sequence does appear to be correct and the issue seems to be related to the template variable. I have read through the documentation on templating and scripting, although there is something I am clearly missing since this isn’t working
If anyone can point me in the right direction I would greatly appreciate it. Also if this is covered in documentation I missed please let me know and I’ll go ahead and read it. I tried to read all of the documentation related to templating and scripting but may have missed something. Thank you!