From ce567554165389a5fcc557e5aa31c528ad5e29cf Mon Sep 17 00:00:00 2001 From: AlexeyMal <75260807+AlexeyMal@users.noreply.github.com> Date: Wed, 7 Jan 2026 04:47:04 +0100 Subject: [PATCH] Random colors via JSON API in Segment object like "col":["r","r","r"] #4996 (#5000) Add support for random colors via JSON API in Segment object like col=["r","r","r"] #4996 --- wled00/json.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/wled00/json.cpp b/wled00/json.cpp index 323b45c2..542a3b62 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -253,6 +253,12 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId) // segment has RGB or White for (size_t i = 0; i < 3; i++) { + // JSON "col" array can contain the following values for each of segment's colors (primary, background, custom): + // "col":[int|string|object|array, int|string|object|array, int|string|object|array] + // int = Kelvin temperature or 0 for black + // string = hex representation of [WW]RRGGBB or "r" for random color + // object = individual channel control {"r":0,"g":127,"b":255,"w":255}, each being optional (valid to send {}) + // array = direct channel values [r,g,b,w] (w element being optional) int rgbw[] = {0,0,0,0}; bool colValid = false; JsonArray colX = colarr[i]; @@ -265,6 +271,9 @@ bool deserializeSegment(JsonObject elem, byte it, byte presetId) if (kelvin == 0) seg.setColor(i, 0); if (kelvin > 0) colorKtoRGB(kelvin, brgbw); colValid = true; + } else if (hexCol[0] == 'r' && hexCol[1] == '\0') { // Random colors via JSON API in Segment object like col=["r","r","r"] ยท Issue #4996 + setRandomColor(brgbw); + colValid = true; } else { //HEX string, e.g. "FFAA00" colValid = colorFromHexString(brgbw, hexCol); }