Set_color in template light does not work anymore:

Hi,

I was using this code to change color from webui of my template light:

        set_color:
          - service: light.turn_off
            data_template:
               entity_id: light.striscia_led_cucina_bianco
          - service: light.turn_on
            data_template:
              entity_id: light.striscia_led_cucina_rgb
              hs_color:
                - "{{ h }}"
                - "{{ s }}"

but with latest mayor update it is broken.

Can someone please give me a help?

Ty in advance!

I’m not sure the problem is simply due to indentation but try this version:

        set_color:
          - service: light.turn_off
            data:
              entity_id: light.striscia_led_cucina_bianco
          - service: light.turn_on
            data:
              entity_id: light.striscia_led_cucina_rgb
              hs_color:
                - "{{ h }}"
                - "{{ s }}"

same (negative) result unfortunately.

The “fun” thing is that there’s no error in the log!

Templates are typed (as of several versions ago), so make sure you’re passing numbers rather than strings to this script.

Do you mean something like this?

        set_color:
          - service: light.turn_off
            data:
              entity_id: light.striscia_led_cucina_bianco
          - service: light.turn_on
            data:
              entity_id: light.striscia_led_cucina_rgb
              hs_color:
                - "{{ h | int }}"
                - "{{ s | int }}"
    

Because I tried but nothing changed.

No, when you call this script you add variables to it. Something like

service: script.set_color
data:
  h: XXX
  s: YYY

I’m saying that XXX and YYY need to be numbers, not strings.

But I want to select color from WEBUI, not from yaml.

Up?

Does anyone know the correct way to use set_color in template light?

Maybe try:

          hs_color: "({{h}}, {{s}})"

full example:

      set_color:
        service: light.turn_on
        data:
          entity_id: light.rgb_strip_controler_6_1
          hs_color: "({{h}}, {{s}})"

@Jokerigno did you sort the issue?

@firstof9 a not entirely related question. Where can I read about lovelace card data points that can be passed as parameters. For example {{h}}, {{s}}, {{brightness}}, {{color_temp}}, {{effect}}. Are they standard or any card maker can define its own?

No idea, that’s more of a card/javascript thing than a template.

Below is what is working for me in both the UI and Google Home. Note that I only have the input-text so I can map a logical device to a physical device (because I keep moving things around).

    lily_mirror:
      friendly_name: "Lily Mirror"
      unique_id: light.lily_mirror
      value_template: "{{ is_state(states('input_text.lily_mirror_light'), 'on') }}"
      color_template: "{{ state_attr(states('input_text.lily_mirror_light'), 'hs_color') }}"
      supports_transition_template: "{{ false }}"
      turn_on:
        service: homeassistant.turn_on
        data_template:
          entity_id: "{{ states('input_text.lily_mirror_light') }}"
      turn_off:
        service: homeassistant.turn_off
        data_template:
          entity_id: "{{ states('input_text.lily_mirror_light') }}"
      set_color:
        - service: light.turn_on
          data_template:
            entity_id: "{{ states('input_text.lily_mirror_light') }}"
            hs_color: "[{{h}}, {{s}}]"

Hello @michaelblight !
I have a same problem: hs_colors sends data to my py script according to UI, but it works only with local variables (for example, I can’t send {{ brightness }} in the set_color).
I have started to use state_attr variables to send all the light states to my scripts, but hs_color doesn’t initialized in the attributes. However, it initialized if I use set_temperature in config, but it works only if I choose orange color in UI.
I have no ides why it happens.
Can you help me, please? I see only one principle difference between your and my config files: I haven’t color_template. If it can be the reason, tell me please what is input_text and where you define it and how?

My input_text is just a way of separating logical devices from physical ones because I sometimes move/update things and don’t want to update the code. Currently states('input_text.lily_mirror_light') is set to “light.controller_rgb_9dfa6a”. color_template just gets the current color. Since I am just creating a template light that is a ‘copy’ of another light, I am just getting its hs_color attribute. Similarly, when setting the color, I turn on the other light and pass the “h” and “s” parameters to hs-color.