Create a temperature changing light from 2 lights and Shelly RGBW2

Hi,
here is my issue.
I have a temperature changing led strip that is actually made of one warm whiote channel and one cold white channel. The relative brightness of these two channels controls the resulting white temperature.
Now, this strip is controlled by a Shelly RGBW2, which sees the strip as 2 independent light, where the brightness of each can be independently controlled. So in HA I see 2 different lights and I have to manually control their brightness.
Is it possible to create a single light in HA that is changing white temperature by controlling the relative brightness?

I hope I explained the issue clearly enough,
Thanks

Yeah, you can use a template light for that.

Oh, embarrassing how I missed that
Many thanks

I’m having the same problem as you are. I’ve got the Shelly setup in HA (using shelly integration, not MQTT) and can control the CW and WW channels individually, however I haven’t found a way to create a lovelace card that combines the two channels into a single light for which I can adjust the color temp & brightness.

If you’ve found a way to do this in lovelace via template lights as KTibow mentioned, could you share the yaml for your lovelace card?

Thanks

Yeah worked the math and still have to translate what I found into templates for all the configuration parameters.
In principle:

  • to read the status (on/off) it is sufficient to check that one of the values of the brightness of the two lights is grater than 0
  • to read the current brightness it must calculate the average of the two values of brightness.
  • to read the current temperature it must calculate the average weighted with the temperature of the two individual lights
  • to set the brightness and the temperature is a bit more complicated because you have to set the brightness according to two expressions that make the light match simultaneously both values.

Let me complete the translation of the equations in a configuration and I’ll share (after having tested!)

Cheers

1 Like

I had been thinking the sum of the two channels, but having max brightness be 200% and half brightness be 100% makes no sense. I agree the average is a better method.

Thanks for the pointers, I’ll give things a shot myself and share anything I come up with. Somewhat experienced with HA, but only recently have I started dabbling into the more advanced yaml writing things such as this.

Cheers

Here is the configuration I came up with:

light:
  - platform: template
    lights: 
      corrimano_u:
        friendly_name: "Corrimano"
        value_template: "{{ (state_attr('light.corrimano_caldo', 'brightness')|int + state_attr('light.corrimano_freddo', 'brightness')|int) > 0 }}"
        level_template: "{{ ((state_attr('light.corrimano_caldo', 'brightness')|float + state_attr('light.corrimano_freddo', 'brightness')|float)/2)|int }}"
        temperature_template: "{{ ((state_attr('light.corrimano_caldo', 'brightness')|float*6500 + state_attr('light.corrimano_freddo', 'brightness')|float*3000)/((state_attr('light.corrimano_caldo', 'brightness')|int + state_attr('light.corrimano_freddo', 'brightness')|int))) }}"
        set_level:
          - service: light.turn_on
            data:
              entity_id: light.corrimano_caldo
              brightness: "{{ (state_attr('light.corrimano_u', 'brightness')|int*2) * (6500-state_attr('light.corrimano_u', 'temperature')|int) / (6500-3000) }}"
          - service: light.turn_on
            data:
              entity_id: light.corrimano_freddo
              brightness: "{{ (state_attr('light.corrimano_u', 'brightness')|int*2) * (state_attr('light.corrimano_u', 'temperature')|int - 3000) / (6500-3000) }}"
        set_temperature:
          - service: light.turn_on
            data:
              entity_id: light.corrimano_caldo
              brightness: "{{ (state_attr('light.corrimano_u', 'brightness')|int*2) * (6500-state_attr('light.corrimano_u', 'temperature')|int) / (6500-3000) }}"
          - service: light.turn_on
            data:
              entity_id: light.corrimano_freddo
              brightness: "{{ (state_attr('light.corrimano_u', 'brightness')|int*2) * (state_attr('light.corrimano_u', 'temperature')|int - 3000) / (6500-3000) }}"
        turn_on:
          - service: light.turn_on
            data:
              entity_id: light.corrimano_caldo
          - service: light.turn_on
            data:
              entity_id: light.corrimano_freddo
        turn_off:
          - service: light.turn_off
            data:
              entity_id: light.corrimano_caldo
          - service: light.turn_off
            data:
              entity_id: light.corrimano_freddo

Where corrimano_caldo and corrimano_freddo are the warm and cold lights, respectively.
The temperatures 3000 and 6500 are hardcoded, replace to match yours. While I think the equations are right, the implementation is definitely not. As I can’t control correctly the template light.
I’ll continue experimenting, in the meantime if somebody notices what’s wrong with the above…