Help with scripts and parameters

Hi.
I’m trying to use my living room light as a notification for various events, by flashing different colors.

For testing I setup an automation that calls a script when an input_boolean is triggered, and passes the rgb color to the script.
Nothing happens. I tried to put/remove brackets etc. but I didn’t find the correct syntax.

automation:

- id: accendi_lampeggiante_interno
  alias: accendi lampeggiante interno
  trigger:
    - platform: state
      entity_id: input_boolean.lampeggiante_interno
      from: 'off'
      to: 'on'
  action:
    - service: script.lampeggia_ikea_colore_1x
      data_template:
        color: [0,255,0]

script:

lampeggia_ikea_colore_1x:
  sequence:
    - service: light.turn_on
      data_template:
        entity_id: light.0x000d6ffffe688544_light 
        brightness: 255
        rgb_color: "{{ color }}"
    - delay:
        milliseconds: 600
    - service: light.turn_off
      data:
        entity_id: light.0x000d6ffffe688544_light
    - delay:
        milliseconds: 600

The original idea was that the automation calls a script passing the color, and this script calls the abobe script 3 times, repassing to it the same color parameter, and so flashing 3 times.
But first I must make the direct script call working with the parameter…
Can someone help me?
Thanks.

Edit - sorry, ignore me.

This is a common issue. See for example:

The gist of the problem is, in the script the color variable will contain a list. However, when you use it in a template, the template will convert it to a string. So rgb_color: "{{ color }}" results in the string:

'[0,255,0]'

not the list:

[0,255,0]

The rgb_color parameter requires a list, not a string that looks like a list.

My typical suggestion is to use color_name instead of rgb_color.

Phil, just to tidy this thread up and provide a useful link for all the dumb schmucks (eg me). Is their a list of valid color_name 's ?

See the color_name option documented in the light.turn_on service. It has a link to that information.

to make it work with a script the way you want, you could do the following

    - service: script.lampeggia_ikea_colore_1x
      data_template:
        r: 0
        g: 255
        b: 0

or

    - service: script.lampeggia_ikea_colore_1x
      data_template: {'r':0, 'g': 255, 'b':0 }

with this in your script

    - service: light.turn_on
      data_template:
        entity_id: light.0x000d6ffffe688544_light 
        brightness: 255
        rgb_color: [ "{{ r }}", "{{ g }}", "{{ b }}" ]

That’s also a good solution. My point was more to describe the limitation / unexpected behavior that most people don’t appreciate/understand.

BTW, I’d suggest this:

    - service: script.lampeggia_ikea_colore_1x
      data:
        color: lime

and

    - service: light.turn_on
      data_template:
        entity_id: light.0x000d6ffffe688544_light 
        brightness: 255
        color_name: "{{ color }}"

:slight_smile:

Wasn’t trying to discount your response, only suppliment it.

1 Like

No problem. BTW, you forgot the necessary quotes in the rgb_color template. Should be:

        rgb_color: [ "{{ r }}", "{{ g }}", "{{ b }}" ]

yep yep, forgot it, updated

You are all wonderful, and this is a great community!
Now I can’t, but tomorrow I will check and try.
Thank you very much!!!

Ok, I tried and it worked at first attempt.
I already introduced the second script, and it immediately worked too.
I didn’t know about color_name, it’s very easy and handy.
The other solution will be useful too.
So thank you again for the help and the explanation.

1 Like