Unable to convert value from MQTT light mired to kelvin

 - platform: mqtt
name: "Living Room Couch Light"
command_topic: "smartthings/LIFX livingroom/switch"
state_topic: "smartthings/LIFX livingroom/switch"
brightness_state_topic: "smartthings/LIFX livingroom/level"
brightness_command_topic: "smartthings/LIFX livingroom/level"
color_temp_state_topic: "smartthings/LIFX livingroom/colorTemperature"
color_temp_command_topic: "smartthings/LIFX livingroom/colorTemperature"
brightness_scale: 100
payload_on: "on"
payload_off: "off"
retain: true
color_temp_template: "{{ (((value-153) * ( 9000 - 2700)) / (500 - 153)) + 2700 }}"

I tried the above config, with the math being "old value - old min, * new max - newmin) / old max - old min) (see this SO link which should convert mired to kelvin (even if the color bars are in revers).

but when I reload the configuration and try adjusting the slider, I still see see mired values being passed to mqtt bridge:

info: Incoming message from MQTT: smartthings/LIFX livingroom/colorTemperature = 500
info: Skipping duplicate message from: smartthings/LIFX livingroom/colorTemperature = 500
info: Incoming message from MQTT: smartthings/LIFX livingroom/switch = on
info: Skipping duplicate message from: smartthings/LIFX livingroom/switch = on
info: Incoming message from MQTT: smartthings/LIFX livingroom/colorTemperature = 186
info: Incoming message from MQTT: smartthings/LIFX livingroom/switch = on
info: Skipping duplicate message from: smartthings/LIFX livingroom/switch = on
info: Incoming message from MQTT: smartthings/LIFX livingroom/colorTemperature = 153

am i doing something wrong, or is it completely impossible to translate to kelvin? this seems like a flaw in the design of HA, since most bulbs have a kelvin value. Thanks in advance

You’ll need to convert the value from string to number.
try this:

color_temp_template: "{{ ((((value | int) - 153) * ( 9000 - 2700)) / (500 - 153)) + 2700 }}"

Thanks. Tried that, but still only getting mired values:

info: Incoming message from MQTT: smartthings/LIFX livingroom/colorTemperature = 336
info: Incoming message from MQTT: smartthings/LIFX livingroom/switch = on
info: Skipping duplicate message from: smartthings/LIFX livingroom/switch = on
info: Incoming message from MQTT: smartthings/LIFX livingroom/colorTemperature = 224
info: Incoming message from MQTT: smartthings/LIFX livingroom/switch = on
info: Skipping duplicate message from: smartthings/LIFX livingroom/switch = on

If I change it from the smartthings app, I get values in that look correct:

info: Incoming message from SmartThings: smartthings/LIFX livingroom/colorTemperature = 6314
info: Incoming message from MQTT: smartthings/LIFX livingroom/colorTemperature = 6314
info: Skipping duplicate message from: smartthings/LIFX livingroom/colorTemperature = 6314

There has to be a way to force values back out rather than what the slider is providing, is there some debug log i can turn on or something? maybe it should be “value.color_temperature” or something and not just value…

I’ve only added the Int, I’ve not actually checked the validity of your formula.
Having had another look, you’ve defined color_temp_template yet the docs define this as color_temp_value_template?

Crap… failure to read properly late at night :slight_smile:

just re-read light.mqtt and you’re right…let me try changing that.

1 Like

Mired to Kelvin is just {{ 1000000/mired }}.

1 Like

well that didn’t work… looking at states, maybe the attributes have something to do with it

min_mireds: 153
max_mireds: 500
brightness: 135
color_temp: 150
friendly_name: Living Room Couch Light
supported_features: 3
entity_picture: /local/lifx.png

maybe instead of value, i need value.color_temp? or something

I saw that on another post too, im figuring out how to convert the output that goes back out to mqtt into kelvin… are you saying it should be:

color_temp_value_template: {{ 1000000/mired }} ?

Eh, I only know about the conversion, not mqtt. It seems like maybe it is command_on_template that you have to set for outgoing messages.

I’ll look into that. Thanks…for now i found this which seems that it was never solved… with the template i posted aove the slider moves when i change kelvin in smartthings app, but it doesn’t work in reverse, still get mired values being sent out.