0

I've been having a heck of a time getting the proper values. In this example I have a device sending me a purple color where the data it sends to me is:

Saturation: 68
Brightness: 100
ColorTemperature: 4049
Hue: 0

And I need to convert that to an RGB. When I try the built-in method:

import colorsys

hue = 0
saturation = 68
brightness = 100
colortemp = 4049

r, g, b = colorsys.hsv_to_rgb(hue, saturation, brightness)

I get a result of:

Red: 100 | Green: -6700.0 | Blue: -6700.0

So I did some research and found this SO article that explains that the numbers need to be decimal values and tried it with their writeup when it is stated that

That function expects decimal for s (saturation) and v (value), not percent. Divide by 100.

Making the following changes to the code:

hue = 0
saturation = .68
brightness = 1.0
colortemp = 4049

Results in:

Red: 1.0 | Green: 0.32 | Blue: 0.32

Or when multiplied by 255:

Red: 255.0 | Green: 81.6 | Blue: 81.6

That color is red.

What am I doing wrong? I know, from using an eyedropper to grab the color, that the results should be around 102, 60, 250 for RGB but I'm not getting anywhere near that value.

To make this even more complicated I will need to, at some point, convert from RGB back to HSV again. If the solution is because I'm just using incorrect values or something then I assume the Python method to convert back will be correct but I'm just stuck now.

martineau
  • 119,623
  • 25
  • 170
  • 301
C4W
  • 239
  • 4
  • 13
  • I think your device is sending you incorrect information. When I enter the HSV values you provided, I get a light red color as well – wpercy Jul 16 '18 at 17:56
  • Thank you, I was wondering that too and used a program to manually input HSV and it came out the same. It's actually Homebridge/HomeKit that sends the values so I'll have to try to figure out why that's so off. – C4W Jul 16 '18 at 17:57
  • 1
    Look at any HSV circle. `hue=0` is always pure red. – Jongware Jul 16 '18 at 17:58

1 Answers1

1

I think your device is sending you incorrect information. The values you provide for HSV are red.

colorpicker

wpercy
  • 9,636
  • 4
  • 33
  • 45
  • I was wondering the same and pulled it up in Photoshop just as you did and got the same result. I don't know why I didn't test that earlier. It's from Homebridge/HomeKit so I don't know why that would be sending such odd values. – C4W Jul 16 '18 at 18:00
  • @C4W not sure, but at least you definitely know you're converting the values they give you correctly! – wpercy Jul 16 '18 at 18:01
  • LOL! Yes, indeed, I wasted so much time working on this and didn't even test the source values like a noob. I suppose the time sink was the price I paid. Thank you for your answer! – C4W Jul 16 '18 at 18:06