[SOLVED] Rgb mqtt separate topics item

I have a rgb led bar spotlights but they controlled by simple mqtt each color have own channel. How I can write item? Or may be I need use transformation?
Some code examples will really help…
Best regards

This assuming that you have MQTT running, you know how to define Things and items and link them, etc; maybe this will help:

Not exactly your sue case, but there are formulas how to convert HSB to RGB.

1 Like

Thank for reply. My problem is my device accept simple mqtt payload not json mqtt. Each color have own topic RED have mosquitto/bar_node/pwm0, GREEN have mosquitto/bar_node/pwm1 and BLUE have mosquitto/bar_node/pwm2. Payload for topics is simple byte with pwm value 0-255. How it link to Color item?

You can’t. what you can do is create a Proxy Color Item and a Rule that sends a message to each of the three separate RGB topics.

The Color Item carries and HSBType which defines the color using Hue, Saturation, and Brightness. Luckily, HSBType has a getRed, getBlue, and get Green method.

1 Like

Thanks a lot. This is exactly what i want.!

@rlkoshak Now my system accept json with rgb data in one mqtt topic. I want to configure RGB chanel of Generic MQTT item using PaperUI interface. Json object with data is :

 "pwm": {  "0": 0,  "1": 0, "2": 0  },

where 0 1 2 color channels of rgb lamp.
I try write transformation in paperUI:

but this is does not work. Does it possible to configure my RGB chanel using paperUI and JSON transformation without using “hard” way with rules and proxies colors.

No because the Color Item uses HSB, not RGB. So even if that transform worked like that it would still be the wrong format.

But a more fundamental problem is you can only apply one JSONPATH transformation to get back a single value. You can’t get more than one value from the JSON using the JSONPATH transform. You can do it using the JavaScript Transform but that isn’t going to be any easier than using a Rule.

You need some code to both extract the three values and then converting those to HSB.

@rlkoshak thank you! What is the best way to do this? Add 3 number channels using JSONPATH and rule to convert this channels into HSB and postUpdate to my item?

I would do one of the following.

  1. Use the JS transform to process the whole JSON an extract the RGB values and convert them into HSB values, returning “HH,SS,BB” where HH is the hue number, SS the saturation number, and BB the brightness value.

  2. Have the Item be a String Item that receives the whole JSON as it’s state. When this Item changes, trigger a Rule which does the same calculations as described in 1 and send the calculated HSB to a Color Item that represents the light.

@rlkoshak i need the back function: publish mqtt json data after colorpicker item changed.
I have some difficulty with publishing json string.
In rules i write test command:


The Bar_Color_String updated to {“pwm”:{“0”:20,“1”:0,“2”:10}} in logs but she is not published to my topic.

This is my chanel config:

No, you’ve written postUpdate. If you want the MQTT binding to publish, you need to sendCommand
It’s a very important difference in openHAB.