Mqtt light template add color_mode

I am trying to implement configuration for fhem rgbww controllers https://forum.fhem.de/index.php/topic,48918.msg619462.html#msg619462 (in german language).
Those controllers are mainly designed for usage with fhem, but also capable to be used with mqtt.
The best color model is hsv.
When using them with HA, mqtt light template is the best option, but this does not present a color selector in the UI and makes the thing pretty uncomfortable (see also here: https://community.home-assistant.io/t/use-hs-color-for-mqtt-light-template/261014 ).
So it would be REALLY helpful if HA mqtt templates could also support color_mode.

Updated: fhem-url

That link doesn’t work, BTW. You should edit it. This one works
I did manage to get to the link and keep in mind that is another newbie trying to find their way. There are a lot of ways to template MQTT completely different than that.

I also have written a color helper custom template that can do color conversions for you, linked it up there and here.

I suggest you add an example of what you are trying to do here in order to get better help from the template experts…

Thanks for that! Of course I did not know that.

Well, what I want to achieve is pretty simple. I have a mqtt-driven light which wants to get hsv values.
Unfortunately, the way I tried to set it up does not show a color-picker.

This is my yaml (mainly copied from the link above):

- name: "ez_espled_nischen"
    unique_id: ez_espled_nischen
    schema: template
    effect_list:
      - blink
      - pause
      - stop
      - continue
      - skip
    state_topic: "rgbww_ez_nischen/espled_ez_nischen/color"
    brightness_template: "{{ (value_json['hsv']['v'] / 100 * 255) | int }}"
    color_temp_template: "{{ (value_json['hsv']['s'] | int)  + 1 }}"
    command_topic: "rgbww_ez_nischen/command"
    command_on_template: >
      {"jsonrpc":"2.0","method":"color","params":{"hsv":{
      {%- if color_temp is defined -%}
      "s":{{ color_temp - 1 }},
      {%- else -%}
      "s":"0.00",
      {%- endif -%}
      {%- if white_value is defined -%}
      "h": {{ white_value / 255 * 360 }}
      {%- else -%}
      "h":"0.00"
      {%- endif -%}
      {%- if brightness is defined -%}
      ,"v":{{ (brightness / 255 * 100) | int }}
      {%- else -%}
      ,"v": 100
      {%- endif -%}
      ,"ct":2700},"d":"1","q":"single"
      {%- if transition is defined -%}
      ,"t":{{ transition * 1000 }}
      {%- else -%}
      ,"t":1000
      {%- endif -%}
      ,"cmd":"fade"}}
    command_off_template: >
      {"jsonrpc":"2.0","method":"color","params":{"hsv":{"h":"0.00","s":"0.00","v":0.00, "ct":2700},"d":"1","q":"single"
      {%- if transition is defined -%}
      ,"t":{{ transition * 1000 }}
      {%- else -%}
      ,"t":1000
      {%- endif -%}
      ,"cmd":"fade"}}
    min_mireds: 1
    max_mireds: 101
    state_template: >
      {%- if value_json["hsv"]["v"] == 0.00 -%}
      off
      {%- else -%}
      on
      {%- endif -%}

If it was not a template but a json, I could simply add a color_mode: true, but the template schema does not allow this.
As @Sir_Goodenough mentioned, there should be other ways to implement what I need - it would be very kind if some of the experts could give me a hint or two :slight_smile:
Best regards and thanks in advance,
Otto

Do you maybe have some hints please @Sir_Goodenough ?

Slowly I am getting a little bit desperate. Change was denied, seems that none of the experts is able or willing to help :frowning:

Thanks. I know this, but it does not help me. The device needs json like this:

{
      "jsonrpc" : "2.0",
      "method" : "color",
      "params" : {
        "hsv" : {
          "h" : "0.00",
          "s" : 100,
          "v" : 0,
          "ct" : 2700
        },
        "cmd" : "fade",
        "t" : 700
      }
}

I could not find a possibility to use this format with mqtt light default schema due to the strange format (in addition there is no on and off, it is only set by brightness).
And when using template schema, there is no color selector in HA UI.
So, if there are any suggestions I would be more than happy to try them…
Best regards and thanks in advance,
Otto

You are asking for third party support for some device no one has and is described in a German language post.
What this has to do with a Feature request, I have no idea.
Nor do I understand your device or what you are trying to do. Youlatched onto another new users attempt at an MQTT command that may ot may not do what you thionk you want to do.

I think the reason you are not getting the help you need is that no one understands what equipment you have what you have tried, and what you want to do with it.

Are you using an ESP device and want to have MQTT discovery pull in the light component? That’s my best guess. And that’s not going to happen with that MQTT topic. The device itself has to send a topic to the correct path so HA sees it and in the schema listed above in order for you to get the light features HA has available. The only way around that is use an integration (custom or otherwise) that will translate what the device wants to the data format that HA wants.

Now with a lot of patience, you could pull the data into HA as is, translate it, use MQTT Discovery topics to create HA entities, and use that conversion autmation to make the lights work. It is not impossible, but is very specific and something you have to do on your own at least to the point you have something you can ask questions about.
We are volunteers, not staff, not official support people. If you have a question or want help, we expect you to have an idea on what is going on and have a bunch of the easy problems solved and be halfway towards your goal. This helps us help you.

How to help us help you - or How to ask a good question.

Well, I do really not know how to describe the problem more specifically.
I think you did not really read what I wrote. Probably it is not really interesting for you as I am a newbie.
Please dont tell me anything about volunteers, I am VERY aware of open source software and I have been using and developing since about 30 years now. But the way YOU are acting is a way people (especially newbies) can be driven back to commercial products. Please dont misunderstand me, I am happy to use products like HA and would be happy to contribute (my python is not too bad) - but at the beginning I really would like to understand the stuff I am using.
Maybe I am also wrong using HA with “helpers” like you. Bad thing.
The way you are acting is really, really annoying. Instead of asking specifically for more information (I do not really know what to add to my desperate questions) you are telling me that nobody is interested to help as the thing I want is too specific and not interesting.
This is really very kind, but not helpful. I am used to different manners especially in the open source community.
Now, please block me as the mighty admin you are.

dear home assistant community,

I’ve been pointed to this discussion. I am the current maintainer of the firmware in question here.
Looking at the available documentation, I assume that we are at a bit of an impass on how Home Assistant and my firmware implement mqtt.
It seems that HA primarily uses topics to convey state and direct state changes (commands) while we implemented a json-rpc interface over mqtt, basically sending and receiving api calls.
At this point, certainly nobody expects autoconfig for those LED lights, but would it be possible for HA to generate mqtt messages like this?

{
  "jsonrpc":"2.0",
  "method":"hsv",
  "params":
  {
    "h":<hue[0-360]>,
    "s":<sat[0-100%]>,
    "v":<val[0-100%]>
  }
}

I can see that the fact that HA treats hue/sat seperately from val to be an issue but the firmware also accepts partial updates, so omitting any of the three parameters should be fine.

The real plus for using this “custom” firmware (which firmware isn’t) is that it does 10Bit pwm on ESP8266 and 50Hz “frames” and thus provides really smooth fades all the way to off, I’m not aware of any other firmware providing this on that platform.
also, we have about 1500-2000 devices running it in the fhem community alone.
I’m currently doing a major rewrite to (finally, took us a while) also support the Esp32 (xtensa and RISC-V) and extend the functionality. Since HA seems to be the current darling of people doing home automation, it would be great to achieve functional parity to what we have in fhem - I’m ok with implementing an alternative mqtt interface that is state rather than command oriented, but I want to explore if HA maybe can deal with the current format without major efforts.

best

pj

2 Likes