HomeAssistant MQTT Component: RGBW Color channel set to trigger

Hello,

I have a running openHAB 3.3 with a bunch of different items. I’m trying to add my new zigbee devices. I’m using zigbee2mqtt and want to add the devices via autodiscovery of homeassistant topics. I have two PIR Sensor which were integrated without problem. Discover the device, slap a label on the thing and link new items to the channels. Works perfect.

But here is my problem: I have a RGBW strip from “Silvercrest” (LIDL for the german forum members). In the zigbee2mqtt webinterface ist works fine. I can set colors, switch it on and of and can check the link quality. If I add this device as a HomeAssistant MQTT Component the thing gets two channels: “color” and “linkquality”. The channel “linkquality” is a number channel and countains the value for the signal strength. The color channel is added as a trigger channel and I can not link an item to this channel. I expected I could add a color picker or something similar.

Here are some Screenshots of my configuration:

Thing config, Channel config and trying to link a new item, which I can’t because there is no profile available:


(Sorry for huge Screenshot, but I can’t split this image into multiple files. I’m not allowed to post more than one)

Can someone please explain, what I’m missing? Thanks!

I see the same behavior here on OH 3.3.0M3 - the channel is presented as a trigger channel, so no way to control the light.
The device I use is a Tuya RGB flood light that zigbee2mqtt recognizes as TS0505B, controlling it in the z2m UI is working fine.

The Thing in the code tab looks like this:

UID: mqtt:homeassistant_zigbee2mqtt_5F0xa4c138e6ad342e03:8498e3f762:zigbee2mqtt_5F0xa4c138e6ad342e03
label: Floodlight01 (Sensor, select, Light, Sensor)
thingTypeUID: mqtt:homeassistant_zigbee2mqtt_5F0xa4c138e6ad342e03
configuration:
  topics:
    - sensor/0xa4c138e6ad342e03/linkquality
    - select/0xa4c138e6ad342e03/effect
    - light/0xa4c138e6ad342e03/light
    - sensor/0xa4c138e6ad342e03/last_seen
  basetopic: homeassistant
bridgeUID: mqtt:broker:8498e3f762

Guess I have to link it manually into OH. Or did someone succeed and is willing to share the config?

I started with a friend to setup openhab. For zigbee we use zigbee2mqtt and homeassist for easy handling for him. Now we take into account that we can’t add some light as expected.
It’s a trigger channel that’s all. Is that an issue of zigbee2mqtt or openhab?

@Wikibear This is an issue with the mqtt binding in openHab. There are two possible workarounds for this problem, but both require manual configuration.

  1. Add a generic mqtt thing and add all needed channels by hand via the ui.
  2. Define a thing via text file, which is what I ended up doing.

Both approaches work fine, but it would be nicer to use the auto discover function.

Regards
Gewuerzwiesel

Yes, but that isn’t a solution for this issue. We take an easier way. All lamps stay in Phillips Hue Network.

Hi Thomas,
have you succeeded in creating a thing for a color light manually?
I still struggle with the channel definition and the required transformation.
Defining a color channel (mqtt-color) I do not get any color picker displayed (independent of the in detail config of the mqtt part).

The light is a floodlight with a TS0505B controller (at least it is detected as one).
In mqtt-Explorer i see f.e. the following JSON for this device:

{
   "brightness":119,
   "color":{
      "hue":0,
      "x":0.4105263157894737,
      "y":0.48947368421052634
   },
   "color_mode":"xy",
   "color_temp":252,
   "linkquality":102,
   "state":"OFF"
}

Similar problem with a Lidl E14 color bulb (TS0505A), did not succeed as well - they show a similar JSON in MQTT-Explorer.

Controlling the lights in z2m is working fine, so that part should be OK.

in OH switching on and off is not a big deal, but the color part itself gives be a pain in the back.

My channel definition for the color part looks like this, currently only trying to get the set part to work, so ignoring the state part:

channels:
  - id: color_xyY
    channelTypeUID: mqtt:color
    label: Color xyY
    description: ""
    configuration:
      commandTopic: zigbee2mqtt/Floodlight02/set
      colorMode: XYY
      formatBeforePublish: '{"color":{"x":%s,"y":%s},"brightness":%s}'
      stateTopic: zigbee2mqtt/Floodlight02/

Linked a color item to the channel and added it to a color picker cell in the MainUI:

component: oh-colorpicker-cell
config:
  item: FlutlichtRGB02_ColorxyY
  modules:
    - wheel

But the cell stays empty.

OH Version is 3.4.0 M1, system only has the mqtt stuff installed and this is the only thing active.
My main system shows the same behaviour, but to narrow things down this is my playground to get things working.

Seems there are many people struggling with this and there are multiple approaches to tackle it, but I have not see a complete information on how to configure it. I would happily create a proper how-to for it, but don’t know how to get it working on my own.

Is it possible that you post a working yaml of a color light thing and, if required, the transformation code files so I have a proper starting point?

Thanks
Thomas (as well :wink: )

Hello Thomas,
it took me quite some time to figure it out. It’s a combination of thing and item configuration as well as configuration of the RGBW controller. This should work on your light as well.

The JSON for my RGBW strip is the same as the one for your floodlight, so i think you can just copy & paste my code.

Step one is to make sure, that the color_temp attribute is not linked to the color attribute in your device. This is, because the color_temp values range from 150 to 500, but if these attributes are linked, the color_temp value can exceed this range. I have no idea why this is, but if you do not unlink them, the item for the color temperature will throw errors (because it gets sent values lower than 150 or higher than 500). So, go to the zigbee2mqtt webinterface and view the details of your device (Devices → Floodlight" → Settings (specific)) and deactivate color_sync.

Now you can add the thing. The definition misses the “effect” attribute for the light effects like blinking and fading. I didn’t need that so i skipped it. Here is the YAML code:

UID: mqtt:topic:RGBW3
label: RGBW3
thingTypeUID: mqtt:topic
configuration:
  payloadNotAvailable: offline
  payloadAvailable: online
  availibilityTopic: zigbee2mqtt/RGBW3/availability
  transformationPattern: JSONPATH:$.state
bridgeUID: mqtt:broker:e62cc6b6d3
channels:
  - id: status
    channelTypeUID: mqtt:switch
    label: State
    description: null
    configuration:
      retained: false
      postCommand: false
      formatBeforePublish: '{"state": "%s"}'
      commandTopic: zigbee2mqtt/RGBW3/set
      stateTopic: zigbee2mqtt/RGBW3
      transformationPattern: JSONPATH:$.state
      off: OFF
      on: ON
  - id: color
    channelTypeUID: mqtt:color
    label: Color
    description: null
    configuration:
      retained: false
      postCommand: false
      transformationPatternOut: JS:colorcsv2json.js
      formatBeforePublish: "%s"
      commandTopic: zigbee2mqtt/RGBW3/set
      colorMode: XYY
      stateTopic: zigbee2mqtt/RGBW3
      transformationPattern: JS:colorjson2csv.js
      off: "0"
      on: "1"
      onBrightness: 10
  - id: brightness
    channelTypeUID: mqtt:dimmer
    label: Brightness
    description: null
    configuration:
      retained: false
      postCommand: false
      min: 0
      formatBeforePublish: '{"brightness": %s}'
      max: 255
      commandTopic: zigbee2mqtt/RGBW3/set
      step: 1
      stateTopic: zigbee2mqtt/RGBW3
      transformationPattern: JSONPATH:$.brightness
      off: "0"
      on: "1"
  - id: color_temperature
    channelTypeUID: mqtt:dimmer
    label: Color Temperature
    description: null
    configuration:
      retained: false
      postCommand: false
      min: 150
      formatBeforePublish: '{"color_temp": %s}'
      max: 500
      commandTopic: zigbee2mqtt/RGBW3/set
      step: 1
      stateTopic: zigbee2mqtt/RGBW3
      transformationPattern: JSONPATH:$.color_temp
      off: "0"
      on: "1"
  - id: link_quality
    channelTypeUID: mqtt:number
    label: Link Quality
    description: null
    configuration:
      retained: false
      postCommand: false
      unit: "%"
      min: 0
      formatBeforePublish: "%s"
      max: 100
      step: 1
      stateTopic: zigbee2mqtt/RGBW3
      transformationPattern: JSONPATH:$.linkquality∩JS:lqi2percent.js

Well you have to change the bridge UID and MQTT topics to fit your devices, but otherwise it should be complete. And I convert the link quality to percentage, because everything else, at least in my installation, uses percentage but this attribute ranges from 0 to 255.

For completion you’re missing three files:

  • colorjson2csv.js
  • colorcsv2json.js
  • lqi2percent.js

These files have to be created in the directory <openhab_home_dir>/conf/transform
All scripts have a variable “logger” which you can use to log stuff to the openhab logfiles. My code could be shortened a lot but well, it works.

colorjson2csv.js

(function(i) {
        var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.transform.colorjson2csv');
        var colorFromMqtt = JSON.parse(i);
        var result = colorFromMqtt.color.x + "," + colorFromMqtt.color.y + "," + (colorFromMqtt.brightness/254*100);
        return result;
})(input)

colorcsv2json.js

(function(i) {
        var logger = Java.type('org.slf4j.LoggerFactory').getLogger('org.openhab.transform.colorcsv2json');
        var parts = i.split(',');
        var x = parseFloat(parts[0]);
        var y = parseFloat(parts[1]);
        var b = parseFloat(parts[2]);
        b = Math.floor(b/100 * 254);

        var response = { "color": { "x": x, "y":y }, "brightness":b };
        var result = JSON.stringify(response);
        return result;
})(input)

lqi2percent.js

(function(lqi) {
    return Math.round(((lqi / 255) * 100));
})(input)

Now after you have defined the MQTT thing, you need to create all items. That is straight forward and does not need any additional configuration or transformation, as everything is done by the thing itself.

If you have any questions, feel free to ask.

Regards
Thomas

2 Likes

Hello Thomas,

thanks for the complete thing, very much appreciated :+1: :clap: :clap:. This is a life and/or time saver for many struggling with the topic.

Unfortunately I still face the problem, that - no matter what kind of module I pick when creating the color picker cell in the UI - the cell stays empty.

The most simple cell definition I tried looks like this:

component: oh-colorpicker-cell
config:
  item: Flood02_Color
  modules:
    - wheel

The item Flood02_Color chosen is the one linked to the color channel of the Thing definition you provided (which in other channels works fine).

Channel linking:

Item definiton:

UI result:


If I set a label this gets displayed, but nothing related to the color channel.

So maybe I understood something fundamentally wrong (nothing I’d totally deny) or there is a bug somewhere in OH. I tend to vote for the first. Moving to M2 did not solve it.

Or do I need to link the picker to some different item and send the updates to the item linked to the channel using rule? Guess not, or?

Kind Regards
Thomas

Hello Thomas,

I remember having the same Problem. This is due to a bug in the color picker component. When the item has a value of NULL the color picker is not displayed.

You can try by setting a value in zigbee2mqtt with the item linked to the channel. Then the item should be updated with a valid value and the color picker should be displayed.

Regards
Thomas

2 Likes

Thomas, you are right, the picker is shown when using this workaround…

Remaining question is how to access the picker after e.g. a reboot of the system.
Z2m is not accessible for the user and OH itself does not show the picker. Somehow a dead end.
I fear that it is the accepted behaviour of the picker, but I’ll have a look if there is already an open issue on GitHub.

Thanks for your support!
Regards,
Thomas

Hello Thomas,

you could create a custom widget with color “favourites”. If the picker us not shown, you could at least click the buttons and set a favourite color, which then enables the color picker. I have to look into that how it could be done. I’ve seen UI examples that have a color picker and buttons for fixed colors. So it’s somehow possible.

Have to test a complete restart of openhab if all item state survive a reboot. Especially the color picker…

Regards
Thas

Maybe setting up persistence and recovering the state of the item when restarting could help, I will give it a try