I've been playing around with QLC+ APIs, and I've noticed, that there was no way to toggle a function on and off with one button. So i've created one:
Code: Select all
function toggleFunction(functionId) {
// Send the request to get function status
websocket.send("QLC+API|getFunctionStatus|" + functionId);
// WebSocket message handler to process the response
websocket.onmessage = function(event) {
// Parse and handle the response here
var message = event.data;
// Check if the message is related to function status
if (message.startsWith("QLC+API|getFunctionStatus|")) {
var functionStatus = message.split("|")[2];
// Toggle the function status
if (functionStatus === "Running") {
websocket.send('QLC+API|setFunctionStatus|' + functionId + '|0');
// console.log("function ID", functionId, "has stopped");
} else {
websocket.send('QLC+API|setFunctionStatus|' + functionId + '|1');
// console.log("function ID", functionId, "is running");
}
}
};
}
Code: Select all
<button class="btn btn-primary" onclick="toggleFunction(5)">Toggle dimmer on and off/button>