Colorpicker and Color item Pushstart (Please help)

Hello, I have been with openhab 2 for several weeks now, and I have managed to do a few things already…
Thing is, documentation is either too advanced or extremely poor. And I have been looking for a tutorial on how to control my LED strip through MQTT but found almost nothing.

I would like somebody helped me to understand the color item as well as the Colorpicker widget and the neccessary rules to make it work. I do not know the format Colorpicker sends the command, I don’t know how to make a Color item understand that output and neither how to send those commands…

What I do know is how MQTT binding works(more or less) and the Arduino part of the code. So please, give me a pushstart on this!

I am willing to pay for the tutorial… Seriously, it is impossible to find the info elsewhere and it would be invaluable material for me. I am just really looking forward to learning openhab2 but all I find is outdated, poor or advanced info. Thank you.

First, I’ll assume you have gone through the Beginner’s Tutorial. If not go there now. This will help you understand the basic parts of OH and how they work together.

The Color Item contains three numbers which represent the color state of a light. The Color Item can also act like a Dimmer or a Switch. Thus the following is valid:

Item

Color MyColorLight { mqtt="blah blah blah" }

Sitemap

Switch item=MyColorLight // treats MyColorLight as a simple ON/OFF switch
Slider item=MyColorLight // treats MyColorLight as as dimmer
Colorpicker item=MyColorLight // treats MyColorLight as a Color

You can have all three on the sitemap at the same time.

Internally each Item has a State. For a ColorItem, the State is an HSBType. This stores the state of the light as three numbers: hue, saturation, and brightness.

When you send an OFF (i.e treat the light as a Switch) it sets all three values to 0. When you treat it as a Dimmer it only changes the brightness value. When you treat it as a Color the hsb values that represent the color selected on the Colorpicker are used to update the hsb values in the ColorItem.

Whenever a ColorItem’s (or any Item’s) state changes that triggers the MQTT binding (if appropriately configured) the new state gets published on the MQTT topic. In the case of the ColorItem, I would expect (I don’t use this type of Item) the value published to be a String of three numbers separated by a comma: e.g. 123,246,54 representing the hue,saturation,brightness where hue and saturation are a value between 0 and 255 and brightness is a value between 0 and 100.

Everything I’ve said above applies and continues to apply to ColorItem sicne at least OH 1.6 so I don’t know what “outdate” information you are finding.

2 Likes

Hello rlkoshalk, first of all thank you so much for your answer. Yes, I have read all the Beginner’s tutorial as well as the standard documentation provided in the openhab website and GitHub repositories(and of course lots of google searches).

What I don’t fully understand is how the color item “outputs” the command. For example a switch outputs ON or OFF, a dimmer outputs an integer between 0 and 100, etc. But when you say Color outputs HSB, in what format? I mean, it can be 255,122,009 or 255122009 or something like H255S122B009. Which one is it?

And finally, how can I make the MQTT send those commands? Let me explain, for some Test Leds I had to write this:

Switch D1 "Green Light" <light> [ "Switchable" ] {mqtt=">[broker:/HA1/E00/001:command:ON:1],>[broker:/HA1/E00/001:command:OFF:0],<[broker:/HA1/E00/001:state:default]"}

//Where MQTT syntax goes as follows
Item itemName { mqtt="<direction>[<broker>:<topic>:<type>:<trigger>:<transformation>]" }

//And what I may be looking for could look something like this (openhab2 documentation example)
Switch mySwitch {mqtt=">[mybroker:myhouse/office/light:command:ON:1],>[mybroker:myhouse/office/light:command:*:Switch ${itemName} was turned ${command}]"}

Meaning that I had to send manually each command(ON,OFF) individually, what is absolutely no problem and obvious for a switch; But I am sure there is a way in which I don’t have to manually send each HSB combination manually. I don’t know if I have explained myself well enough: What I want is to take the Color Item output and send(publish) that output as a message(I am aware I would have to transform it before to a String, as you said before).

I am sure that I am missing a concept quite important here. I hope you can help me! Tell me if I can thank you other way.

With outdated, I meant some of the info is only for openhab1 and sometimes I struggle finding that documentation for openhab2. Nevertheless, “outdated” is not the main problem; It’s just there is very little info for beginners like me.

Thank you!! Really!

I think it is comma separated with no leading zeros. But honestly I would just do a mosquitto_sub on the topic the ColorItem is attached to and see what gets published and go from there.

Use state instead of command and default for the transformation and any change to the Item’s state will be published.

Color MyColorLight {mqtt=">[broker:path/to/topic:state:default]"}

There is no need for a transform.

This is great! It didn’t work at the beginning since it needed a * wildcard after state:
It looks like this now:

Items

Color myColorTest "Color test" {mqtt=">[broker:/HA1/colortest:state:*:default]"}

Sitemap

Frame label="Colortest"
       {
               Colorpicker item=myColorTest
               Switch item=myColorTest
               Slider item=myColorTest
                          
       }

I now receive the MQTT messages separated by commas and no leading zeros; For example 35,23,67 or 255,100,0

At the same time, slider outputs a single value between 0 and 100 and the switch ON or OFF, as usual.

Now that I have this, I can use rules to transform it(so my arduino code handles it correctly). I took a quick look at a few interesting topics. Someone may find them useful too:

Send color value to MQTT

How to convert colorpicker to RGB values

Thank you so much for your help! Really appreciate it! Now let’s see if I can actually manage to make my LED strip work :slight_smile:.

IMPORTANT EDIT: I was confused! HSB stands for Hue(from 0 to 360), Saturation(0 to 100) and Brightness(0 to 100). It’s RGB which goes from 0 to 255! Important to keep in mind!

1 Like