HSV>RGB Conversion problem

Hi. I'm a very new Node-RED user attempting a conversion of a lighting output from a Loxone node to a Milight Node.

Despite reading and watching hours of tutorials, I can now say I'm more confused than when I started.

I've successfully got the 'Off' and 'Brightness/Temperature' features working in the following flow -


I can also successfully inject a payload at the RGB node to change the light colour.

  1. The node 'HSV Reformat' transfers the payload as a format -

["220,60,95"]

The node 'HSV> RGB' expects the payload without quotes -

[220,60,95]

If I understand correctly (which is likely to be wrong...), the HSV>RGB node is expecting a JSON array?

  1. The node 'HSV> RGB' outputs the correct RGB value, but in the format -

[97,145,242]

The node 'RGB' expects the incoming payload as -

rgb (97,145,242)

I'm subscribing to the technique of "1000 monkeys and a typewriter". But I've tried so many variations of curly brackets, straight brackets etc. that I have to admit I don't have a clue.

I've attempted to upload the exported clipboard here but unfortunately new users are not permitted attachments.

Any guidance would be much appreciated.

And here's the HSV Reformat node -

HSV%20Reformat

What does your input look like ?

The color convert node states:

input:

  • RGB - Red, Green, Blue
  • HSL - Hue, Saturation, Level
  • HSV - Hue, Saturation, Value (brightness)

For the first 3 input modes the node will attempt to determine the input format from the 3 following:

  • a 3 segment array with values between 0-255 for RGB.
  • a 3 segment array for HSL and HSV with Hue is between 0-360 and Saturation, Level, values 0-100.
  • a object with keys red , green , blue .
  • a object with keys hue , saturation , lightness or value , brightness

An 3 segment array:

[number,number,number]

An object with rgb keys:

{red:number,green:number,blue:number}

An object with HSL/HSB keys:

{hue:number,saturation:number,brightness:number}

The easiest is to end up with:
{payload:[number, number, number]} (as HSV/HSB input)

Your function looks complicated and the command is not correct, as you create an array containing 1 string.

change the reformat function:

h = hsv[0]
s = hsv[1]
v = hsv[2]

return {payload:[h,s,v]}

The milight expects a string (I am not a fan tbh), so the output of the color convert node needs to be changed again.

create a function connect it to the color convert node (this is your RGB function):

m = msg.payload
return {topic:"rgb",payload:"rgb("+m+")"};

and attach the output it to milight.

1 Like

@bakman2 Thank-you! That worked. :grinning:

I found an alternate method for a node before the HSV>RGB node. That consists of -

msg.payload = msg.payload.replace("hsv(", "").replace(")", "").split(",");
return msg;

The output format is now [ "359", "69", "100" ]. That is accepted by the HSV>RGB node.

Your function after the colour convert node filled the missing link!

I've spent days getting nowhere trying to learn this new discipline...it looks so simple afterwards. :confused:

One thing to be careful of with your flow is that you split the flow and then point them all back to a single node.

Out of the box that node will see this as 4 separate messages. Which might work well for your flow but often doesn’t

If your intention was that the end node would join all those messages back up together, you have to do that yourself

Either by using the JOIN node or by using context values or by remodelling your flow to do things in serial

The output format is now [ "359", "69", "100" ]. That is accepted by the HSV>RGB node.

I cannot imagine this will function correctly. It expects an array of numbers, why change it to strings ? Overcomplicating things.

What is the output of the switch node ?

@bakman2 - When a light selection is made using the colour picker, the switch node outputs in format -

"hsv(292,54,100)"

@ukmoose - As far as I can ascertain, the light selection 'device' only sends messages when the relevant feature is touched. At any given time, there can only be -

an RGB selection or
CW/WW light selection or
Brightness or
Off

Replace your HSV reformat node with:

m = msg.payload
r = /\((.*?),(.*?),(.*?)\)/gm;
o = r.exec(m)

h = parseInt(o[1])
s = parseInt(o[2])
v = parseInt(o[3])

return {payload:[h,s,v]};

Just like I showed above. This is correctly accepted by the color convert node.

@bakman2 - Thanks, that code works fine.

I'm happy to say I can now install 100 watts of colourful grandness in the backyard. I'm also curious to see how long this MiLight works...

1 Like