API toggle function

This is a place for sharing with the community the results you achieved with QLC+, as a sort of use case collection.
You can share photos, videos, personal hardware/software projects, interesting HOWTO that might help other users to achieve great results.
Post Reply
SMNDVC
Posts: 3
Joined: Sat Nov 25, 2023 9:32 pm
Real Name: Simon Dovicovic

Hi,

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");
            }
        }
    };
}
Example usage case (I'm using bootstrap, but you can use it without it)

Code: Select all

<button class="btn btn-primary" onclick="toggleFunction(5)">Toggle dimmer on and off/button>
Hope someone finds this usefull :D
Yestalgia
Posts: 371
Joined: Thu Jun 17, 2021 9:31 am
Location: Australia
Real Name:
Contact:

Thanks for the contribution - I can see why something like this would be useful.
Post Reply