Light value rotating - rainbow effect - transition etc

Hi all.

I would like to have a smooth - slow - light changing of several RGB stripes. I’ve read several ideas and solutions here, but I don’t get them working according to my needs. The “effect” transition time, isn’t available for all stripe types; other solutions are doing a strange dependency on now().second or the frequency of the call via automation.
What I want to do:

  • Define an 3-dimensional array of RGB values for different lights config [0,0,255],[0,255,0];[255,0,0]… inside the script
  • Define a variable where I can store the current array pointer within HA (variables or input_number ?)
    Every time when call the script:
  • load the current array position value (pos) (from variable or input_number ?)
  • set the light to the array values at pos (can use transition: y here if it is supported by strip)
  • increase pos+1 and if pos > num_of_array_fields → reset pos to 0
  • save pos back to (variable or input_number ?)…

Finally - call the script using an automation with time_pattern for instance minutes /5

What I don’t get, and where I need help with:
How to save a value to an external variable and how to get it back?
And - to be honest - how does the script exactly look like (but I’m willing to find this out myself;-))

And yes, I’ve understood that I can start learning python… I’m 50 years old, starting with BasicV7 and assamber on a C128, Turbo Pascal within CP/M, tried C, create a Java-script store and used PHP and visual Basic a lot. After so many years at the console, scripting company security and active directory, audits etc… I’m personally a bit tired to understand docker concepts and all the python include/import dependencies. I prefer to have an easy GUI - like Home Assistant. I’m using the build-in File editor but have huge problems to remember always on how to access the home-assistant core docker file system etc… :wink:

So I assumed that I can realize my idea above using a simple mix of automation and a call for a script. Just need to understand how to load a value from a variable (there is something like “variables:” as well in HA, or input_number) into a script and how to write it back to this variable when the script ends.

It would be great if you can point me to a link where I can read about, I’m fine too. But I haven’t found any example on what I want to do yet.

Thank you all in advance.

1 Like

It’s fairly easy to meet your requirements using an input_select to store the RGB values.

Create an input_select and enter the RGB values you want. You can create it via Configuration > Helpers > Dropdown

Or you can create in in configuration.yaml

input_select:
  colors:
    name: Colors
    options:
      - 0,0,255
      - 0,255,0
      - 255,0,0

It’s important that you enter the RGB value as shown (don’t add brackets or quotes). Home Assistant will interpret a value like 0,0,255 to mean [0,0,255] which is what’s needed for this application.

Create an input_boolean that will be used to control when the automation should, or should not, cycle through the colors. You can create it using the UI or in configuration.yaml.


The following automation triggers every 5 minutes. If input_boolean.colors is on, it executes the action.

It sets the light’s color to whatever is the currently selected option in input_select.colors then sets the input_select’s value to its next option (it will automatically wrap around from the last option to the first). The inclusion of transition: 5 is optional (i.e. transition from one color to another over a period of 5 seconds).

alias: 'example 1'
trigger:
- platform: time_pattern
  minutes: '/5'
condition: "{{ is_state('input_boolean.colors', 'on') }}"
action:
- service: light.turn_on
  target:
    entity_id: light.your_light
  data:
    rgb_color: "{{ states('input_select.colors') }}"
    transition: 5
- service: input_select.select_next
  target:
    entity_id: input_select.colors

I tested it on my system and it repeatedly cycled through the list of colors in the input_select.


Here’s another automation that does the same thing but works a bit differently. It is triggered by the state of the input_boolean.

When on, it starts a repeat that cycles through the colors in the same manner as the previous example but uses a delay to pause for 5 minutes. It cycles through the colors as long as the input_boolean is on and less than 200 times (an optional ‘limiter’; discard it if you feel it’s unnecessary). When the input_boolean is turned off it will cause the repeat to terminate and will also turn off the light.

alias: 'example 2'
trigger:
- platform: state
  entity_id: input_boolean.colors
action:
- choose:
  - conditions: "{{ trigger.to_state.state == 'on' }}"
    sequence:
    - repeat:
        while:
        - "{{ is_state('input_boolean.test', 'on') }}"
        - "{{ repeat.index <= 200 }}"
        sequence:
        - service: light.turn_on
          target:
            entity_id: light.your_light
          data:
            rgb_color: "{{ states('input_select.colors') }}"
            transition: 5
        - service: input_select.select_next
          target:
            entity_id: input_select.colors
        - delay:
            minutes: 5
  default:
  - service: light.turn_off
    target:
      entity_id: light.your_light
3 Likes

Wow! Merci!
Thank you very much for this fast and detailed and 100% helpful response! The select_next method of input_select is what’s doing the trick much easier and no script is required at all!
I think the second option - to keep the automation running instead of re-start it every time would reduce resources usage a bit.
Thanks for clearly explaining both of them, I’ve tested this already and it worked as expected!
Thank you again - and have a nice rest weekend!

1 Like

Hi guys and sorry for restarting this post :slight_smile:

I’m pretty new at HA, and I’m trying to set my new LED light strip (from Gosund, intengration with Tuya) to do a rainbow pattern when someone at the door rings the doorbell. Unfortunately the post from @123 Taras is not working for me. I set the input_select, and the automation is:

- id: '1667510350135'
  alias: Doorbell Lights
  description: ''
  trigger:
  - platform: state
    entity_id:
    - binary_sensor.g4_doorbell_doorbell
  action:
  - service: light.turn_on
    target:
      entity_id: light.led_strip_lights
    data:
      rgb_color: "{{ states('input_select.colors') }}"
      transition: 5
  - service: input_select.select_next
    target:
      entity_id: light.led_strip_lights

When I run the automation it doesn’t do anything. Any ideas what can I check or test?
Thank you in advance!

  • The example I posted (over a year ago) was confirmed to work by the person it was designed for.
  • The example you posted is substantially different.

Check the automation’s trace

Reference: Troubleshooting Automations