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.