Cycling from RGB Colour to White light/Colour Temp

Hi all

I’m trying to figure out how to cycle my Benta Gu10 bulb with Tasmota from RGB colours to use the yellow/white LEDS in a single automation, currently I’m using 2 separate ones to achieve this.

  - alias: BedroomColorChange
    trigger:
      platform: event
      event_type: click 
    action:
      service: light.turn_on
      data_template:
        entity_id: light.bentagu10test
        color_name:  >
          {% if states.light.bentagu10test.attributes.rgb_color == (255,0,0) %} blue
          {% elif states.light.bentagu10test.attributes.rgb_color == (0,0,255) %} green
          {% elif states.light.bentagu10test.attributes.rgb_color == (0,255,0) %} yellow
          {% else %} red
          {% endif %}
        brightness_pct: 100        
        
  - alias: BedroomWhiteLED
    trigger:
      platform: event
      event_type: click 
    action:
      service: light.turn_on
      entity_id: light.bentagu10test
      data_template:
        color_temp: 158
        brightness_pct: 100
        transition: 0.5

First cycles selected colours and seconds switches back to white LEDS, currently have them as separate buttons with custom UI.

Both automations use the same trigger. How are you triggering one without also triggering the other? Are you calling automation.trigger? If so, why are they even automations? Why not scripts?

If you want one automation (or script???) to do both operations in sequence, then just add them as multiple steps to the same automation/script. E.g.:

  - alias: Bedroom
    trigger:
      platform: event
      event_type: click 
    action:
    - service: light.turn_on
      data_template:
        entity_id: light.bentagu10test
        color_name:  >
          {% if states.light.bentagu10test.attributes.rgb_color == (255,0,0) %} blue
          {% elif states.light.bentagu10test.attributes.rgb_color == (0,0,255) %} green
          {% elif states.light.bentagu10test.attributes.rgb_color == (0,255,0) %} yellow
          {% else %} red
          {% endif %}
        brightness_pct: 100        
    - service: light.turn_on
      entity_id: light.bentagu10test
      data_template:
        color_temp: 158
        brightness_pct: 100
        transition: 0.5

Or did I misunderstand what you’re trying to do? (You never asked a question, so it’s not very clear what help you’re asking for.)

1 Like

I’m activating them with a button push on a custom UI panel. So the trigger is pretty irrelevant actually, it’s more about the action that is confusing me. Sorry I’m not too sure exactly what my code should be. I understand I have a color_name if else but I’m not sure what to do other than that.

How would I create a script which makes the light go from blue, green, red and then colour temp = 158 and cycle around?

Ok, I think I finally understand what you’re asking for. The easiest way is to not use color_temp, but rather to convert the color temperature value to an RGB value:

>>> from homeassistant.util.color import color_temperature_to_rgb
>>> color_temperature_to_rgb(158)
(255, 67.92041905680745, 0)

And then, looking at the available color names, it appears orangered is very close (i.e., 255, 69, 0.) So you could do:

        color_name:  >
          {{ {
               none: 'blue',
               (255, 69, 0): 'blue',
               (0, 0, 255): 'green',
               (0, 255, 0): 'red',
               (255, 0, 0): 'orangered'
             }[state_attr('light.bentagu10test', 'rgb_color')] }}

This uses a dictionary instead of an if-elif-else statement, but achieves the same result. It also handles the case where the rgb_color attribute cannot be read (e.g., if the light was off).

Of course, I don’t have the same type of light you have, so I don’t know if using an equivalent color_name as the color_temp works the same way. If it doesn’t, then probably the easiest way to do what you want is to write a python_script. Let me know if the above doesn’t do what you need and you’d rather try the python_script.

1 Like
>>> from homeassistant.util.color import color_temperature_to_rgb
>>> color_temperature_to_rgb(158)
(255, 67.92041905680745, 0)

I’m uncertain what to do with this?

One other thing I do see, when I set colour temp to 153, rgb goes to (255,255,255), color temp being 153 is also the only value colour temp should be in this scenario.

Nothing. I was just “showing my work.” I first converted 158 kelvin to an equivalent RGB value, and then used that to look up a close color name.

Then your light platform is broken:

>>> color_temperature_to_rgb(153)
(255, 67.92041905680745, 0)

153 K == (255, 67.92, 0)

Then why did you previously say, “light go from blue, green, red and then colour temp = 158”?

1 Like

Ok I see!

So currently, the code you gave me goes from ‘orangered’ to being (255,255,255), so white but then doesn’t cycle back around.

It seems that making the shift from a rgb colour to changing the value of the colour temp is what switches to the other LEDs on the light, so it has to be a call that calls, blue, green, red, colour temp 153

Sorry 153, not 158. 158 funny enough works in the code but I’m looking directly at the colour palette now and 153 is the max.

Recall I said:

I can suggest a python_script, but you need to tell me what the light’s attributes are after it is changed to red, and after it is changed to a color temp of 153.

BTW, what light platform are you using here?

Well if you can suggest a script that would change color_name to red, green, blue and lastly set the color_temp to 153, then cycle around. That would definitely do it.

When I’m changing the RGB value, the hs and rgb color both change, the color temp stays constant at whatever value it last was because the color temp value only relates to the other set of LEDS in the globe it seems. So as soon as the color temp value is called or altered those LEDS light up and the LEDs used for RGB stop working, and visa versa.

It’s a Bneta Gu10 globe running Tasmota 8.1.0.2 with the recommended template.

So how is the script supposed to tell the difference between having set it to red, and having set it to 153 K? You seem to be telling me that there’s no guarantee that the state of the light entity (i.e., its attributes) will be any different after these two very different actions.

What the script needs to do is just call the color_temp value to be 153 and then the required color_name values. Sorry that’s all I can say because each set of LEDS use different attributes.

brightness
hs color
rgb color
xy color

and:

brightness
color temp

Let’s take a step back. Please set the light to red, then go to the STATES tab of the Developer Tools page, find light.bentagu10test and click on it. At the top of the page it will fill in the box under “State attributes” with the light’s current attributes. Copy and paste that into your reply. Then do the same after setting the color temperature to 153.

Red

min_mireds: 153
max_mireds: 500
brightness: 255
color_temp: 158
hs_color:
  - 0
  - 100
rgb_color:
  - 255
  - 0
  - 0
xy_color:
  - 0.701
  - 0.299
friendly_name: BentaGu10Test
supported_features: 19

Color temp = 153


min_mireds: 153
max_mireds: 500
brightness: 255
color_temp: 158
hs_color:
  - 0
  - 0
rgb_color:
  - 255
  - 255
  - 255
xy_color:
  - 0.323
  - 0.329
friendly_name: BentaGu10Test
supported_features: 19

If I tap white on the color palette and get info:

min_mireds: 153
max_mireds: 500
brightness: 255
color_temp: 153
hs_color:
  - 0
  - 0
rgb_color:
  - 255
  - 255
  - 255
xy_color:
  - 0.323
  - 0.329
friendly_name: BentaGu10Test
supported_features: 19

Seems when switching between RGB colours colour temp goes to 158. (If I use my original automation)

Thanks.

BTW, I misspoke earlier. The unit for color_temp is actually mireds, which is 1,000,000 / Kelvin. So when you set color_temp to 153, you’re not actually setting it to 153 K, but 6,535 K.

Let’s try this:

cur_rgb = hass.states.get('light.bentagu10test').attributes['rgb_color']
service_data = {'entity_id': 'light.bentagu10test'}
if cur_rgb == (255, 0, 0):
    service_data['rgb_color'] = (0, 255, 0)
elif cur_rgb == (0, 255, 0):
    service_data['rgb_color'] = (0, 0, 255)
elif cur_rgb == (0, 0, 255):
    service_data['color_temp'] = 153
else:
    service_data['rgb_color'] = (255, 0, 0)
hass.services.call(
    'light',
    'turn_on',
    service_data,
)

Sorry could you just clarify what the full automation should look like?

Well, this isn’t an automation, or a script, but a Python script. If you haven’t used them before, please read the doc via that last link. But here’s the shortcut version:

First, add the following line to configuration.yaml:

python_script:

Then create a folder named python_scripts in the same folder where configuration.yaml lives.

Now restart HA.

Then inside the python_scripts folder create a file containing the code above. Let’s use cycle_bentagu10test.py for the name.

Now go to the SERVICES tab of the Developer Tools page. Select service python_script.reload and click CALL SERVICE. Now your script (namely python_script.cycle_bentagu10test) should be in the services list. Select it and click CALL SERVICE. Each time you click CALL SERVICE it should run and cycle the light.

Let me know if you run into any trouble. I might have missed some detail.

EDIT:

Ultimately you’ll want to call your new python_script.cycle_bentagu10test service via whatever technique you’re using (which I never quite understood, nor did you ever actually clarify.)

1 Like