Generic MQTT Thing, Channel Color Value RGB

I’m using MQTT 2.4 and Paper UI.
Defined channel types swich, number and text are working well.
For a color channel it’s not clear for me to define the “Outgoing Value Format”.
Result should be "{color:{“r”:xxx,“g”:yyy,“b”:zzz}}
Input value from mqtt is i.e. “255,240,12”
How can I split up this value into three parts.
I know that I can use the input value multiple time using %1$…
For date format it’s clear, i.e. %1$td %1$tm %1$ty

I don’t think you can do this just within the Channel config. I think you will need a Rule or a JavaScript transform to achieve this. You can use the %1$ with DateTimeTypes because deep down it’s a standard Java DateTime and the %1$ stuff is all standard Java. HSBType is not a standard Java type like that so the String Formatter won’t be able to parse it like that.

A JavaScript transform seems your best bet.

This is a quite common request. I think I should allow more spaceholer symbols to address the different colour components (eg hue, saturation, brightness, red, green, blue).

I’ve not used JavaScript transformation so far. Is it possible within Paper UI or do I have to switch to Basic UI.
I’m familiar with JS but I don’t know where the starting point is to configure it. Some hints would be great.

This question belies a fundamental misunderstanding of the purpose of and how these parts of the system work.

PaperUI is an administration UI intended for the configuration of your OH instance. The Control tab, in so far as it lets you control some things, is strictly for testing things out. It is not intended to be used for actually using your home automation.

BasicUI is a UI that you configure using sitemaps to be used as the interface that you and your home’s users interact with to operate your home automation.

Except for installation of the transformation and what you type into the transformation field in the MQTT Channel config, neither one of these UIs have anything to do with JavaScript transformations. The docs are always the best first place to look.

It’s pretty easy, you just have to install the Javascript Transformation service in paper Ui under addons and than in the transformation tab. Next you have to create a .js file with your transformation in it and put it in the transformations folder which you find in the same spot where the folders for .items files and Co are.
This Transformation you can than use from paper Ui in the channel settings of your mqtt things.
It would probably look something like this (not tested):

(function(i) {

  var rgb = i.split(",");
  var color = {"r":rgb[0],"g":rgb[1],"b":rgb[2]}
  return JSON.stringify({color});


Hope this helped in case you hadn’t figured it out yourself yet :slight_smile:

Thanks to all of you. I got it working with different solutions.
Greate community, great procject.

I am having same issue,
I need to send color data into below format:

{“color”:{“r”: 46,“g”: 102,“b”: 193}}

but by default its sending

I found above solution of yours but not able to call by .js in paper UI, for setting channels outgoing format.

Thanks in advance.

Which version of openhab are you using? The outgoing transformations weren’t added to the mqtt2 binding till 2.5M1.

I am using
Embedded broker misc-mqttbroker - 2.4.0
binding-mqtt - 2.4.0

please let me know how can I upgrade.

How did you install openhab? In openhabian there is an option for it in the config for example.

I am using openhab installed over raspberry pi rasbian os.
Not using openhabian.

I am struggling to put this to work. Can you please share an example of your thing, item and how you manage to send "{color:{“r”:xxx,“g”:yyy,“b”:zzz}} ?

What have you tried?
@JGKK gives you a script example; you’d need to install JS transformation and configure your channel’s transformationPatternOut

Yes. I did. I have actually managed to send {“color”:{“x”:"",“y”:""}} and also {“color”: {“rgb”: “R,G,B”}}. So I would assume that my configuration is correct. But I am getting nowhere. I am getting “no converter available…” on both cases.
This is my zigbee2MQTT log:

Client mosqsub|30958-openHABia received PUBLISH (d0, q0, r0, m0, ‘zigbee2mqtt/LonsonhoSmartCandle02/set/color_xy’, … (59 bytes))
Client mosqsub|30958-openHABia received PUBLISH (d0, q0, r0, m0, ‘zigbee2mqtt/bridge/logging’, … (85 bytes))
{“level”:“error”,“message”:“No converter available for ‘color_xy’ ([object Object])”}

Oh okay. So your problem is that you don’t know what to send, but it’s not the format that this old thread was about, and also unlike it you are using zigbee2mqtt.
This looks helpful-

Based on the device information here Lonsonho ZB-RGBCW control via MQTT | , either one is supposed to work. So I was pretty sure of what to send. But your point is correct. And thanks for having taken the time.