Cycling between available colors

Is there a way to cycle through (not randomly) available light colors with a switch?
I’m using a Yeelight RGB with a Xiaomi magic cube which acts as a switch.

1 Like

Yes, there is. I just did it but using Philips Hue. What I did:

  1. create the “profiles” you want and put it on light_profiles.csv. Example:
    id,x,y,brightness
    normal,0.4596,0.4105,254
    relax,0.5119,0.4147,255
    concentrate,0.5119,0.4147,255
    energize,0.368,0.3686,203
    reading,0.4448,0.4066,240
    orange,0.6177,0.3636,151
    red,0.6663,0.318,146

  2. Create a automation which “cycle” your profiles. I use a xiaomi wireless switch. Double click cycle the profiles:

    alias: alterna profiles do spot da sala
    hide_entity: True
    trigger:
    platform: event
    event_type: click
    event_data:
    entity_id: binary_sensor.switch_xxxxxx
    click_type: double
    action:

    • service: light.turn_on
      data_template:
      entity_id: light.spot_sala
      profile: >-
      {% if states.light.spot_sala.attributes[‘rgb_color’] | string == “(255, 206, 118)” %}
      energize
      {% elif states.light.spot_sala.attributes[‘rgb_color’] | string == “(242, 228, 190)” %}
      red
      {% elif states.light.spot_sala.attributes[‘rgb_color’] | string == “(255, 69, 31)” %}
      orange
      {% else %}
      normal
      {% endif %}

The tricky part was to discover on which profile the light is so you can choose the next one. The numbers between parentesis is the RGB color that the light reports to HA. I dont know why the light_profile use one color representation and the light another one (my fault, I guess :slight_smile: ). I’m almost sure someone wil come with a better solution. To discover those numbers I add this to the action:

- service: notify.Lyra
  data_template:
      message: "sala {{states.light.spot_sala.attributes['rgb_color']}}  {{states.light.spot_sala.attributes['xy_color']}} {{states.light.spot_sala.attributes['brightness']}}"

So the ligth report those values on my telegram :-).

Can anybody share their code on this one? As i understand the csv can be skipped by just calling new RGB values. But i don’t like the checking of if states.light.spot_sala.attributes[‘rgb_color’]
Maybe there is a better workaround?

Well… there are other ways. One way is using a input_selection to cycle the colors. I did a little test here with this configuration. First you create a input_selection:

color:
    initial: green
    options:
      - red
      - green
      - yellow
      - blue

And then you can use them, like this example script:

lightcolor:
    sequence:
       - service: input_select.select_next
         entity_id: input_select.color
       - service: persistent_notification.create
         data_template:
           title: "color alert"
           message: >
                 now the color should be {{ states('input_select.color') }}

My approach for my new Philips Hue switch:

alias: Philips Hue Switch
description: ''
trigger:
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: on_press_release
    discovery_id: 0x001788010926fed5 action_on_press_release
    id: on_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: up_press_release
    discovery_id: 0x001788010926fed5 action_up_press_release
    id: up_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: down_press_release
    discovery_id: 0x001788010926fed5 action_down_press_release
    id: down_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: off_press_release
    discovery_id: 0x001788010926fed5 action_off_press_release
    id: off_press_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: on_hold_release
    discovery_id: 0x001788010926fed5 action_on_hold_release
    id: on_hold_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: off_hold_release
    discovery_id: 0x001788010926fed5 action_off_hold_release
    id: off_hold_release
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: up_hold
    discovery_id: 0x001788010926fed5 action_up_hold
    id: up_hold
  - platform: device
    domain: mqtt
    device_id: fbb638b9fbade2db6739a4002bb0f9f3
    type: action
    subtype: down_hold
    discovery_id: 0x001788010926fed5 action_down_hold
    id: down-hold
condition: []
action:
  - choose:
      - conditions:
          - condition: trigger
            id: on_press_release
        sequence:
          - type: toggle
            device_id: 3bd52319e8de1a6106f1b7f729c3ddd8
            entity_id: light.bedroom_lamps
            domain: light
      - conditions:
          - condition: trigger
            id: up_press_release
        sequence:
          - device_id: 3bd52319e8de1a6106f1b7f729c3ddd8
            domain: light
            entity_id: light.bedroom_lamps
            type: brightness_increase
      - conditions:
          - condition: trigger
            id: down_press_release
        sequence:
          - device_id: 3bd52319e8de1a6106f1b7f729c3ddd8
            domain: light
            entity_id: light.bedroom_lamps
            type: brightness_decrease
      - conditions:
          - condition: trigger
            id: off_press_release
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.bedroom_lamps
            data_template:
              color_temp: >
                {% if state_attr("light.bedroom_lamps","color_temp")|int > 350 %}
                333
                {% elif state_attr("light.bedroom_lamps","color_temp")|int > 332 %}
                285
                {% elif state_attr("light.bedroom_lamps","color_temp")|int > 284 %}
                244
                {% elif state_attr("light.bedroom_lamps","color_temp")|int > 243 %}
                165
                {% else %}
                370
                {% endif %}
      - conditions:
          - condition: trigger
            id: on_hold_release
        sequence:
          - service: light.toggle
            target:
              device_id:
                - 9ffc5618d5df2d3a408bae4f98c2d2c4
                - 3bd52319e8de1a6106f1b7f729c3ddd8
      - conditions:
          - condition: trigger
            id: off_hold_release
        sequence:
          - service: light.turn_on
            target:
              entity_id: light.bedroom_lamps
            data:
              color_temp: 260
              brightness_pct: 100
      - conditions: []
        sequence: []
    default: []
mode: queued
max: 10
4 Likes