Setting LIFX bulbs to Random color?

Is it possible to set the LIFX bulbs to a random color? I looked the Lifx combinations and just see color loop, not random. Anyone have an example?

Thanks

Try thisL

 - service: light.lifx_set_state
   data_template:
     entity_id: light.light_name
     brightness: 255
     rgb_color: [{{range(0, 255)|random}},{{range(0, 255)|random}},{{range(0, 255)|random}}]

FYI, the second value for range should be 256, not 255. (The last value produced by range must be less than the second parameter. So, to get values up to 255, the second parameter should be 256.) In fact, you can just use range(256), because the default start value is zero.

Thanks for pointing this out. Doubt it will make any difference in the end result for this specific case, but I like to be corrected :slight_smile:

Thanks - but something still isn’t quite right. I’m trying to convert this into an automation from Smartthings webcore for a Lutron pico. I’m using a different pico example I found here.

Here is what I have:

  • id: kc_pico_fav_on_sf
    alias: SF Pico Fav Button
    initial_state: True
    trigger:
    • platform: state
      entity_id: sensor.kitchen_pico_side_entry
      to: ‘2’
      condition:
      condition: state
      entity_id: group.kitchen_ceiling_lights
      state: ‘on’
      action:
      service: light.lifx_set_state
      data_template:
      entity_id: group.kitchen_ceiling_lights
      brightness: 255
      rgb_color: [{{range(0, 255)|random}},{{range(0, 256)|random}},{{range(0, 255)|random}}]

This is giving me this error:

ERROR:homeassistant.util.yaml:invalid key: “OrderedDict([(‘range(0’, None), (‘255)|random’, None)])”
in “/config/automations.yaml”, line 41, column 0
Failed config
General Errors:
- Error loading /config/configuration.yaml: invalid key: “OrderedDict([(‘range(0’, None), (‘255)|random’, None)])”
in “/config/automations.yaml”, line 41, column 0
Successful config (partial)

Needed quotes are missing:

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

When do you need quotes for RGB parameters and when do you not? I have a few LED strips that I defined as JSON MQTT lights and I don’t need the quotes…

It’s not whether you need them for RGB, but whether you need them for templates, which is just about always (at least if you don’t use multi-line, which you really can’t in this situation.) If you don’t use the quotes the YAML parser will see the curly braces and think they are the start of a dictionary.

1 Like