Links that help me with code for Google Home and Amazon Echo
for Google Home
1- Smart Home ColorSpectrum Trait Schema
2- My Code
//G=>{"deviceId":"xxxx","action":"action.devices.commands.ColorAbsolute","value":{"color":{"name":"sky blue","spectrumRGB":8900331}}}
else if(action == "action.devices.commands.ColorAbsolute") { // color
S = "Google Home";
String Name = json ["value"]["color"]["name"];
int spectrumRGB = json ["value"]["color"]["spectrumRGB"];
int temperature = json ["value"]["color"]["temperature"];
Gcolor = Name ;
String strRGB = String(spectrumRGB, HEX);
while (strRGB.length() < 6) strRGB = "0" + strRGB;
strRGB.toUpperCase();
strRGB = "#" + strRGB ;
// Split them up into r, g, b values
byte r = spectrumRGB >> 16;
byte g = spectrumRGB >> 8 & 0xFF;
byte b = spectrumRGB & 0xFF;
rr = r ; gg = g ; bb = b ;
RGB_Out(rr,gg,bb) ;
For Alexa it needs a function to convert HSB to RGB
// For Light device type
// {"deviceId": xxxx, "action": "setPowerState", value: "ON"} // https://developer.amazon.com/docs/device-apis/alexa-powercontroller.html
// {"deviceId": xxxx, "action": "AdjustBrightness", value: 3} // https://developer.amazon.com/docs/device-apis/alexa-brightnesscontroller.html
// {"deviceId": xxxx, "action": "setBrightness", value: 42} // https://developer.amazon.com/docs/device-apis/alexa-brightnesscontroller.html
// {"deviceId": xxxx, "action": "SetColor", value: {"hue": 350.5, "saturation": 0.7138, "brightness": 0.6501}} // https://developer.amazon.com/docs/device-apis/alexa-colorcontroller.html
// {"deviceId": xxxx, "action": "DecreaseColorTemperature"} // https://developer.amazon.com/docs/device-apis/alexa-colortemperaturecontroller.html
// {"deviceId": xxxx, "action": "IncreaseColorTemperature"} // https://developer.amazon.com/docs/device-apis/alexa-colortemperaturecontroller.html
// {"deviceId": xxxx, "action": "SetColorTemperature", value: 2200} // https://developer.amazon.com/docs/device-apis/alexa-colortemperaturecontroller.html
3- HSV → RGB
*** Color math ***
//H, S and V input range = 0 ÷ 1.0
//R, G and B output range = 0 ÷ 255
if ( S == 0 )
{
R = V * 255
G = V * 255
B = V * 255
}
else
{
var_h = H * 6
if ( var_h == 6 ) var_h = 0 //H must be < 1
var_i = int( var_h ) //Or ... var_i = floor( var_h )
var_1 = V * ( 1 - S )
var_2 = V * ( 1 - S * ( var_h - var_i ) )
var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) )
if ( var_i == 0 ) { var_r = V ; var_g = var_3 ; var_b = var_1 }
else if ( var_i == 1 ) { var_r = var_2 ; var_g = V ; var_b = var_1 }
else if ( var_i == 2 ) { var_r = var_1 ; var_g = V ; var_b = var_3 }
else if ( var_i == 3 ) { var_r = var_1 ; var_g = var_2 ; var_b = V }
else if ( var_i == 4 ) { var_r = var_3 ; var_g = var_1 ; var_b = V }
else { var_r = V ; var_g = var_1 ; var_b = var_2 }
R = var_r * 255
G = var_g * 255
B = var_b * 255
}
4-void HSV_to_RGB(float h, float s, float v, byte &r, byte &g, byte &b)
My Code
void HSV_to_RGB(float h, float s, float v, byte rgb[])
{
int i;
float f,p,q,t; //http://www.easyrgb.com/en/math.php
h = constrain(h, 0.0, 360.0);
s = constrain(s, 0.0, 100.0);
v = constrain(v, 0.0, 100.0);
s /= 100;
v /= 100;
if (s == 0) {
// Achromatic (grey)
rgb[0] = rgb[1] = rgb[2] = round(v*255);
return;
}
h /= 60.0;
i = floor(h); // sector 0 to 5
f = h - (float)i; // factorial part of h
p = v * (1.0 - s);
q = v * (1.0 - s * f);
t = v * (1.0 - s * (1 - f));
switch(i) { //http://colorizer.org/
case 0:
rgb[0] = round(255*v);
rgb[1] = round(255*t);
rgb[2] = round(255*p);
break;
case 1:
rgb[0] = round(255*q);
rgb[1] = round(255*v);
rgb[2] = round(255*p);
break;
case 2:
rgb[0] = round(255*p);
rgb[1] = round(255*v);
rgb[2] = round(255*t);
break;
case 3:
rgb[0] = round(255*p);
rgb[1] = round(255*q);
rgb[2] = round(255*v);
break;
case 4:
rgb[0] = round(255*t);
rgb[1] = round(255*p);
rgb[2] = round(255*v);
break;
default: // case 5:
rgb[0] = round(255*v);
rgb[1] = round(255*p);
rgb[2] = round(255*q);
}
}
//---------------------------------
6- Arilux RGB LED controllers for use with Home Assistant and an IR remote
—Alternative firmware for Arilux AL-LC0X LED controllers