Control OnOff
To control the OnOff 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 "value" of the OnOff object of the message is the wanted value between 0 and 1 for the related luminaire. Value 0.0 = Off and anything above that = On.
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 = {"OnOff": {"value": 1.0}}; // OnOff value normalized to range [0..1]
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.