#Node-Red: Pass HSV and colour temp values from Loxone to HA.

1 messages · Page 1 of 1 (latest)

vast moss
#

Hey hive!

I install a home automation system called Loxone into homes as one of my day jobs but I have just installed it at my own home.
Now I am wanting to keep HA as the back end and back up automation system if loxone ever went belly up. All my Hue lamps/relays/sensors are all connected via zigbee to HA. I have gotten all my sensors into Loxone outside of Node-Red using Rest commands for the moment and PyLoxone integration from HACS for basic relay switching.

I am trying to use the lighting controller in loxone to send HSV/colour temp values to HA via service calls via Node-Red.
These are the plug ins im using in Node-Red:
node-red-contrib-loxone
node-red-contrib-home-assistant-websocket

I have tested just manually entering YAML into the data portion of the action node and all works good. I am just struggling to find out how to pass HSV/colour temp values to the node. Also in loxone if you pick a colour temp it will spit out a kelvin value and brightness instead of HSV so the ability to choose between them would be a big plus as well.

vast moss
#

EDIT: i was able to pass colour temp and brightness, it works perfectly. I seem to have an issue with the formatting for hs_color

Chat GPT has actually been a massive help (lol) but i cant seem to get passed this formatting issue

FUNCTION NODE coding

// Example of hsv input: "hsv(231,88,83)" (from Loxone Control In node)
let hsvString = msg.payload; // Get the HSV string, e.g., "hsv(231,88,83)"

// Check if the input is valid
if (typeof hsvString === "string" && hsvString.startsWith("hsv(") && hsvString.endsWith(")")) {
// Remove the "hsv(" and ")" parts and split by commas
let hsvValues = hsvString.slice(4, -1).split(',');

// Convert to integers
let hue = parseInt(hsvValues[0], 10); // Hue value
let saturation = parseInt(hsvValues[1], 10); // Saturation value
let brightness_pct = parseInt(hsvValues[2], 10); // Brightness value

// Ensure the values are valid
if (!isNaN(hue) && !isNaN(saturation) && !isNaN(brightness_pct)) {
    // Prepare the payload for Home Assistant
    msg.payload = {
        brightness_pct: brightness_pct,  // Brightness
        hs_color: [hue, saturation]  // Color as an array [hue, saturation]
    };

    return msg;
} else {
    node.warn("Invalid HSV values in input: " + hsvString);
    return null;
}

} else {
node.warn("Invalid HSV string format: " + hsvString);
return null;
}