Animated lights template / rgb_color randomization

@skalavala hi!

trying your animated lights on Hue, I wonder why this has another order than the ‘regular’ order for entity_id and data?

https://github.com/skalavala/smarthome/blob/master/packages/lights.yaml#L453

action:
  service: light.turn_on
  data:
    entity_id: light.master_bedroom
    transition: 5
    brightness: 150
  data_template:
    rgb_color: ['{{ "{0:d}".format(range(0, 255)|random) }}',
                '{{ "{0:d}".format(range(0, 255)|random) }}',
                '{{ "{0:d}".format(range(0, 255)|random) }}']

while usually I see this:

action:
  service: light.turn_on
  entity_id: light.master_bedroom
  data_template:
    transition: 5
    brightness: 150
    rgb_color: ['{{ "{0:d}".format(range(0, 255)|random) }}',
                '{{ "{0:d}".format(range(0, 255)|random) }}',
                '{{ "{0:d}".format(range(0, 255)|random) }}']

Ive tried that, but it won’t do anything…

second: is this a special notation for the rgb_color template? elsewhere I use it like this:

      rgb_color: ['{{ (range(0, 255)|random) }}',
                  '{{ (range(0, 255)|random) }}',
                  '{{ (range(0, 255)|random) }}']

just trying to understand the format, maybe you can explain what this does please?

thx,
Marius

Hi,

The attributes can be in any order. If the value of the attribute is “dynamic”, meaning it uses some sort of template code, you need to use data_template instead of just data. What that automation does is, it fires every 5 seconds, and it generates random RGB values and transition from the current color to the new color slowly (in 5 seconds). That way, every 5 seconds, the light will change to a new color gradually/slowly and it never ends. The only way to stop is to disable the automation is to turn off the input boolean animate_downstairs_lights.

The code was written long time ago, when the “effect” feature was limited. You might be able to use the effect feature to get the same functionality. I used a lot of light automations earlier when I was new to Home Automation, and I just don’t find that interesting anymore :smile:

Each color value is a whole number that is typically between 0 and 255. Either format should work.

1 Like