Shelly Pro RGBWW PM - Control CCT LED lights

Hi,

Since VenusOS does not support yet the Shelly CCT integration to control the lights, I made one with Node-Red.

My goal was to controls the LED CCT lights from VenusOS, but if I use Shelly to change the lights, I want to update the VenusOS UI. That way, the status is always in sync between VenusOS and the Shelly RGBWW.

I have use the following components:
  • Shelly Pro RGBWW PM with firmware 2.0.1 configured with “Device Profile”: RGB and CCT
    • CCT LED Light Strip, color from 3000 to 6000K (min/max color limited in Shelly)
  • VenusOS 3.90beta8
  • Node-Red
    • Virtual Switch node with CCT Wheel
    • Shelly Gen 2+ node, configured in Callback with Event output.

Here is the Node-Red flow:

[
    {
        "id": "8dd6cd4f20f5d5e1",
        "type": "tab",
        "label": "Shelly CCT",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "31900539e8d88276",
        "type": "shelly-gen2",
        "z": "8dd6cd4f20f5d5e1",
        "hostname": "192.168.1.50",
        "description": "Pro RGBWW PM #1",
        "mode": "callback",
        "verbose": false,
        "server": "e61ff07629f31d52",
        "outputmode": "event",
        "uploadretryinterval": 5000,
        "pollinginterval": 5000,
        "pollstatus": true,
        "getstatusoncommand": true,
        "devicetype": "SPDC-0D5PE16EU",
        "devicetypemustmatchexactly": true,
        "captureblutooth": false,
        "outputs": 1,
        "x": 560,
        "y": 180,
        "wires": [
            [
                "40b23fd196e6ff07",
                "1b5481a56553e6c0"
            ]
        ]
    },
    {
        "id": "7c705637a4684e81",
        "type": "victron-virtual-switch",
        "z": "8dd6cd4f20f5d5e1",
        "name": "RGBWW #1 CCT",
        "outputs": 3,
        "switch_1_type": "11",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_customname": "Plafond",
        "switch_1_group": "Shelly",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": true,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_show_ui_input": 1,
        "switch_1_passthrough_mode": "auto_only",
        "x": 550,
        "y": 340,
        "wires": [
            [
                "2a564eeafee927be"
            ],
            [
                "9fa78ae0d48352d5",
                "5ad064abdb73d083"
            ],
            [
                "047a0e63ce8f620b",
                "5ad064abdb73d083"
            ]
        ]
    },
    {
        "id": "2a564eeafee927be",
        "type": "debug",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT Passthrough",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 850,
        "y": 420,
        "wires": []
    },
    {
        "id": "047a0e63ce8f620b",
        "type": "debug",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT LightControls",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 850,
        "y": 500,
        "wires": []
    },
    {
        "id": "40b23fd196e6ff07",
        "type": "debug",
        "z": "8dd6cd4f20f5d5e1",
        "name": "Shelly output: RGBWW #1",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 880,
        "y": 120,
        "wires": []
    },
    {
        "id": "9fa78ae0d48352d5",
        "type": "debug",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT State",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 830,
        "y": 460,
        "wires": []
    },
    {
        "id": "1b5481a56553e6c0",
        "type": "function",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT: Shelly to Victron",
        "func": "// Function 1: Shelly to VenusOS\nconst input = msg.payload;\n\n// Initialisation du contexte local au flow\nlet state = flow.get(\"cct_state\") || {\n    output: false,\n    brightness: 50,\n    ct: 4000\n};\n\nlet hasStateChange = false;\nlet hasControlChange = false;\n\n// 1. Cas : Payload d'état complet\nif (input && input.cct0) {\n    if (typeof input.cct0.output === \"boolean\" && input.cct0.output !== state.output) {\n        state.output = input.cct0.output;\n        hasStateChange = true;\n    }\n    if (typeof input.cct0.brightness === \"number\" && input.cct0.brightness !== state.brightness) {\n        state.brightness = Math.min(100, Math.max(1, Math.round(input.cct0.brightness)));\n        hasControlChange = true;\n    }\n    if (typeof input.cct0.ct === \"number\" && input.cct0.ct !== state.ct) {\n        state.ct = Math.min(6000, Math.max(3000, Math.round(input.cct0.ct)));\n        hasControlChange = true;\n    }\n}\n\n// 2. Cas : Payload d'événement Shelly Gen 2+\nif (input && input.info && input.component === \"cct:0\") {\n    const info = input.info;\n\n    if (info.event === \"toggle\" && typeof info.state === \"boolean\") {\n        if (info.state !== state.output) {\n            state.output = info.state;\n            hasStateChange = true;\n        }\n    }\n\n    if (info.event === \"value_change\") {\n        if (typeof info.brightness === \"number\") {\n            const clampedBrightness = Math.min(100, Math.max(1, Math.round(info.brightness)));\n            if (clampedBrightness !== state.brightness) {\n                state.brightness = clampedBrightness;\n                hasControlChange = true;\n            }\n        }\n        if (typeof info.ct === \"number\") {\n            const clampedCt = Math.min(6000, Math.max(3000, Math.round(info.ct)));\n            if (clampedCt !== state.ct) {\n                state.ct = clampedCt;\n                hasControlChange = true;\n            }\n        }\n    }\n}\n\n// Aucun changement détecté\nif (!hasStateChange && !hasControlChange) {\n    return null;\n}\n\n// Sauvegarde de l'état consolidé\nflow.set(\"cct_state\", state);\n\n// Détection d'écho : si la commande vient de VenusOS il y a moins de 1500ms, bloquer le retour\nconst lastVenusUpdate = flow.get(\"last_venus_command_ts\") || 0;\nif (Date.now() - lastVenusUpdate < 1500) {\n    return null;\n}\n\nconst outPayload = {};\n\nif (hasStateChange) {\n    outPayload[\"/SwitchableOutput/output_1/State\"] = state.output ? 1 : 0;\n}\n\nif (hasControlChange) {\n    outPayload[\"/SwitchableOutput/output_1/LightControls\"] = [\n        0,\n        0,\n        state.brightness,\n        0,\n        state.ct\n    ];\n}\n\nmsg.payload = outPayload;\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 860,
        "y": 180,
        "wires": [
            [
                "50cd4931604da14d",
                "7c705637a4684e81"
            ]
        ]
    },
    {
        "id": "5ad064abdb73d083",
        "type": "function",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT: Victron to Shelly",
        "func": "// Function 2: VenusOS to Shelly\nconst payload = msg.payload;\n\nlet state = flow.get(\"cct_state\") || {\n    output: false,\n    brightness: 50,\n    ct: 4000\n};\n\nlet shouldSend = false;\n\n// 1. Traitement de la sortie State (0 ou 1)\nif (typeof payload === \"number\" && (payload === 0 || payload === 1)) {\n    const requestedOutput = payload === 1;\n    if (state.output !== requestedOutput) {\n        state.output = requestedOutput;\n        shouldSend = true;\n    }\n}\n\n// 2. Traitement de la sortie LightControls (Tableau à 5 éléments)\nif (Array.isArray(payload) && payload.length >= 5) {\n    // Index 2: Brightness (1-100)\n    const rawBrightness = Number(payload[2]);\n    const clampedBrightness = Math.min(100, Math.max(1, Math.round(rawBrightness)));\n\n    // Index 4: ColorTemperature (3000-6000)\n    const rawCt = Number(payload[4]);\n    const clampedCt = Math.min(6000, Math.max(3000, Math.round(rawCt)));\n\n    if (state.brightness !== clampedBrightness || state.ct !== clampedCt) {\n        state.brightness = clampedBrightness;\n        state.ct = clampedCt;\n        shouldSend = true;\n    }\n}\n\n// 3. Alternative : traitement si le nœud passe des objets nommés\nif (typeof payload === \"object\" && !Array.isArray(payload) && payload !== null) {\n    if (typeof msg.colorTemperature === \"number\") {\n        const clampedCt = Math.min(6000, Math.max(3000, Math.round(msg.colorTemperature)));\n        if (state.ct !== clampedCt) {\n            state.ct = clampedCt;\n            shouldSend = true;\n        }\n    }\n}\n\nif (!shouldSend) {\n    return null;\n}\n\n// Sauvegarde de l'état et armement du timestamp anti-boucle\nflow.set(\"cct_state\", state);\nflow.set(\"last_venus_command_ts\", Date.now());\n\n// Formatage pour l'entrée du nœud Shelly Gen 2+\n// Méthode: Appel RPC\nmsg.payload = {\n    method: \"CCT.Set\",\n    params: {\n        id: 0,\n        on: state.output,\n        brightness: state.brightness,\n        ct: state.ct\n    }\n};\n\nreturn msg;\n",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 860,
        "y": 340,
        "wires": [
            [
                "31900539e8d88276",
                "e4f391d79ce19e0b"
            ]
        ]
    },
    {
        "id": "e4f391d79ce19e0b",
        "type": "debug",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT VS Output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1120,
        "y": 340,
        "wires": []
    },
    {
        "id": "50cd4931604da14d",
        "type": "debug",
        "z": "8dd6cd4f20f5d5e1",
        "name": "CCT SV Output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1120,
        "y": 180,
        "wires": []
    },
    {
        "id": "86b7d8f66afa00f5",
        "type": "inject",
        "z": "8dd6cd4f20f5d5e1",
        "name": "Off",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"/SwitchableOutput/output_1/State\": 0}",
        "payloadType": "json",
        "x": 310,
        "y": 400,
        "wires": [
            [
                "7c705637a4684e81"
            ]
        ]
    },
    {
        "id": "1887c68799c2c4b3",
        "type": "inject",
        "z": "8dd6cd4f20f5d5e1",
        "name": "On",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "{\"/SwitchableOutput/output_1/State\": 1}",
        "payloadType": "json",
        "x": 310,
        "y": 340,
        "wires": [
            [
                "7c705637a4684e81"
            ]
        ]
    },
    {
        "id": "e61ff07629f31d52",
        "type": "shelly-gen2-server",
        "port": "8001",
        "hostname": "",
        "hostip": ""
    },
    {
        "id": "ab5f117df4f73bdc",
        "type": "global-config",
        "env": [],
        "modules": {
            "node-red-contrib-shelly": "11.12.3",
            "@victronenergy/node-red-contrib-victron": "1.7.29"
        }
    }
]

Now, working on the RGB…

Configuration of Victron “Virtual Switch Node”

Configuration of Shelly Gen 2+ Node

Part 1:

Part 2, Callback configuration: