examples: handle the relative light directives. lightWithBrightness and lightWithColorTemp now act on AdjustBrightness (brightnessDelta, clamped 0-100); lightWithColorTemp starts at 2700 K instead of reporting 0 K (outside Alexa's 1000-10000 K range) and acts on IncreaseColorTemperature / DecreaseColorTemperature in 500 K steps. Verified on a D1 mini with Alexa: SetBrightness 10/100 and SetColorTemperature 7000/2200 K round-trip; the relative directives await a voice test.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
David 2026-09-28 09:41:59 +00:00
parent 87caad25be
commit 21cc693e74
2 changed files with 13 additions and 1 deletions

View file

@ -89,6 +89,10 @@ void setup() {
brightness=directive["payload"]["brightness"];
Serial.printf("setting brightness to: %d\n", brightness);
outputState = PowerController::ON;
} else if(directive["header"]["name"]=="AdjustBrightness"){ // "dim" / "brighten" (by N percent)
brightness=constrain(brightness + (int)directive["payload"]["brightnessDelta"], 0, 100);
Serial.printf("adjusting brightness to: %d\n", brightness);
outputState = PowerController::ON;
}
}else{
return;

View file

@ -28,7 +28,7 @@ AlexaDevice* device1;
// Initial state for the light (PowerController)
PowerController outputState = PowerController::OFF;
int brightness=100;
int colorTemp=0;
int colorTemp=2700; // Kelvin; Alexa accepts 1000-10000, so never report 0
void setup() {
// Initialize the LED as output
pinMode(LED_BUILTIN, OUTPUT);
@ -94,12 +94,20 @@ void setup() {
brightness=directive["payload"]["brightness"];
Serial.printf("setting brightness to: %d\n", brightness);
outputState = PowerController::ON;
} else if(directive["header"]["name"]=="AdjustBrightness"){ // "dim" / "brighten" (by N percent)
brightness=constrain(brightness + (int)directive["payload"]["brightnessDelta"], 0, 100);
Serial.printf("adjusting brightness to: %d\n", brightness);
outputState = PowerController::ON;
}
}else if (type == AlexaInterfaceType::COLOR_TEMPERATURE_CONTROLLER) {
if(directive["header"]["name"]=="SetColorTemperature"){
colorTemp=directive["payload"]["colorTemperatureInKelvin"];
Serial.printf("setting color temperature to: %d\n", colorTemp);
outputState = PowerController::ON;
} else if(directive["header"]["name"]=="IncreaseColorTemperature" || directive["header"]["name"]=="DecreaseColorTemperature"){ // "cooler" / "warmer"
colorTemp=constrain(colorTemp + (directive["header"]["name"]=="IncreaseColorTemperature" ? 500 : -500), 1000, 10000);
Serial.printf("adjusting color temperature to: %d\n", colorTemp);
outputState = PowerController::ON;
}
}else{
return;