Creating a template light, trying to figure out how to do color temperature

I have an RF controlled ring light in my studio, I want HA to control it.
I’ve created a template light:

    ringlight:
      friendly_name: "Studie Ringlys"
      turn_on:
        - service: remote.send_command
          data:
            entity_id: remote.office_sender
            device: ringlight
            command: toggle
      turn_off:
        - service: remote.send_command
          data:
            entity_id: remote.office_sender
            device: ringlight
            command: toggle
      set_temperature:
        service: remote.send_command
        data_template:
          entity_id: remote.office_sender
          command: >
            {% if temperature | int < 33%}
              coldwhite
            {% elif temperature | int >=33 and brightness | int < 66%}
              warmwhite
            {% else %}
              verywarmwhite
            {% endif %}
          device: ringlight
      icon_template: mdi:camera-iris

Unfortunately the remote does not have an on/off, only a toggle.
The light has color and whites, and for now I just want the whites to be controlled.
I have cold, warnwhite, verywarmwhite defined as remote commands.
Being an RF433 light there is no reporting back, so all is ‘optimistic’
I tried doing the above, the idea was that it could translate a value for temperature into these three discreet levels, but that doesn’t work, ‘temperature’ is unknown. So what to do?

{{ color_temp }}} ?

1 Like

From HA Doc -Template Light:

image

Thankyou for the suggestions @armedad and @Didgeridrew

Entering

          command: >
            {% if color_temp | int < 1000}
              coldwhite
            {% elif color_temp | int >=1000 and brightness | int < 2000}
              warmwhite
            {% else %}
              verywarmwhite
            {% endif %}

got me a new error:

Invalid config for 'template' from integration 'light' at light.yaml, line 34: template value should be a string for dictionary value 'lights->ringlight
>set_temperature->0->data_template', got None

I also tried enclosing color_temp in {{}} but that didn’t help :frowning:

You’re now missing a % at the end of your if and elif lines.

You had them before but because you spaced them like 33%} you would have unintentionally read it as 33% } and removed them when you edited it.

Leave a space:

{% if x %}

Always try out your templates in Developer Tools / Template before committing them to the config:

That last one, just for fun, is:

{% set c,b = color_temp|int, brightness|int %}
{{ { c<1000: 'cold', c>=1000 and b<2000: 'warm' }.get(true, 'verywarm')~'white' }}
1 Like

Wow @Troon
That’s what editing gets you late at night, darned, thankyou very much.

I got it working now with temperature (the brightness was a miss, it was supposed to be color_temp):

    ringlight:
      friendly_name: "Studie Ringlys"
      turn_on:
        - service: remote.send_command
          data:
            entity_id: remote.office_sender
            device: ringlight
            command: toggle
      turn_off:
        - service: remote.send_command
          data:
            entity_id: remote.office_sender
            device: ringlight
            command: toggle
      set_temperature:
        service: remote.send_command
        data_template:
          entity_id: remote.office_sender
          command: >
            {% if color_temp | int < 212 %}
              coldwhite
            {% elif color_temp | int >=212 and color_temp | int < 312 %}
              warmwhite
            {% else %}
              verywarmwhite
            {% endif %}
          device: ringlight
      icon_template: mdi:camera-iris

and of couse with your very clever compression it also works:

    ringlight:
      friendly_name: "Studie Ringlys"
      turn_on:
        - service: remote.send_command
          data:
            entity_id: remote.office_sender
            device: ringlight
            command: toggle
      turn_off:
        - service: remote.send_command
          data:
            entity_id: remote.office_sender
            device: ringlight
            command: toggle
      set_temperature:
        service: remote.send_command
        data_template:
          entity_id: remote.office_sender
          command: >
            {% set c = color_temp|int %}
              {{ { c<212: 'cold', c>=212 and c<312: 'warm' }.get(true, 'verywarm')~'white' }}
          device: ringlight
      icon_template: mdi:camera-iris

That is very nice, of course as soon as it goes ‘out of sync’ with on/off state, all hell breaks loose, but I’m trying to find out if I can measure the powerdraw, and make an assumption from that if it is on or off, but at least now I can make sure the ringlight is set properly when I set up studio lights here, thankyou!