Here my code for RGB to HSV
case "Control.Color":
double r = int.Parse(values[0]) / 255;
double g = int.Parse(values[1]) / 255;
double b = int.Parse(values[2]) / 255;
double min = Math.Min( r, Math.Min( g, b ));
double max = Math.Max( r, Math.Max( g, b ));
double v = max; // v
double s = 0; // s
double h = 0; // h
double delta = max - min;
if( max != 0 )
{
s = delta / max; // s
if( r == max )
h = ( g - b ) / delta; // between yellow & magenta
else if( g == max )
h = 2 + ( b - r ) / delta; // between cyan & yellow
else
h = 4 + ( r - g ) / delta; // between magenta & cyan
h *= 60; // degrees
if( h < 0 )
h += 360;
}
if (values.Length > 3)
transition = ((int)(double.Parse(values[3]) * 10));
bridgeapicall(grp, lightnumber, "{ \"on\" : true" +
", \"hue\" : " + ((int)Math.Round(h * 182.044)).ToString() +
", \"sat\" : " + ((int)Math.Round(s * 255)).ToString() +
", \"bri\" : " + ((int)Math.Round(v * 255)).ToString() +
", \"transitiontime\" : " + transition.ToString() + "}");
break;