var socket = new TCPSocket(false);
var JSON_on = '{"on":true,"bri":255}';
var bridgeIP = CF.widget("Hue_URL","HUE").label;
var port = 80;
var groupID = 1;
// Function to send the PUT request over the socket
function sendHueCommand(commandJSON) {
var httpRequest =
'PUT /api/Y1Vpd5qwJVnjsRIdxFThJR0jxcrnZaEvrQVe0NYM/groups/' + groupID + '/action HTTP/1.1\r\n' +
'Host: ' + bridgeIP + '\r\n' +
'User-Agent: ProntoTSU9600\r\n' +
'Content-Type: application/json\r\n' +
'Content-Length: ' + commandJSON.length + '\r\n' +
'\r\n' +
commandJSON;
socket.write(httpRequest);
// Update the widget label for feedback
CF.widget(bri).label = JSON.parse(commandJSON).bri;
// Properly close the socket after sending
socket.close();
}
// When socket connects, send the command
socket.onConnect = function() {
sendHueCommand(JSON_on);
};
// Handle socket errors
socket.onError = function(err) {
CF.log("Socket error: " + err);
};
// Connect to the Hue Bridge
socket.connect(bridgeIP, port, 3000);
Many Thanks! For other users, note that the link above will have to be changed to add your user token. The group may also need to be changed.