RGB Color Bulb Sequencing Problem

I have 9 hue bulbs in a chandelier. I want to setup some simple color sequences.

The script works fine when call the script as follows, and hard-code rgb_color: [0,255,255].

service: script.light_sequence
data:
  light_group: light.dining_room
  delay: 0.2
  transition: 5
script:
  light_sequence:
    mode: restart
    sequence:
        - repeat:
            count: "{{ state_attr(light_group,'entity_id')|count }}"
            sequence:
              - service: light.turn_on
                data_template:
                  brightness: 255
                  entity_id: "{{ state_attr(light_group,'entity_id')[repeat.index-1] }}"
                  rgb_color: [0,255,255]
                  transition: "{{ transition|default(5) }}"

                - delay: "{{ delay|default(0.2) }}"

But, if I try to pass a sequence of color sequences as follows, the script throws the following error:
None for dictionary value @ data['rgb_color']

light_group: light.dining_room
delay: 0.2
transition: 5
colors:
  - [255,255,0]
  - [255,0,255]
  - [0,255,255]
  - [0,0,255]
  - [0,255,0]
  - [255,0,0]
  - [255,255,0]
  - [255,0,255]
  - [0,255,255]
                  #rgb_color: [0,255,255]
                  rgb_color: "{{ colors[repeat.index-1] }}"

It seems like this should work. What am I missing?

See for example:

This one is for you:

tl;dr
rgb_color only accepts a list.

Templates can only produce a string.

This "{{ colors[repeat.index-1] }}" produces a string that only looks like a list.

1 Like

Thank you. That confirms my suspicions. I will find an alternate way. Thanks!

My solution ended up being to switch to color_name: instead. Those are strings. :slight_smile:

FWIW, it’s possible to template rgb_color by templating each value separately. For example, this template selects a random value between 0-255.

{{ range(0,256) | random }}

To use it with rgb_color, you apply it to red, green, and blue.

  rgb_color:
    - "{{ range(0,256) | random }}"
    - "{{ range(0,256) | random }}"
    - "{{ range(0,256) | random }}"

or in the more traditional way to represent a list:

  rgb_color: [ "{{ range(0,256) | random }}",  "{{ range(0,256) | random }}", "{{ range(0,256) | random }}" ]
1 Like