Kelvin vs Mired

For a tunable white bulb, is it possible to send kelvin values instead of mired values to a MQTT server? I have my HASS connected to SmartThings and SmartThings will only accept kelvin values for the bulb color?

On the same subject, is it possible to send the Saturation vaules for a RGBW bulb? That appears to be how SmartThings is handling my color bulbs.

If you’re sending those values to SmartThings over the MQTT bridge, you may be out of luck. I’ve been watching another thread on here for quite some time, and so far it doesn’t appear that the MQTT light component will work with HSL color or Kelvin temp. Much of the problem lies with not being able to set separate value templates for the incoming and outgoing values, or publish multiple mqtt packets to specify hue saturation and luminance separately the way SmartThings wants.

Do you know of another way I can accomplish this while still leaving the bulbs on SmartThings?

Is it possible to accomplish this using an automation with MQTT templates? It seems like it should be, but I don’t understand JSON enough to make it work.

It seems like i should be able to take to mired command and send it to smartthings/light_name/miredcolorTemperature, get that data in an automation, perform math on it, and publish it to smartthings/light_name/colorTemperature.

Hey folks - I figured out a reasonably easy way to accomplish Mired to Kelvin conversions for inbound and outbound color temperature values with the MQTT Light component.

By using this custom component you don’t interfere with the operations of any of the other core python scripts - and it’ll persist updates. The only two lines which were changed are the lines concerning the acquisition of the color temperature payload value from MQTT and the outgoing value script for color temperature.

Color value templating still works as needed, but is unnecessary for the purposes of this component - your MQTT payload is assumed to be kelvin, and the milred value HA generates will be converted to Kelvin before it goes to MQTT.

I’ll check it into github when I get the chance, but you’ll just need to create the directory structure ‘/custom_components/light/’ within your HA config directory - and update your kelvin-using MQTT lights to “platform: mqtt_light_kelvin”

1 Like

Hi This is great. Can you post a sample configuration. I cant seem to control the color temp after adding the new script.

 - platform: mqtt_light_kelvin
    name: "Left Lamp"
    state_topic: "smartthings/Left Lamp/switch"
    command_topic: "smartthings/Left Lamp/switch"
    brightness_state_topic: "smartthings/Left Lamp/level"
    brightness_command_topic: "smartthings/Left Lamp/level"
    color_temp_state_topic: "smartthings/Left Lamp/colorTemperature"
    color_temp_command_topic: "smartthings/Left Lamp/colorTemperature"
    color_temp_value_template: "{{ (1000000/float(value)) | int }}"
    state_value_template: "{{ value_json.state }}"
    brightness_value_template: "{{ value_json.brightness }}"
    rgb_value_template: "{{ value_json.rgb | join(',') }}"
    payload_on: "on"
    payload_off: "off"
    optimistic: false
    retain: false

this seems like something using NodeRed would be useful for? What the conversion rates?

hmm… added mqtt_light_kelvin.py to

core-ssh:/config/custom_components/light

but using mqtt_light_kelvin my device disappears. There sure is a lot of broken sh*t on this platform.

Posting here as well for visibility/future searchers.

Here’s the latest version I’m running on .77.3 - the two tweaks are annotated in the code.

Is it possible to get this updated for 0.84.5? It appears that something changed as others are reporting similar issues with other custom components. Here is the error I’m getting:

2018-12-20 22:06:42 ERROR (MainThread) [homeassistant.loader] Error loading custom_components.light.mqtt_light_kelvin. Make sure all dependencies are installed
Traceback (most recent call last):
  File "/usr/src/app/homeassistant/loader.py", line 92, in get_component
    module = importlib.import_module(path)
  File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/config/custom_components/light/mqtt_light_kelvin.py", line 27, in <module>
    from homeassistant.helpers.restore_state import async_get_last_state
ImportError: cannot import name 'async_get_last_state'
2018-12-20 22:06:42 ERROR (MainThread) [homeassistant.loader] Unable to find component light.mqtt_light_kelvin

Here’s a couple other posts showing similar errors:

I tried changing the ‘async_get_last_state’ to ‘RestoreEntity’ on my own, however I got errors about line 229 saying async_get_last_state was not defined. So there’s something else that needs to be done, but I’m not proficient in Python at all so I’d have no idea where to start.