Device_id as variable in script?

I have the following script:

alias: Inovelli - Clear LEDs
variables:
  switch: 0e8b546b7257587a218f63ad4547d13a
sequence:
  - type: issue_all_led_effect
    domain: zha
    device_id: "{{switch}}"
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 0
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 1
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 2
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 3
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 4
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 5
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
  - type: issue_individual_led_effect
    domain: zha
    device_id: "{{switch}}"
    led_number: 6
    effect_type: Clear
    color: 0
    level: 100
    duration: 255
mode: single
icon: mdi:led-outline

But it throws the following error:

Message malformed: Unknown device '{{switch}}'

As far as I can see based on the docs, this is the correct syntax… is device_id not able to take a variable?

Maybe try to put quotes for the variable like:

variables:
  switch: "0e8b546b7257587a218f63ad4547d13a"

Device actions do not support templating. Use the light turn on service call if you want to use templates.

You should avoid device automations altogether.

1 Like

Gotcha. How disappointing. Is this documented anywhere? Also- how would I use ‘light turn on’ service in this case? The individual LEDs are not entities.

Which integration are you using to connect to the LEDs?

I’m using the ZHA Integration.

I think you are out of luck then.

Boooooo. Thanks!

Hi @kylepyke, did you find an alternate solution for this problem? I am hoping to do the same thing. I was unable to figure out how to use a “call service” action to invoke this command. (Posted the same question in this related thread as well)

It sounds like zha-toolkit might offer some solutions to problems like this, but it seems to bring some additional complexity I would like to avoid if possible.

Would the zigbee2mqtt integration make this eaiser? I am open to switching since my system is not very large yet.

Just ran into the same thing. @jtbandes , did you ever find an easy way? I think this is the straw that breaks the yaml’s back and pushes me to pyscript.

1 Like

I ended up using this ZHA - Inovelli Blue Series 2-1 Switch LED Notification Script. Once that is set up as a script you can do something like this:

action: script.inovelli_notification
data:
  led: "{{ some variable here }}"
  effect: "{{ effect }}"
  duration: 255
  color: 150
  level: 50
  switch: "{{ some variable here }}"

Not sure if this advice applies to other types of devices/actions, but perhaps you can see what the script is doing and make your own solution based on that.

2 Likes