Light Template Cannot Change Color Mode

I’ve got a light template and I cannot (from the documentation) figure out how to change the color mode. In my light template, if i change the color temperature, the color/temperature will correctly change but the color mode will stay at “HS”. If I change an actual light’s color temperature, the color mode will go to “color_temp”. Is there any way to fix my template?

  - platform: template
    lights:
      fish_light_3:
        friendly_name: "Fish Light 3"
        level_template: "{{ state_attr('light.gledopto_gl_c_008_1a140f15_11', 'brightness')|int }}"
        #value_template: "{{ state_attr('light.gledopto_gl_c_008_1a140f15_11', 'brightness')|int > 0 }}"
        value_template: "{{ states.light.gledopto_gl_c_008_1a140f15_11.state }}"
        temperature_template: "{{state_attr('light.gledopto_gl_c_008_1a140f15_11', 'color_temp') | int}}"
        color_template: "{{state_attr('light.gledopto_gl_c_008_1a140f15_11', 'hs_color')}}" #"({{states('input_number.h_input') | int}}, {{states('input_number.s_input') | int}})"
        #effect_list_template: "{{ state_attr('light.gledopto_gl_c_008_1a140f15_11', 'effect_list') }}"
        turn_on:
          - service: light.turn_on
            entity_id: light.gledopto_gl_c_008_1a140f15_11
        turn_off:
          - delay: 00:00:05
          - service: light.turn_off
            entity_id: light.gledopto_gl_c_008_1a140f15_11
        set_level:
          service: light.turn_on
          data:
            entity_id: light.gledopto_gl_c_008_1a140f15_11
            brightness: "{{ brightness }}"
        set_temperature:
          #- service: input_text.set_value
          #  data_template:
          #    entity_id: input_text.broadcast_message_to_office
          #    value: "{{ color_temp }}"
          - service: light.turn_on
            data:
              entity_id: light.gledopto_gl_c_008_1a140f15_11
              color_temp: "{{ color_temp }}"
        #set_white_value:
        #  service: light.turn_on
        #  data:
        #    entity_id: light.gledopto_gl_c_008_1a140f15_11
        #    white: "{{ white_value }}"
        set_color:
          - service: light.turn_on
            data_template:
              entity_id: light.gledopto_gl_c_008_1a140f15_11
              hs_color: "[{{h}}, {{s}}]"
        #set_effect:
        #  - service: light.turn_on
        #    data_template:
        #      entity_id:
        #        - light.ledvance_a19_rgbw_e1e40500_level_light_color_on_off
        #      effect: "{{ effect }}"
        supports_transition_template: "{{ true }}"
  - platform: template
    lights:
      kitchen_led:
        friendly_name: "Kitchen LED"
        level_template: "{{ state_attr('light.gledopto_gl_c_008_c19f431d_level_light_color_on_off', 'brightness')|int }}"
        #value_template: "{{ state_attr('light.gledopto_gl_c_008_c19f431d_level_light_color_on_off', 'brightness')|int > 0 }}"
        value_template: "{{ states.light.gledopto_gl_c_008_c19f431d_level_light_color_on_off.state }}"
        temperature_template: "{{state_attr('light.gledopto_gl_c_008_c19f431d_level_light_color_on_off', 'color_temp') | int}}"
        color_template: "{{state_attr('light.gledopto_gl_c_008_c19f431d_level_light_color_on_off', 'hs_color')}}" #"({{states('input_number.h_input') | int}}, {{states('input_number.s_input') | int}})"
        #effect_list_template: "{{ state_attr('light.gledopto_gl_c_008_c19f431d_level_light_color_on_off', 'effect_list') }}"
        turn_on:
          - service: light.turn_on
            entity_id: light.gledopto_gl_c_008_c19f431d_level_light_color_on_off
        turn_off:
          - delay: 00:00:05
          - service: light.turn_off
            entity_id: light.gledopto_gl_c_008_c19f431d_level_light_color_on_off
        set_level:
          service: light.turn_on
          data:
            entity_id: light.gledopto_gl_c_008_c19f431d_level_light_color_on_off
            brightness: "{{ brightness }}"
        set_temperature:
          service: light.turn_on
          data:
            entity_id: light.gledopto_gl_c_008_c19f431d_level_light_color_on_off
            color_temp: "{{ color_temp }}"
        #set_white_value:
        #  service: light.turn_on
        #  data:
        #    entity_id: light.gledopto_gl_c_008_c19f431d_level_light_color_on_off
        #    white: "{{ white_value }}"
        set_color:
          - service: light.turn_on
            data_template:
              entity_id: light.gledopto_gl_c_008_c19f431d_level_light_color_on_off
              hs_color: "[{{h}}, {{s}}]"
        #set_effect:
        #  - service: light.turn_on
        #    data_template:
        #      entity_id:
        #        - light.ledvance_a19_rgbw_e1e40500_level_light_color_on_off
        #      effect: "{{ effect }}"
        supports_transition_template: "{{ true }}"
2 Likes

Did you ever discover the solution to this? I can’t discover how Home Assistant determines what color mode the light is in. I assumed there would be a color_mode_template but there is not. No matter what I do if I go look at the state attributes the “color_mode” is always “hs” and I can’t figure out how to change it to “color_temp”.

@James_Huang
Did you found a solution ?

1 Like

Same issue here.

Same issue. Has anyone found a solution?

I want to merge a relay and a led controller into a single light entity. Everything works except for this color_mode change.

If it’s any help, I reported it as an issue on GitHub. Light Template Cannot Change Color Mode · Issue #105902 · home-assistant/core · GitHub

the Github issue has been closed with “not planned” :frowning:

I have the same issue with IKEA bulbs that have supported_color_modes: color_temp and xy.

However, the issue does not exist for my Athom bulbs that have supported_color_modes: color_temp and rgb.
I use almost the same templated light as for the Athom bulbs and for those, it changes their color_mode state correctly to color_temp. No idea why though…

What’s the high-level use case (excuse me if I’m oblivious). Perhaps there’s a way to work around an integration limitation.

Ok, just found a working solution!
Instead of
hs_template: "{{ state_attr('light.bulbdm03', 'hs_color') }}"

I used

hs_template: >
  {% if is_state_attr('light.bulbdm03', 'color_mode', 'xy') %}
    {{ state_attr('light.bulbdm03', 'hs_color') }}
  {% else %}
  {% endif %}

So if the underlying bulb(s) is/are not in xy mode, the hs_color is also not set. This results in color_mode being correctly set to color_temp for the light template. I know I am mixing xy and hs in the template, but it works fine.

Again, this was not necessary for my Athom bulbs that support rgb (not xy), it worked out of the box in that template.

@d921
The use case is quite well described in @zolaktt’s Github issue: Light Template Cannot Change Color Mode · Issue #105902 · home-assistant/core · GitHub
Quote: “This results in the handle on the color temperature slider not being show, so you don’t really know what is the current temperature. You can see it while you set it, but then it disappears after you leave it alone.”

Not a huge deal overall, but some people like it neat :slight_smile:

You don’t need this part:

{% else %}

that was just me telling HA - you better work… OR ELSE! :wink:

I wish that would work :(.

Maybe you need

{# on penalty of death #}
1 Like

Yeah, I just saw that now. Great… If there is one thing I hate, it’s bots automatically closing Github issues. What are we supposed to do, post meaningless comments like “any updates?” every 2 days, just so the bot doesn’t close it… Then they will complain I’m spamming the thread…This sweeping problems under the rug approach is very frustrating, and quite honestly, insulting to users that actualy put in their time to investigate and report issues. No one has even looked at it, let alone replied…they just let it die.

Thanks for your workaround. I’ll give it a try.

UPDATE: It works great. Thanks. I just removed that else block. As already mentioned, it doesn’t do anything

1 Like