So, my guess is it’s a percent value from 0 to 100?
I would just create 2 MQTT sensors looking at those states and 1 MQTT light that does everything else.
Then I would use a template light to combine the 3 things. For all templates, just refer to the MQTT light values. For temperature, here is where you would combine them.
Your job now is to translate those numbers to a kelvin value. For example, I would assume
zway/walls_sw = 30
zway/walls_cw = 99
Means the cool color is max brightness, and the soft color is 30% brightness? Thus, temperature would be defined by the ratio of the 2 values and brightness would be the sum. We just need to know the Kelvin of the soft and cool white.
Here’s my guess. It’s probably wrong. Calculate the ratio, then subtract the difference. Take the ABS.
temperature_template: >
{% set c = states('sensor.cool_white') | int %}
{% set w = states('sensor.soft_white') | int %}
{% set avg = (c + w)/2 %}
{% set cr = c / avg %}
{% set sr = w / avg %}
{{ (5000 * cr - 2000*sr) | abs }}
Quick test:
Cool 100%, Soft 0% --> 5000k
Cool 100%, Soft 100% --> 3000K
Cool 50%, Soft 50% --> 3000K
Cool 0%, Soft 100% --> 2000K
Going the other way is going to be trickier. We know the brightness from the brightness topic, so we have 2 equations and 2 unknowns. You’d have to calculate the soft and warm components given brightness and temp.
lights:
example_light:
friendly_name: "Example Light"
level_template: "{{ state_attr('light.mqtt_light', 'brightness') }}"
value_template: "{{ states('light.mqtt_light') }}"
# Convert the 2 separate MQTT sensors to one temperature.
temperature_template: >
{% set c = states('sensor.cool_white') | int %}
{% set w = states('sensor.soft_white') | int %}
{% set avg = (c + w)/2 %}
{% set cr = c / avg %}
{% set sr = w / avg %}
{{ (5000 * cr - 2000 * sr) | abs }}
turn_on:
service: light.turn_on
entity_id: light.mqtt_light
turn_off:
service: light.turn_off
entity_id: light.mqtt_light
set_level:
service: light.turn_on
entity_id: light.mqtt_light
data:
brightness: "{{ brightness }}"
set_temperature:
- variables:
cool_value: "{{ <function to calculate cool value> }}"
soft_value: "{{ <function to calculate soft value> }}"
- service: mqtt.publish
data:
topic: "zway/walls_sw"
payload: "{{ soft_value }}"
- service: mqtt.publish
data:
topic: "zway/walls_cw"
payload: "{{ cool_value }}"