[SOLVED]/Improving Color Loop

How can I make this light do color loop/rainbow effect?

Thanks,

UPDATE WORKING CONFIG

SCRIPTS.YAML

# script.rainbow_light

rainbow_light:
  alias: rainbow light
  mode: single

  fields:
    entity:
      description: The entity that will be rainbowed
      example: light.bathroom

  variables:
    colors: |-
      {{ [[0.217,0.077], [0.157,0.05], [0.136,0.04], [0.137,0.065],
          [0.141,0.137], [0.146,0.238], [0.151,0.343], [0.157,0.457],
          [0.164,0.591], [0.17,0.703], [0.172,0.747], [0.199,0.724],
          [0.269,0.665], [0.36,0.588], [0.444,0.517], [0.527,0.447],
          [0.612,0.374], [0.677,0.319], [0.701,0.299], [0.667,0.284],
          [0.581,0.245], [0.477,0.196], [0.385,0.155], [0.301,0.116], 
          [0.217,0.077]] }}

  sequence:
    - service: light.turn_on
      data_template:
        xy_color: |
          {{  colors[(now().second/2.5)|round(0)] }}
        transition: 50
        entity_id: '{{ entity }}'

AUTOMATIONS.YAML

# automation.rainbow_strip_led
alias: Living Room LEDs Rainbow Mode
description: Three LEDs Strips in Living Room
trigger:
  - hours: '*'
    minutes: '*'
    platform: time_pattern
    seconds: /1
condition: []
action:
  - service: script.rainbow_light
    data:
      entity: light.living_room_leds  # --> CHANGE THIS ENTITY TO YOUR BULB OR LED STRIP
mode: single
1 Like

If it does not list an attribute like this:

effect_list: effect_colorloop

You are going to have to use a script or automation to do it.

How can I do it with script or automation, I am new to home assistant.

1 Like

I getting these errors, need help

alias: rainbow light

mode: single

fields:

  entity:

    description: light.living_room_leds

    example: light.bathroom

variables:

  colors: |-

    {{ [[0.217,0.077], [0.157,0.05], [0.136,0.04], [0.137,0.065],

        [0.141,0.137], [0.146,0.238], [0.151,0.343], [0.157,0.457],

        [0.164,0.591], [0.17,0.703], [0.172,0.747], [0.199,0.724],

        [0.269,0.665], [0.36,0.588], [0.444,0.517], [0.527,0.447],

        [0.612,0.374], [0.677,0.319], [0.701,0.299], [0.667,0.284],

        [0.581,0.245], [0.477,0.196], [0.385,0.155], [0.301,0.116], 

        [0.217,0.077]] }}

sequence:

  - service: light.turn_on

    data_template:

      xy_color: |

        {{  colors[(now().second/2.5)|round(0)] }}

      transition: 1

      entity_id: light.living_room_leds

That’s a script. It needs to all be indented under script: or if you have split your configuration, put in your scripts.yaml file.

I placed them in correct locations, but am getting this error Unable to find service script.rainbow_light

chrome_XMm0mIgJaQ

Try the script like this:

rainbow_light:
  alias: rainbow light
  mode: single

  fields:
    entity:
      description: The entity that will be rainbowed
      example: light.bathroom

  variables:
    colors: |-
      {{ [[0.217,0.077], [0.157,0.05], [0.136,0.04], [0.137,0.065],
          [0.141,0.137], [0.146,0.238], [0.151,0.343], [0.157,0.457],
          [0.164,0.591], [0.17,0.703], [0.172,0.747], [0.199,0.724],
          [0.269,0.665], [0.36,0.588], [0.444,0.517], [0.527,0.447],
          [0.612,0.374], [0.677,0.319], [0.701,0.299], [0.667,0.284],
          [0.581,0.245], [0.477,0.196], [0.385,0.155], [0.301,0.116], 
          [0.217,0.077]] }}

  sequence:
    - service: light.turn_on
      data_template:
        xy_color: |
          {{  colors[(now().second/2.5)|round(0)] }}
        transition: 1
        entity_id: '{{ entity }}'
2 Likes

Thanks a lot, it’s working

One last thing, Is it possible make colors fade rather than hard change?

Increase the transistion time in this bit:

  sequence:
    - service: light.turn_on
      data_template:
        xy_color: |
          {{  colors[(now().second/2.5)|round(0)] }}
        transition: 1
        entity_id: '{{ entity }}'

Thanks, all good.

What are these color values [0.157,0.05] rgb?

It is xy_color.

Thanks,

Can’t thank you enough.

@tom_l Will the RGB values work instead of xy?

Yes you would just have to change the variables and the light.turn_on service call.

Is there a limit of how many color variables can be there?

No but there is a limit to the number of colours your lights can display. You might find that RGB values like [ 0, 248, 255] and [ 0, 255, 255] look so similar as to be indistinguishable.

Also I missed that this part of the template would need adjusting if you altered the transition time.

{{  colors[(now().second/2.5)|round(0)] }}

It would also need adjusting if you changed the number of colours. It only works with a transition time of 1 second and 25 colours. So if you have adjusted the transition time you are probably not seeing all the colours.

So 2.5 = 25 colors?

Including zero, yes.

The index for the list of colours starts counting at 0, so [0, 1, 2, 3 … 24]

60 sec / 2.5 = 24

As the transition cant be interrupted, if you use a transition time of 5 seconds you would only see 5 colours.

What transition time are you using?

Let’s say I want to use 100 colors, what would my setting for seconds and transition?