MQTT Light Outgoing Template?

Hello All,

I’m new to Home Assistant/MQTT and all this other wonderful HA stuff. I’m having some trouble getting a light to work via MQTT.

Here’s my setup:

I have Hue Bulb (connected via ST Hub).
HA is running on Raspbian Jessie using the one-click installer. The only mod is that I switched to mysql db.
ST is connected to HA via ‘smartthings-mqtt-bridge’, which I have running in the background.

I have a Hue Bulb configured as a mqtt_light:

light:
  - platform: mqtt
    name: 'Living Room Light'
    state_topic: "smartthings/Living Room Lamp/switch"
    command_topic: "smartthings/Living Room Lamp/switch"
    brightness_state_topic: "smartthings/Living Room Lamp/level"
    brightness_command_topic: "smartthings/Living Room Lamp/level"
    brightness_scale: 100
    rgb_state_topic: "smartthings/Living Room Lamp/color"
    rgb_command_topic: "smartthings/Living Room Lamp/color"
    color_temp_state_topic: "smartthings/Living Room Lamp/colorTemperature"
    color_temp_command_topic: "smartthings/Living Room Lamp/colorTemperature"
    color_temp_value_template: "{{ (1000000/float(value)) | int }}"
    payload_on: "on"
    payload_off: "off"
    retain: true

MQTT messages are being successfully sent from HA -> ST.
MQTT messages are being successfully received from ST -> HA.

The problem I am trying to figure out right now is the color temperature situation. From what I read here on the forums is that HA uses the Mired scale. Well, the Hue on ST uses the Kelvin scale. I am able to use templating to convert the incoming Kelvin scale to the Mired scale for HA.

However, I don’t know how to convert the outgoing Mired scale to Kelvin for ST. Yes, I know, just divide it by 1e7 again. But I don’t know where to plug this in. The documentation for MQTT_Light shows color_temp_value_template but from what I gather, that is the templating for incoming data, not outgoing.

Any ideas?

Thanks

I’m running into the same issue with Osram lights, smarthings hub.

Me too. Sylvania Lightify RGBW Bulbs, SmartThings Hub using MQTT bridge. I feel like I’m going to run into the same issue with the RGB side of things too, since the Lightify bulb expects /hue and /saturation topics.

Did anyone get anywhere with this?

edit: looks like there is a PR … hopefully it makes its way to the next release

https://github.com/home-assistant/home-assistant/pull/5105

I have a POC mqtt light component I worked on last night, that does color temp + colors. LMK if you still interested

1 Like

Definitely interested! I’d love to try it out!

Hi. I have a similar question, so I thought I’d add here rather than post a fresh topic…
I need to set a particular format for brightness changes, like:
$hardware/status/reset {"brightness": 89}
but my HA MQTT light sends just:
$hardware/status/reset 89

So all I need is to wrap that brightness value in a string…
I found mqtt_template light platform, but it only has on/off templates, not templates for other outgoing commands like brightness.

Is this just not possible at the moment, or am I missing something to make it possible?

Jared,
Where did you end up landing with this? I’m considering making a PR for a new MQTT Light component that supports the hue/saturation channels since I’m in the same boat. I would love to see your code if you have it pushed somewhere.

I also started a GitHub issue to get feedback before I start my own endeavor.

1 Like

I got colors working but it was shit because you have to send both hue and sat and st can’t handle both at the same time.

Bought a 30$ Lightify hub and called it a day since it already had ha integration

could you please elaborate what you have done? as far as I can see there is no HSL in mqtt yet - as I am also using ST I am surely interested in getting this to work

I’ve just run into this problem with colour temperature - is there a solution yet?

So far, I’ve got:

light:
platform: mqtt
name: “Landing Lamp”
state_topic: “smartthings/Lamp Landing/switch”
command_topic: “smartthings/Lamp Landing/switch”
brightness_state_topic: “smartthings/Lamp Landing/level”
brightness_command_topic: “smartthings/Lamp Landing/level”
brightness_scale: 100
color_temp_state_topic: “smartthings/Lamp Landing/colorTemperature”
color_temp_command_topic: “smartthings/Lamp Landing/colorTemperature”
payload_on: “on”
payload_off: “off”
retain: true

Did anyone ever come up with a solution for this problem?

I modified the mqtt.light platform and made a custom component - that way you don’t need to alter core scripts.

The only quirk is that the mired values HA uses goes down to 2000 Kelvin equivalent. Assigning a value lower than the 2700 my bulbs use just results in the bulbs going to 2700 and the slider’s effective minimum isn’t absolute 0 on the slider.

Doesn’t work for me. Device disappears if I use platform: mqtt_light_kelvin. Waste of time.

This post is very old, and the mqtt light component that my example is built off is equally as old. It will not work on newer versions.

However, the change to the code remains the same to this day. I can post my most recent version, I think I’m a few versions back. it’s as easy as copying my modifications to the same spot in the most recent version of the mqtt light code

Unless someone wants to integrate this into the platform, perhaps with a conditional flag on the devices themselves for this conversion, it will remain clumsy. I’m not really source savvy.

Could you post it? thanks! Oh… so you’re mod is just a copy of mqtt light with the changes? ok…cool.

Note that I’ve annotated the two tweaks to the default mqtt_light.py component with the flag “#MODIFICATION

If you apply those same tweaks, to the same parts of any more recent version of mqtt_light.py, it should still work fine.

I’m running .77.3 with the version in my github.