Set brightness AND temperature/color of template light

Hey guys,

I created a dummy light via template light, which basically controls and mimics a real light (see code at the bottom). This works well, I can set a brightness or a light temperature or a light color (which seems to be a somewhat new function, as this was not a feature a couple of months ago) via the Home Assistant developer tools, for example:

service: light.turn_on
data:
  entity_id: light.living_kitchen_dummy
  brightness: 200

service: light.turn_on
data:
  entity_id: light.living_kitchen_dummy
  kelvin: 2500

service: light.turn_on
data:
  entity_id: light.living_kitchen_dummy
  color_name: red

All of those change my real light.living_kitchen appropriately. Other commands such as hs_color or rgb_color work as well. But changing two attributes at the same time apparently does NOT work, eg:

service: light.turn_on
data:
  entity_id: light.living_kitchen_dummy
  color_name: red
  brightness: 200

The brightness gets changed accordingly, but the color or temperature gets entirely ignored. If you look at my code at the bottom, I created input booleans to investigate, which “service” gets called on the dummy light if I want to change two attributes at the same time. I can confirm, that in this case only the set_level service of the template light gets triggered. I tried to also put an hs_color template into the set_level service, but I could not get this to work.

So, has anyone an idea how to solve this problem?

A little bit of background: I do this to eventually change the turn_on service of the dummy light to activate a script. Then I will expose the dummy light to google home and ideally I would be able to change the lights brightness and color via voice commands, but a simple “Hey google, turn kitchen on” would activate the script. Unfortunately, google apparently sends a color AND a brightness when setting a color via voice or app, which leads to the problem.

light:
  - platform: template
    lights:
      living_kitchen_dummy:
        friendly_name: "Kitchen Dummy"
        level_template: "{{ state_attr('light.living_kitchen', 'brightness') | int }}"
        value_template: "{{ is_state('light.living_kitchen', 'on') }}"
        temperature_template: "{{ state_attr('light.living_kitchen', 'color_temp') }}"
        color_template: "{{ state_attr('light.living_kitchen', 'hs_color') | float}}"
        turn_on:
          - service: light.turn_on
            entity_id: light.living_kitchen
          - service: input_boolean.toggle
            entity_id: input_boolean.turnon_boolean
        turn_off:
          service: light.turn_off
          entity_id: light.living_kitchen
        set_level:
          - service: light.turn_on
            data_template:
              entity_id: light.living_kitchen
              brightness: "{{ brightness }}"
          - service: input_boolean.toggle
            entity_id: input_boolean.bright_boolean
        set_temperature:
          - service: light.turn_on
            data_template:
              entity_id: light.living_kitchen
              color_temp: "{{ color_temp }}"
          - service: input_boolean.toggle
            entity_id: input_boolean.temp_boolean
        set_color:
          - service: light.turn_on
            data_template:
              hs_color:
                - "{{ h }}"
                - "{{ s }}"
              brightness: "{{ brightness }}"
              entity_id: light.living_kitchen
          - service: input_boolean.toggle
            entity_id: input_boolean.color_boolean
2 Likes

Try it like this:

service: light.turn_on
entity_id: light.living_kitchen_dummy
data:
  color_name: red
  brightness: 200

Sorry, tried this and it does not work either. It also sets only the brightness.

1 Like

Sounds familiar. Are you using Tradfri by any chance? They only accept 1 call at a time, either brightness or color but not both in one call. In my template light I compensate for this by calling brightness, then a 3 second delay, then color.

I am using a Philips Hue lightstrip. If I address the lightstrip itself (light.living_kitchen) through the developer tools, i can set brightness and color at the same time. Only via the template this is not working.

I can confirm, that only the set_value service gets exexuted while the set_color service does not even get called, when setting brightness and color to the template light. To me this looks like a bug/missing-feature, but maybe I do overlook something?

1 Like

I think you might be right. You might want to raise an issue on Github.

Found the issue #34915 relating to this bug, which also has a proposed and actively discussed approach with #36353.

2 Likes

Did you ever find any workaround for this? I’m struggling with the same issue. Google assistant cannot change the colours of a light template.