How could this be split from 1 aico to 3 aircos?

I have this flow:

[
    {
        "id": "b984ca5b35cf43bb",
        "type": "tab",
        "label": "Airco Automation",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "f469ea8cf928138a",
        "type": "server-state-changed",
        "z": "b984ca5b35cf43bb",
        "name": "realtime_produced_power_kw",
        "server": "e088f9a18be9efaf",
        "version": 6,
        "outputs": 1,
        "exposeAsEntityConfig": "",
        "entities": {
            "entity": [
                "sensor.realtime_produced_power_kw"
            ],
            "substring": [],
            "regex": []
        },
        "outputInitially": false,
        "stateType": "num",
        "ifState": "",
        "ifStateType": "str",
        "ifStateOperator": "is",
        "outputOnlyOnStateChange": true,
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            }
        ],
        "x": 380,
        "y": 200,
        "wires": [
            [
                "af9e50462e4fa7a9"
            ]
        ]
    },
    {
        "id": "af9e50462e4fa7a9",
        "type": "change",
        "z": "b984ca5b35cf43bb",
        "name": "set topic to realtime_produced_power_kw",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "realtime_produced_power_kw",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 720,
        "y": 200,
        "wires": [
            [
                "29afbc6978016251",
                "9d4cd0482f4339dd"
            ]
        ]
    },
    {
        "id": "a86e2f17605167a2",
        "type": "change",
        "z": "b984ca5b35cf43bb",
        "name": "set topic to realtime_consumption_kw",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "realtime_consumption_kw",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 710,
        "y": 100,
        "wires": [
            [
                "9d4cd0482f4339dd",
                "d74b013885f9862e"
            ]
        ]
    },
    {
        "id": "46f29b5046816ca2",
        "type": "server-state-changed",
        "z": "b984ca5b35cf43bb",
        "name": "realtime_consumption_kw",
        "server": "e088f9a18be9efaf",
        "version": 6,
        "outputs": 1,
        "exposeAsEntityConfig": "",
        "entities": {
            "entity": [
                "sensor.realtime_power_kw"
            ],
            "substring": [],
            "regex": []
        },
        "outputInitially": false,
        "stateType": "num",
        "ifState": "",
        "ifStateType": "str",
        "ifStateOperator": "is",
        "outputOnlyOnStateChange": true,
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "ignorePrevStateNull": false,
        "ignorePrevStateUnknown": false,
        "ignorePrevStateUnavailable": false,
        "ignoreCurrentStateUnknown": false,
        "ignoreCurrentStateUnavailable": false,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            }
        ],
        "x": 370,
        "y": 100,
        "wires": [
            [
                "a86e2f17605167a2"
            ]
        ]
    },
    {
        "id": "9d4cd0482f4339dd",
        "type": "join",
        "z": "b984ca5b35cf43bb",
        "name": "Join Power Data",
        "mode": "custom",
        "build": "object",
        "property": "payload",
        "propertyType": "msg",
        "key": "topic",
        "joiner": "\\n",
        "joinerType": "str",
        "useparts": false,
        "accumulate": true,
        "timeout": "",
        "count": "3",
        "reduceRight": false,
        "reduceExp": "",
        "reduceInit": "",
        "reduceInitType": "",
        "reduceFixup": "",
        "x": 1070,
        "y": 140,
        "wires": [
            [
                "96f29f2f35a0e8f1"
            ]
        ]
    },
    {
        "id": "29afbc6978016251",
        "type": "debug",
        "z": "b984ca5b35cf43bb",
        "name": "realtime_produced_power_kw",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1150,
        "y": 200,
        "wires": []
    },
    {
        "id": "d74b013885f9862e",
        "type": "debug",
        "z": "b984ca5b35cf43bb",
        "name": "realtime_consumption_kw",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1070,
        "y": 100,
        "wires": []
    },
    {
        "id": "96f29f2f35a0e8f1",
        "type": "function",
        "z": "b984ca5b35cf43bb",
        "name": "Check conditions",
        "func": "let producedPower = parseFloat(msg.payload.realtime_produced_power_kw); // Extracting the produced power\nlet realtime_consumption_kw = parseFloat(msg.payload.realtime_consumption_kw); // Extracting the consumption power\nlet hvacState = msg.payload.hvac_state; // Extracting the HVAC state\n\n// Log the incoming values to check they are as expected\nnode.warn(`Produced Power: ${producedPower}`);\nnode.warn(`Real-time Consumption: ${realtime_consumption_kw}`);\nnode.warn(`HVAC State: ${hvacState}`);\n\n// Set up a flow variable to track if HVAC is already on\nlet hvacOn = flow.get(\"hvacOn\") || false;\n\n// Adjust conditions to account for the hvac_state\nif (producedPower - realtime_consumption_kw >= 1.8 && !hvacOn && hvacState !== \"heat\") {\n    // Condition to turn ON: produced power exceeds consumption by 1.8 kW, and HVAC is off and not in 'heat' mode\n    node.warn(\"Condition to turn ON met\");\n    flow.set(\"hvacOn\", true);\n    return [msg, null]; // Proceed with \"on\" actions\n}\nelse if (realtime_consumption_kw > producedPower && hvacOn && hvacState === \"heat\") {\n    // Condition to turn OFF: consumption exceeds production, and HVAC is on and in 'heat' mode\n    node.warn(\"Condition to turn OFF met\");\n    flow.set(\"hvacOn\", false);\n    return [null, msg]; // Trigger \"off\" actions\n}\nelse {\n    // Log which condition failed\n    if (!(producedPower - realtime_consumption_kw >= 1.8)) {\n        node.warn(\"Condition to turn ON not met: Produced power is not sufficient.\");\n    }\n    if (!(realtime_consumption_kw > producedPower)) {\n        node.warn(\"Condition to turn OFF not met: Consumption is not greater than production.\");\n    }\n    if (!(hvacState !== \"heat\")) {\n        node.warn(\"HVAC is in heat mode, so turn ON condition is skipped.\");\n    }\n    if (!(hvacState === \"heat\")) {\n        node.warn(\"HVAC is not in heat mode, so turn OFF condition is skipped.\");\n    }\n\n    node.warn(\"No action taken - conditions not met\");\n}\n\nreturn null; // No action if conditions are not met\n",
        "outputs": 2,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 310,
        "y": 560,
        "wires": [
            [
                "15de4adb5840fcf7",
                "0f3a9ac1dcd8cf64",
                "6b5d8fceb4d0b66d"
            ],
            [
                "735ac8ec4566d685"
            ]
        ]
    },
    {
        "id": "be064340653c0bda",
        "type": "api-call-service",
        "z": "b984ca5b35cf43bb",
        "name": "Set HVAC Mode to Heat",
        "server": "e088f9a18be9efaf",
        "version": 7,
        "debugenabled": false,
        "action": "climate.set_hvac_mode",
        "floorId": [],
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "climate.1e6a9e2b"
        ],
        "labelId": [],
        "data": "{ \"hvac_mode\": \"heat\" }",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "blockInputOverrides": false,
        "domain": "climate",
        "service": "set_hvac_mode",
        "service_domain": "climate",
        "x": 1110,
        "y": 540,
        "wires": [
            [
                "fd0d61c5bd083414"
            ]
        ]
    },
    {
        "id": "4f54c319b9c5f408",
        "type": "api-call-service",
        "z": "b984ca5b35cf43bb",
        "name": "Set Preset Mode to Boost",
        "server": "e088f9a18be9efaf",
        "version": 7,
        "debugenabled": false,
        "action": "climate.set_preset_mode",
        "floorId": [],
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "climate.1e6a9e2b"
        ],
        "labelId": [],
        "data": "{ \"preset_mode\": \"boost\" }",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "blockInputOverrides": false,
        "domain": "climate",
        "service": "set_preset_mode",
        "service_domain": "climate",
        "x": 1110,
        "y": 600,
        "wires": [
            [
                "b18a65bc919bcaf5"
            ]
        ]
    },
    {
        "id": "025f5c9eaa43c581",
        "type": "api-call-service",
        "z": "b984ca5b35cf43bb",
        "name": "Set Target Temperature to 30",
        "server": "e088f9a18be9efaf",
        "version": 7,
        "debugenabled": false,
        "action": "climate.set_temperature",
        "floorId": [],
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "climate.1e6a9e2b"
        ],
        "labelId": [],
        "data": "{ \"temperature\": 30 }",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "blockInputOverrides": false,
        "domain": "climate",
        "service": "set_temperature",
        "service_domain": "climate",
        "x": 1120,
        "y": 660,
        "wires": [
            [
                "79cd5c0219bfdb7c"
            ]
        ]
    },
    {
        "id": "78744bf75ef1cdf9",
        "type": "api-call-service",
        "z": "b984ca5b35cf43bb",
        "name": "Set HVAC Mode to Off",
        "server": "e088f9a18be9efaf",
        "version": 7,
        "debugenabled": false,
        "action": "climate.set_hvac_mode",
        "floorId": [],
        "areaId": [],
        "deviceId": [],
        "entityId": [
            "climate.1e6a9e2b"
        ],
        "labelId": [],
        "data": "{ \"hvac_mode\": \"off\" }",
        "dataType": "jsonata",
        "mergeContext": "",
        "mustacheAltTags": false,
        "outputProperties": [],
        "blockInputOverrides": false,
        "domain": "climate",
        "service": "set_hvac_mode",
        "service_domain": "climate",
        "x": 1120,
        "y": 760,
        "wires": [
            [
                "fc2c7a977d86f73c"
            ]
        ]
    },
    {
        "id": "c1c3b6e18bf75f8b",
        "type": "api-current-state",
        "z": "b984ca5b35cf43bb",
        "name": "",
        "server": "e088f9a18be9efaf",
        "version": 3,
        "outputs": 1,
        "halt_if": "",
        "halt_if_type": "str",
        "halt_if_compare": "is",
        "entity_id": "climate.1e6a9e2b",
        "state_type": "str",
        "blockInputOverrides": true,
        "outputProperties": [
            {
                "property": "payload",
                "propertyType": "msg",
                "value": "",
                "valueType": "entityState"
            },
            {
                "property": "data",
                "propertyType": "msg",
                "value": "",
                "valueType": "entity"
            }
        ],
        "for": "0",
        "forType": "num",
        "forUnits": "minutes",
        "override_topic": false,
        "state_location": "payload",
        "override_payload": "msg",
        "entity_location": "data",
        "override_data": "msg",
        "x": 390,
        "y": 280,
        "wires": [
            [
                "e768509ea2cead1f"
            ]
        ]
    },
    {
        "id": "e768509ea2cead1f",
        "type": "change",
        "z": "b984ca5b35cf43bb",
        "name": "set topic to hvac_state",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "hvac_state",
                "tot": "str"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 700,
        "y": 280,
        "wires": [
            [
                "9d4cd0482f4339dd"
            ]
        ]
    },
    {
        "id": "d76f3c23df45ac81",
        "type": "inject",
        "z": "b984ca5b35cf43bb",
        "name": "start_check",
        "props": [],
        "repeat": "30",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 150,
        "y": 280,
        "wires": [
            [
                "c1c3b6e18bf75f8b"
            ]
        ]
    },
    {
        "id": "6b5d8fceb4d0b66d",
        "type": "trigger",
        "z": "b984ca5b35cf43bb",
        "name": "Trigger 5 Min Timer",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5",
        "extend": true,
        "overrideDelay": false,
        "units": "min",
        "reset": "false",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 810,
        "y": 660,
        "wires": [
            [
                "025f5c9eaa43c581"
            ]
        ]
    },
    {
        "id": "0f3a9ac1dcd8cf64",
        "type": "trigger",
        "z": "b984ca5b35cf43bb",
        "name": "Trigger 5 Min Timer",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5",
        "extend": true,
        "units": "min",
        "reset": "false",
        "outputs": 1,
        "x": 810,
        "y": 600,
        "wires": [
            [
                "4f54c319b9c5f408"
            ]
        ]
    },
    {
        "id": "15de4adb5840fcf7",
        "type": "trigger",
        "z": "b984ca5b35cf43bb",
        "name": "Trigger 5 Min Timer",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5",
        "extend": true,
        "units": "min",
        "reset": "false",
        "outputs": 1,
        "x": 810,
        "y": 540,
        "wires": [
            [
                "be064340653c0bda"
            ]
        ]
    },
    {
        "id": "735ac8ec4566d685",
        "type": "trigger",
        "z": "b984ca5b35cf43bb",
        "name": "Trigger 5 Min Timer",
        "op1": "true",
        "op2": "false",
        "op1type": "bool",
        "op2type": "bool",
        "duration": "5",
        "extend": true,
        "units": "min",
        "reset": "false",
        "outputs": 1,
        "x": 810,
        "y": 760,
        "wires": [
            [
                "78744bf75ef1cdf9"
            ]
        ]
    },
    {
        "id": "fd0d61c5bd083414",
        "type": "debug",
        "z": "b984ca5b35cf43bb",
        "name": "HVAC Mode to Heat",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1380,
        "y": 540,
        "wires": []
    },
    {
        "id": "b18a65bc919bcaf5",
        "type": "debug",
        "z": "b984ca5b35cf43bb",
        "name": "Preset Mode to Boost",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1380,
        "y": 600,
        "wires": []
    },
    {
        "id": "79cd5c0219bfdb7c",
        "type": "debug",
        "z": "b984ca5b35cf43bb",
        "name": "Target Temperature to 30",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1390,
        "y": 660,
        "wires": []
    },
    {
        "id": "fc2c7a977d86f73c",
        "type": "debug",
        "z": "b984ca5b35cf43bb",
        "name": "HVAC Mode to Off",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1370,
        "y": 760,
        "wires": []
    },
    {
        "id": "e088f9a18be9efaf",
        "type": "server",
        "name": "Home Assistant",
        "version": 5,
        "addon": false,
        "rejectUnauthorizedCerts": true,
        "ha_boolean": "y|yes|true|on|home|open",
        "connectionDelay": true,
        "cacheJson": true,
        "heartbeat": false,
        "heartbeatInterval": "30",
        "areaSelector": "friendlyName",
        "deviceSelector": "friendlyName",
        "entitySelector": "friendlyName",
        "statusSeparator": ": ",
        "statusYear": "hidden",
        "statusMonth": "short",
        "statusDay": "numeric",
        "statusHourCycle": "default",
        "statusTimeFormat": "h:m",
        "enableGlobalContextStore": false
    }
]

This automation is related to an airco start and stop based on energy production and consumption. If the production is higher then consumption by 1.8 kw for 5 minutes then the airco is started. If production drops more the consumption for 5 minutes then airco will be turned off.

I need to use the same logic for my new flow but instead of 1 airco to have 3 aircos in there. If production is higher then consumption by 1.8 kw for 5 minutes then start airco1. If production is still higher then consumption after 5 minutes by 1.8 kw more then start airco2.
If production is still higher then consumption after another 5 minutes by 1.8 kw then start airco3.

I would need the same logic to be applied on turning off. Basically if consumption is higher then production for 5 minutes by 1.8 kw then stop airco1. If after another 5 minutes the consumption is higher then production by 1.8 kw then stop airco2. If after another 5 minutes the consumption is higher then production by 1.8 kw then stop airco3.

Also the state of the airco should be checked before sending any commands to it. If the airco is already turned on, then there is no more need to send the command again. If the airco is already turned off, then there is no more need to send the configuration again

I managed to get it working properly for a single airco but I have no idea how I can make this happen for 3 aircos.
Any help or idea is greatly appreciated

The easy way is not to think of the timings being interlinked.
Drive aircon1 as you currently have it. For aircon 2 use 10 minutes instead of 5, and for aircon3 use 15 minutes.

That is the easy bit, use a Filter node to block unless the value (aircon on/off) has changed.

Can you please elaborate a bit on this how I could do it? I never did something similar

First look at the Filter node and understand what it does.

Does this make sense?

Condition check:

let producedPower = parseFloat(msg.payload.realtime_produced_power_kw); // Extracting produced power
let consumptionPower = parseFloat(msg.payload.realtime_consumption_kw); // Extracting consumption power

// Flow variables for tracking each airco state
let hvacOn_Birou = flow.get("hvacOn_Birou") || false;
let hvacOn_Camera_Spate = flow.get("hvacOn_Camera_Spate") || false;
let hvacOn_Camera_Bia = flow.get("hvacOn_Camera_Bia") || false;
let hvacOn_Living = flow.get("hvacOn_Living") || false;

// Airco states from Home Assistant (replace these with the actual entity state IDs if necessary)
let hvacState_Birou = msg.payload.hvac_state_birou; // State of birou
let hvacState_Camera_Spate = msg.payload.hvac_state_camera_spate; // State of camera_spate
let hvacState_Camera_Bia = msg.payload.hvac_state_camera_bia; // State of camera_bia
let hvacState_Living = msg.payload.hvac_state_living; // State of camera_bia

// Thresholds for each airco (1.8 kW increments)
const threshold = 1.8;
const threshold_birou = threshold * 4;
const threshold_camera_spate = threshold * 2;
const threshold_camera_bia = threshold;
const threshold_living = threshold * 3;


// Log the incoming values to check they are as expected
node.warn(`Produced Power: ${producedPower}`);
node.warn(`Consumption Power: ${consumptionPower}`);
node.warn(`HVAC States: [${hvacState_Birou}, ${hvacState_Camera_Spate}, ${hvacState_Camera_Bia}, ${hvacState_Living}]`);

// Calculate the difference between production and consumption
let powerDifference = producedPower - consumptionPower;

// Array to hold actions for each airco
let actions = [null, null, null, null]; // [birou_action, camera_spate_action, camera_bia_action, living_action]

// Logic for turning aircos ON based on power difference and their current state
if (powerDifference >= threshold_birou && !hvacOn_Birou && hvacState_Birou !== "heat") {
    node.warn("Condition to turn ON birou met");
    flow.set("hvacOn_Birou", true);
    actions[0] = "turn_on_birou"; // Start birou
} else if (powerDifference >= threshold_camera_spate && !hvacOn_Camera_Spate && hvacState_Camera_Spate !== "heat") {
    node.warn("Condition to turn ON camera_spate met");
    flow.set("hvacOn_Camera_Spate", true);
    actions[1] = "turn_on_camera_spate"; // Start camera_spate
} else if (powerDifference >= threshold_camera_bia && !hvacOn_Camera_Bia && hvacState_Camera_Bia !== "heat") {
    node.warn("Condition to turn ON camera_bia met");
    flow.set("hvacOn_Camera_Bia", true);
    actions[2] = "turn_on_camera_bia"; // Start camera_bia
} else if (powerDifference >= threshold_living && !hvacOn_Living && hvacState_Living !== "heat") {
    node.warn("Condition to turn ON living met");
    flow.set("hvacOn_Living", true);
    actions[2] = "turn_on_living"; // Start living
}

// Logic for turning aircos OFF based on power difference and their current state
if (powerDifference < threshold_birou && hvacOn_Birou && hvacState_Birou === "heat") {
    node.warn("Condition to turn OFF birou met");
    flow.set("hvacOn_Birou", false);
    actions[0] = "turn_off_birou"; // Stop birou
} else if (powerDifference < threshold_camera_spate && hvacOn_Camera_Spate && hvacState_Camera_Spate === "heat") {
    node.warn("Condition to turn OFF camera_spate met");
    flow.set("hvacOn_Camera_Spate", false);
    actions[1] = "turn_off_camera_spate"; // Stop camera_spate
} else if (powerDifference < threshold_camera_bia && hvacOn_Camera_Bia && hvacState_Camera_Bia === "heat") {
    node.warn("Condition to turn OFF camera_bia met");
    flow.set("hvacOn_Camera_Bia", false);
    actions[2] = "turn_off_camera_bia"; // Stop camera_bia
} else if (powerDifference < threshold_living && hvacOn_Living && hvacState_Living === "heat") {
    node.warn("Condition to turn OFF living met");
    flow.set("hvacOn_Living", false);
    actions[2] = "turn_off_living"; // Stop living
}

// Log actions to understand which commands will be sent
actions.forEach((action, index) => {
    if (action) {
        node.warn(`Action for airco${index + 1}: ${action}`);
    } else {
        node.warn(`No action for airco${index + 1}`);
    }
});

// Send commands only for the actions that need to be executed
let outputs = [null, null, null, null];
if (actions[0]) outputs[0] = { payload: actions[0] };
if (actions[1]) outputs[1] = { payload: actions[1] };
if (actions[2]) outputs[2] = { payload: actions[2] };
if (actions[3]) outputs[3] = { payload: actions[3] };

// Return array to handle multiple outputs in Node-RED
return outputs;

And complete json. Anything I can try to make it nicer or to clean it up further? I also plan to make the heat/cool as a variable to reuse the same thing for summer/winter.

[
    {
        "id": "506d9ee81ba237c5",
        "type": "function",
        "z": "ec616a038f54c72f",
        "name": "Check conditions",
        "func": "let producedPower = parseFloat(msg.payload.realtime_produced_power_kw); // Extracting produced power\nlet consumptionPower = parseFloat(msg.payload.realtime_consumption_kw); // Extracting consumption power\n\n// Flow variables for tracking each airco state\nlet hvacOn_Birou = flow.get(\"hvacOn_Birou\") || false;\nlet hvacOn_Camera_Spate = flow.get(\"hvacOn_Camera_Spate\") || false;\nlet hvacOn_Camera_Bia = flow.get(\"hvacOn_Camera_Bia\") || false;\nlet hvacOn_Living = flow.get(\"hvacOn_Living\") || false;\n\n// Airco states from Home Assistant (replace these with the actual entity state IDs if necessary)\nlet hvacState_Birou = msg.payload.hvac_state_birou; // State of birou\nlet hvacState_Camera_Spate = msg.payload.hvac_state_camera_spate; // State of camera_spate\nlet hvacState_Camera_Bia = msg.payload.hvac_state_camera_bia; // State of camera_bia\nlet hvacState_Living = msg.payload.hvac_state_living; // State of camera_bia\n\n// Thresholds for each airco (1.8 kW increments)\nconst threshold = 1.8;\nconst threshold_birou = threshold * 4;\nconst threshold_camera_spate = threshold * 2;\nconst threshold_camera_bia = threshold;\nconst threshold_living = threshold * 3;\n\n\n// Log the incoming values to check they are as expected\nnode.warn(`Produced Power: ${producedPower}`);\nnode.warn(`Consumption Power: ${consumptionPower}`);\nnode.warn(`HVAC States: [${hvacState_Birou}, ${hvacState_Camera_Spate}, ${hvacState_Camera_Bia}, ${hvacState_Living}]`);\n\n// Calculate the difference between production and consumption\nlet powerDifference = producedPower - consumptionPower;\n\n// Array to hold actions for each airco\nlet actions = [null, null, null, null]; // [birou_action, camera_spate_action, camera_bia_action, living_action]\n\n// Logic for turning aircos ON based on power difference and their current state\nif (powerDifference >= threshold_birou && !hvacOn_Birou && hvacState_Birou !== \"heat\") {\n    node.warn(\"Condition to turn ON birou met\");\n    flow.set(\"hvacOn_Birou\", true);\n    actions[0] = \"turn_on_birou\"; // Start birou\n} else if (powerDifference >= threshold_camera_spate && !hvacOn_Camera_Spate && hvacState_Camera_Spate !== \"heat\") {\n    node.warn(\"Condition to turn ON camera_spate met\");\n    flow.set(\"hvacOn_Camera_Spate\", true);\n    actions[1] = \"turn_on_camera_spate\"; // Start camera_spate\n} else if (powerDifference >= threshold_camera_bia && !hvacOn_Camera_Bia && hvacState_Camera_Bia !== \"heat\") {\n    node.warn(\"Condition to turn ON camera_bia met\");\n    flow.set(\"hvacOn_Camera_Bia\", true);\n    actions[2] = \"turn_on_camera_bia\"; // Start camera_bia\n} else if (powerDifference >= threshold_living && !hvacOn_Living && hvacState_Living !== \"heat\") {\n    node.warn(\"Condition to turn ON living met\");\n    flow.set(\"hvacOn_Living\", true);\n    actions[2] = \"turn_on_living\"; // Start living\n}\n\n// Logic for turning aircos OFF based on power difference and their current state\nif (powerDifference < threshold_birou && hvacOn_Birou && hvacState_Birou === \"heat\") {\n    node.warn(\"Condition to turn OFF birou met\");\n    flow.set(\"hvacOn_Birou\", false);\n    actions[0] = \"turn_off_birou\"; // Stop birou\n} else if (powerDifference < threshold_camera_spate && hvacOn_Camera_Spate && hvacState_Camera_Spate === \"heat\") {\n    node.warn(\"Condition to turn OFF camera_spate met\");\n    flow.set(\"hvacOn_Camera_Spate\", false);\n    actions[1] = \"turn_off_camera_spate\"; // Stop camera_spate\n} else if (powerDifference < threshold_camera_bia && hvacOn_Camera_Bia && hvacState_Camera_Bia === \"heat\") {\n    node.warn(\"Condition to turn OFF camera_bia met\");\n    flow.set(\"hvacOn_Camera_Bia\", false);\n    actions[2] = \"turn_off_camera_bia\"; // Stop camera_bia\n} else if (powerDifference < threshold_living && hvacOn_Living && hvacState_Living === \"heat\") {\n    node.warn(\"Condition to turn OFF living met\");\n    flow.set(\"hvacOn_Living\", false);\n    actions[2] = \"turn_off_living\"; // Stop living\n}\n\n// Log actions to understand which commands will be sent\nactions.forEach((action, index) => {\n    if (action) {\n        node.warn(`Action for airco${index + 1}: ${action}`);\n    } else {\n        node.warn(`No action for airco${index + 1}`);\n    }\n});\n\n// Send commands only for the actions that need to be executed\nlet outputs = [null, null, null, null];\nif (actions[0]) outputs[0] = { payload: actions[0] };\nif (actions[1]) outputs[1] = { payload: actions[1] };\nif (actions[2]) outputs[2] = { payload: actions[2] };\nif (actions[3]) outputs[3] = { payload: actions[3] };\n\n// Return array to handle multiple outputs in Node-RED\nreturn outputs;\n",
        "outputs": 2,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 110,
        "y": 1020,
        "wires": [
            [
                "a3cb44595d649192",
                "adf7b93e4172643d",
                "662f7010c288b1a2",
                "8708037e4b45f955",
                "a7b29be52fd7ede3",
                "dcb97f5730483625",
                "4241a87a8936f42b",
                "42d292b5fda422de",
                "f4ce43abca81110c",
                "2db964369d6f62ab",
                "ebc630d94fd2873d",
                "c751a08a12001259"
            ],
            [
                "111bf4374f45d866",
                "ac808c23f7f85932",
                "cf5555eb83aeec1f",
                "fb18651e711090fa"
            ]
        ]
    }
]

Thank you