Control hue/saturation color
To control the hue/saturation color of specific luminaire of network you can send a CONTROL message to server over active WebSocket connection (and opened wire). The "targetControls" parameter of the message uses similar format as received with unitChanged event of the related device. The "hue" and "sat" values of the RGB object of the message define the wanted color in HS color map (V = 100%) for the related luminaire. The "source" of Colorsource object must be set to "RGB" for color functionality to work as expected. Note that the specific luminaire must support hue/saturation color scheme for this to work.
let wire = 1; // Use same wire ID as was used in the related OPEN message for the targeted network
let unit_id = 1; // Device ID of the related luminaire
let targetControls = {"RGB": {"hue": 0.5, "sat": 0.5}, "Colorsource": {"source": "RGB"}}; // RGB value where hue and sat are converted to range [0..1]
// Optionally you can use "rgb" value instead but use of "hue" and "sat" is recommended way because it is more accurate..
// let targetControls = {"RGB": {"rgb": "rgb(0, 125, 255)"}, "Colorsource": {"source": "RGB"}};
if (webSocket.readyState === webSocket.OPEN) {
const data = JSON.stringify({
"wire": wire,
"method": "controlUnit",
"id": unit_id,
"targetControls": targetControls
});
socket.send(decodeURIComponent(escape(data)));
}
When CONTROL luminaire of network message was successful then server will send unitChanged event (with updated state info) of related device to all related clients and color of related luminaire will be updated. Note that color conversions are not fully lossless and thus accuracy can vary a bit.