Turn luminaire on/off/dim
To control the dim level of a luminaire 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.
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 = {"Dimmer": {"value": 0.5}}; // Dimmer value can be anything from 0 to 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 message was successful then server will send unitChanged event (with updated state info) to all related clients and related luminaire will be on/off/dimmed.