Shelly Pill temperature sensors

I found a recent thread about the Shelly Pill: https://community.victronenergy.com/t/how-to-use-data-from-shelly-pill-with-attached-temperature-sensor-in-vrm-dashboard/63241 But It wasn’t clear if the Pill can easily be used with its Wifi connection to VenusOS. The Pill is a tiny and affordable way to get temperature values into Venus. I wasn’t sure if I could use it connected via WiFi to control diversion loads or integrate into Opportunity Loads (OL) in Node Red.

However it does work, and I thought I’d say so for others that might do a search. I have the Pill with 5 x temperature probes, some placed in my thermal store probe pockets, so I can use these values to amend my diversion control logic with OL based on the store temperature.

The Pill publishes to the dbus, so the temperatures show up in VRM in the device list and dashboard, I’m only using Wifi to connect, there’s no need for MQTT etc. I simply did it vibe coding with Gemini.

Initially all I had to do was log in on a browser to the Pill and set a static IP address, then use that address in the ‘Get Pill Components’ http request node. The Victron ‘Virtual Device’ node is used for publishing all of the temperature probes individually to the dbus.

Here’s my flow to get the temperatures of all 5 probes. Hope that’s useful info for someone.

[
    {
        "id": "4883200e0abeb165",
        "type": "group",
        "z": "323a1aa7a6d42be7",
        "style": {
            "stroke": "#999999",
            "stroke-opacity": "1",
            "fill": "none",
            "fill-opacity": "1",
            "label": true,
            "label-position": "nw",
            "color": "#a4a4a4"
        },
        "nodes": [
            "d05b8cd415762575",
            "1b0a59fe0cfd7eb2",
            "88c90b880b6cc1d9",
            "ccdfc3697ea267ef",
            "5d87d5783742e4a6",
            "8bb0ac5bbd5d5dfc",
            "0d23c68c08aecb3f",
            "cb1d45dbb5be6227",
            "a9d4f5f23ce2b2d0"
        ],
        "x": 14,
        "y": 496.5,
        "w": 1212,
        "h": 364.5
    },
    {
        "id": "d05b8cd415762575",
        "type": "inject",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "Poll Pill",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "5",
        "crontab": "",
        "once": true,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "iso",
        "payloadType": "date",
        "x": 120,
        "y": 560,
        "wires": [
            [
                "1b0a59fe0cfd7eb2"
            ]
        ]
    },
    {
        "id": "1b0a59fe0cfd7eb2",
        "type": "http request",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "Get Pill Components",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "http://192.168.18.150/rpc/Shelly.GetComponents?dynamic_only=true&include=[\"status\"]",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 320,
        "y": 560,
        "wires": [
            [
                "88c90b880b6cc1d9"
            ]
        ]
    },
    {
        "id": "88c90b880b6cc1d9",
        "type": "function",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "Parse Pill Temps",
        "func": "let components = msg.payload.components || [];\n\n// 1. Create a clean key-value lookup table\nlet data = {};\nfor (let c of components) {\n    if (c.key && c.status && c.status.tC !== undefined) {\n        data[c.key] = c.status.tC;\n    }\n}\n\n// 2. Extract all 5 probe readings\nlet t200 = data[\"temperature:200\"] !== undefined ? data[\"temperature:200\"] : null;\nlet t201 = data[\"temperature:201\"] !== undefined ? data[\"temperature:201\"] : null;\nlet t202 = data[\"temperature:202\"] !== undefined ? data[\"temperature:202\"] : null;\nlet t203 = data[\"temperature:203\"] !== undefined ? data[\"temperature:203\"] : null;\nlet t204 = data[\"temperature:204\"] !== undefined ? data[\"temperature:204\"] : null;\n\n// 3. Save into Flow Context\n// Active tank controls:\nif (t200 !== null) flow.set('tank_temp_top', t200);\nif (t201 !== null) flow.set('tank_temp_bottom', t201);\n\n// Spare probes stored in flow context for future automation:\nif (t202 !== null) flow.set('temp_202', t202);\nif (t203 !== null) flow.set('temp_203', t203);\nif (t204 !== null) flow.set('temp_204', t204);\n\n// 4. Build output messages formatted for Victron Virtual D-Bus nodes\nlet msg200 = t200 !== null ? { payload: { \"/Temperature\": t200 } } : null;\nlet msg201 = t201 !== null ? { payload: { \"/Temperature\": t201 } } : null;\nlet msg202 = t202 !== null ? { payload: { \"/Temperature\": t202 } } : null;\nlet msg203 = t203 !== null ? { payload: { \"/Temperature\": t203 } } : null;\nlet msg204 = t204 !== null ? { payload: { \"/Temperature\": t204 } } : null;\n\n// Return all 5 outputs sequentially:\n// Output 1 -> Tank Top (200)\n// Output 2 -> Tank Bottom (201)\n// Output 3 -> T 202\n// Output 4 -> T 203\n// Output 5 -> T 204\nreturn [msg200, msg201, msg202, msg203, msg204];",
        "outputs": 5,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 580,
        "y": 560,
        "wires": [
            [
                "5d87d5783742e4a6"
            ],
            [
                "8bb0ac5bbd5d5dfc"
            ],
            [
                "0d23c68c08aecb3f"
            ],
            [
                "cb1d45dbb5be6227"
            ],
            [
                "a9d4f5f23ce2b2d0"
            ]
        ]
    },
    {
        "id": "ccdfc3697ea267ef",
        "type": "debug",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "debug 4",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload[\"/Temperature\"]",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1120,
        "y": 740,
        "wires": []
    },
    {
        "id": "5d87d5783742e4a6",
        "type": "victron-virtual",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "Tank Top",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_position": 0,
        "heatpump_nrofphases": 1,
        "heatpump_phasesetting": 1,
        "heatpump_auto_energy": true,
        "evcs_nrofphases": 1,
        "battery_capacity": 25,
        "include_battery_temperature": false,
        "battery_voltage_preset": "24",
        "battery_voltage_custom": 24,
        "generator_type": "ac",
        "generator_nrofphases": 1,
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "grid_nrofphases": 1,
        "energymeter_role": "",
        "energymeter_position": 0,
        "energymeter_nrofphases": 1,
        "energymeter_phasesetting": 1,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "position": 0,
        "pvinverter_nrofphases": 1,
        "pvinverter_auto_energy": true,
        "switch_1_type": 1,
        "switch_1_min": 0,
        "switch_1_max": "",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_unit": "",
        "switch_1_step": 1,
        "switch_1_customname": "",
        "switch_1_group": "",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_passthrough_mode": "auto_only",
        "fluid_type": 0,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": 3.3,
        "tank_capacity": 0.2,
        "auto_aggregate": false,
        "pulsemeter_multiplier": 0.001,
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": 3.3,
        "start_disconnected": false,
        "x": 820,
        "y": 580,
        "wires": [
            [
                "ccdfc3697ea267ef"
            ]
        ]
    },
    {
        "id": "8bb0ac5bbd5d5dfc",
        "type": "victron-virtual",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "Tank Bottom",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_position": 0,
        "heatpump_nrofphases": 1,
        "heatpump_phasesetting": 1,
        "heatpump_auto_energy": true,
        "evcs_nrofphases": 1,
        "battery_capacity": 25,
        "include_battery_temperature": false,
        "battery_voltage_preset": "24",
        "battery_voltage_custom": 24,
        "generator_type": "ac",
        "generator_nrofphases": 1,
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "grid_nrofphases": 1,
        "energymeter_role": "",
        "energymeter_position": 0,
        "energymeter_nrofphases": 1,
        "energymeter_phasesetting": 1,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "position": 0,
        "pvinverter_nrofphases": 1,
        "pvinverter_auto_energy": true,
        "switch_1_type": 1,
        "switch_1_min": 0,
        "switch_1_max": "",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_unit": "",
        "switch_1_step": 1,
        "switch_1_customname": "",
        "switch_1_group": "",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_passthrough_mode": "auto_only",
        "fluid_type": 0,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": 3.3,
        "tank_capacity": 0.2,
        "auto_aggregate": false,
        "pulsemeter_multiplier": 0.001,
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": 3.3,
        "start_disconnected": false,
        "x": 830,
        "y": 640,
        "wires": [
            [
                "ccdfc3697ea267ef"
            ]
        ]
    },
    {
        "id": "0d23c68c08aecb3f",
        "type": "victron-virtual",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "T 202",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_position": 0,
        "heatpump_nrofphases": 1,
        "heatpump_phasesetting": 1,
        "heatpump_auto_energy": true,
        "evcs_nrofphases": 1,
        "battery_capacity": 25,
        "include_battery_temperature": false,
        "battery_voltage_preset": "24",
        "battery_voltage_custom": 24,
        "generator_type": "ac",
        "generator_nrofphases": 1,
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "grid_nrofphases": 1,
        "energymeter_role": "",
        "energymeter_position": 0,
        "energymeter_nrofphases": 1,
        "energymeter_phasesetting": 1,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "position": 0,
        "pvinverter_nrofphases": 1,
        "pvinverter_auto_energy": true,
        "switch_1_type": 1,
        "switch_1_min": 0,
        "switch_1_max": "",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_unit": "",
        "switch_1_step": 1,
        "switch_1_customname": "",
        "switch_1_group": "",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_passthrough_mode": "auto_only",
        "fluid_type": 0,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": 3.3,
        "tank_capacity": 0.2,
        "auto_aggregate": false,
        "pulsemeter_multiplier": 0.001,
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": 3.3,
        "start_disconnected": false,
        "x": 810,
        "y": 700,
        "wires": [
            [
                "ccdfc3697ea267ef"
            ]
        ]
    },
    {
        "id": "cb1d45dbb5be6227",
        "type": "victron-virtual",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "T 203",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_position": 0,
        "heatpump_nrofphases": 1,
        "heatpump_phasesetting": 1,
        "heatpump_auto_energy": true,
        "evcs_nrofphases": 1,
        "battery_capacity": 25,
        "include_battery_temperature": false,
        "battery_voltage_preset": "24",
        "battery_voltage_custom": 24,
        "generator_type": "ac",
        "generator_nrofphases": 1,
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "grid_nrofphases": 1,
        "energymeter_role": "",
        "energymeter_position": 0,
        "energymeter_nrofphases": 1,
        "energymeter_phasesetting": 1,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "position": 0,
        "pvinverter_nrofphases": 1,
        "pvinverter_auto_energy": true,
        "switch_1_type": 1,
        "switch_1_min": 0,
        "switch_1_max": "",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_unit": "",
        "switch_1_step": 1,
        "switch_1_customname": "",
        "switch_1_group": "",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_passthrough_mode": "auto_only",
        "fluid_type": 0,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": 3.3,
        "tank_capacity": 0.2,
        "auto_aggregate": false,
        "pulsemeter_multiplier": 0.001,
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": 3.3,
        "start_disconnected": false,
        "x": 810,
        "y": 760,
        "wires": [
            [
                "ccdfc3697ea267ef"
            ]
        ]
    },
    {
        "id": "a9d4f5f23ce2b2d0",
        "type": "victron-virtual",
        "z": "323a1aa7a6d42be7",
        "g": "4883200e0abeb165",
        "name": "T 204",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_position": 0,
        "heatpump_nrofphases": 1,
        "heatpump_phasesetting": 1,
        "heatpump_auto_energy": true,
        "evcs_nrofphases": 1,
        "battery_capacity": 25,
        "include_battery_temperature": false,
        "battery_voltage_preset": "24",
        "battery_voltage_custom": 24,
        "generator_type": "ac",
        "generator_nrofphases": 1,
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "grid_nrofphases": 1,
        "energymeter_role": "",
        "energymeter_position": 0,
        "energymeter_nrofphases": 1,
        "energymeter_phasesetting": 1,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "position": 0,
        "pvinverter_nrofphases": 1,
        "pvinverter_auto_energy": true,
        "switch_1_type": 1,
        "switch_1_min": 0,
        "switch_1_max": "",
        "switch_1_initial": 0,
        "switch_1_label": "",
        "switch_1_unit": "",
        "switch_1_step": 1,
        "switch_1_customname": "",
        "switch_1_group": "",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_passthrough_mode": "auto_only",
        "fluid_type": 0,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": 3.3,
        "tank_capacity": 0.2,
        "auto_aggregate": false,
        "pulsemeter_multiplier": 0.001,
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": 3.3,
        "start_disconnected": false,
        "x": 810,
        "y": 820,
        "wires": [
            [
                "ccdfc3697ea267ef"
            ]
        ]
    },
    {
        "id": "5c344e8b9254197d",
        "type": "global-config",
        "env": [],
        "modules": {
            "@victronenergy/node-red-contrib-victron": "1.7.27"
        }
    }
]

Great solution that works!
Thanks a million
Michael

I wasn’t sure if you had yours working or not already, and the thread was closed so I couldn’t ask you. I was surprised how easy it was in the end, as I bought the Pill not really knowing whether it would or wouldn’t work!

Just an update.

Here is my whole flow, integrating the Shelly Pill and Shelly 4PM to control my 3 element immersion, either with solar excess or from the Generator. I have added more complex criteria than Opportunity Loads would allow including if the Quattro is in overload, and to make sure the batteries and Quattro don’t overheat. All vibe coded with Gemini 4 Argon providing a .JSON to upload when more than a simple bit of code to edit a node.


[
    {
        "id": "491e2f6b782fe415",
        "type": "tab",
        "label": "Hot Water & Shelly 4PM v5",
        "disabled": false,
        "info": "v5: Adds SmartShunt Net Battery Power Solar Staging, Quattro Internal Overtemp & Overload Alarm Shedding, and Auxiliary Cooling Fan Output."
    },
    {
        "id": "8304153b53a77f41",
        "type": "victron-input-custom",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.battery/1024",
        "path": "/Info/ChargeMode",
        "serviceObj": {
            "service": "com.victronenergy.battery/1024",
            "name": "Battery Aggregator (1024)"
        },
        "pathObj": {
            "path": "/Info/ChargeMode",
            "name": "/Info/ChargeMode",
            "type": "string",
            "value": "Bulk"
        },
        "initial": "",
        "name": "BatteryAggregator Mode",
        "onlyChanges": false,
        "x": 150,
        "y": 40,
        "wires": [
            [
                "1da112373040532f"
            ]
        ]
    },
    {
        "id": "1da112373040532f",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Charge Mode",
        "func": "flow.set('battery_mode', msg.payload);\nnode.status({ fill: msg.payload === 'Float' ? 'green' : 'blue', shape: 'dot', text: String(msg.payload) });\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 40,
        "wires": []
    },
    {
        "id": "07faf7a1d3dfbb77",
        "type": "victron-input-vebus",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.vebus/274",
        "path": "/Ac/Out/L1/P",
        "serviceObj": {
            "service": "com.victronenergy.vebus/274",
            "name": "Quattro 24/8000/200-2x100"
        },
        "pathObj": {
            "path": "/Ac/Out/L1/P",
            "type": "float",
            "name": "Output power phase 1 (W)"
        },
        "name": "Quattro Power (W)",
        "onlyChanges": false,
        "roundValues": "0",
        "x": 130,
        "y": 100,
        "wires": [
            [
                "c6e2607d54201edc"
            ]
        ]
    },
    {
        "id": "c6e2607d54201edc",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Quattro Power",
        "func": "flow.set('quattro_power', Number(msg.payload));\nnode.status({ fill: 'blue', shape: 'dot', text: `${msg.payload} W` });\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 100,
        "wires": []
    },
    {
        "id": "fdeef9923fc4020a",
        "type": "victron-input-battery",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.battery/275",
        "path": "/Soc",
        "serviceObj": {
            "service": "com.victronenergy.battery/275",
            "name": "B SmartShunt"
        },
        "pathObj": {
            "path": "/Soc",
            "type": "float",
            "name": "State of charge (%)"
        },
        "initial": "",
        "name": "SmartShunt (SOC)",
        "onlyChanges": false,
        "roundValues": "1",
        "x": 130,
        "y": 160,
        "wires": [
            [
                "81ae2a1239e35cba"
            ]
        ]
    },
    {
        "id": "81ae2a1239e35cba",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Battery SOC",
        "func": "flow.set('battery_soc', Number(msg.payload));\nnode.status({ fill: 'blue', shape: 'dot', text: `${msg.payload}%` });\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 160,
        "wires": []
    },
    {
        "id": "3dc740ed112706f9",
        "type": "victron-input-temperature",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.temperature/22",
        "path": "/Temperature",
        "serviceObj": {
            "service": "com.victronenergy.temperature/22",
            "name": "LFP Chest"
        },
        "pathObj": {
            "path": "/Temperature",
            "type": "float",
            "name": "Temperature (°C)"
        },
        "name": "LFP Chest (°C)",
        "onlyChanges": false,
        "roundValues": "1",
        "x": 120,
        "y": 220,
        "wires": [
            [
                "9d3e130f3d81ac5e"
            ]
        ]
    },
    {
        "id": "9d3e130f3d81ac5e",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Chest Temp",
        "func": "flow.set('chest_temp', Number(msg.payload));\nnode.status({ fill: msg.payload >= 34 ? 'red' : 'green', shape: 'dot', text: `${msg.payload} °C` });\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 390,
        "y": 220,
        "wires": []
    },
    {
        "id": "a624c9d60e439add",
        "type": "inject",
        "z": "491e2f6b782fe415",
        "name": "Shelly Master Mode (Auto / Force ON All / Force OFF)",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 260,
        "y": 380,
        "wires": [
            [
                "1350c5988e470880"
            ]
        ]
    },
    {
        "id": "1350c5988e470880",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Toggle Master Override",
        "func": "let current = flow.get('manual_override') || 0;\nlet next = (current + 1) % 3; // 0 = Per-Channel/Auto, 1 = Force ON All, 2 = Force OFF All\nflow.set('manual_override', next);\nnode.status({ fill: next === 0 ? 'green' : 'yellow', shape: 'dot', text: ['Auto (Use VRM Switches)', 'Master Force ON All', 'Master Force OFF All'][next] });\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "flow.set('manual_override', 0);\nnode.status({ fill: 'green', shape: 'dot', text: 'Auto (Use VRM Switches)' });",
        "finalize": "",
        "libs": [],
        "x": 690,
        "y": 380,
        "wires": []
    },
    {
        "id": "33a9467a57df528d",
        "type": "inject",
        "z": "491e2f6b782fe415",
        "name": "AC Out 2 - Toggle (Auto / Force ON / Force OFF)",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 240,
        "y": 320,
        "wires": [
            [
                "f8ee19cddf6e407c"
            ]
        ]
    },
    {
        "id": "f8ee19cddf6e407c",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Sync VRM AC Out 2 Switch & Override",
        "func": "const colors = ['green', 'yellow', 'red'];\nconst labels = [\n    'AC Out 2: AUTO (VRM ON / Follows Settings)',\n    'AC Out 2: FORCED ON (Shelly stays powered)',\n    'AC Out 2: FORCED OFF (Switched OFF in VRM/Node-RED)'\n];\n\n// Check if message came from VRM / Venus GX Relay 2 state change (payload is 0 or 1)\nif (msg.payload === 0 || msg.payload === 1) {\n    let actual = Number(msg.payload);\n    let expected = flow.get('expected_gx_relay2');\n    let lastCmd = flow.get('last_gx_relay2_cmd_time') || 0;\n\n    // On initial boot, record current state\n    if (expected === undefined) {\n        flow.set('expected_gx_relay2', actual);\n        return null;\n    }\n\n    // If this change was NOT commanded by Node-RED, the user clicked the VRM 'AC OUT 2' switch!\n    if (actual !== expected && (Date.now() - lastCmd) > 1000) {\n        let next = (actual === 0) ? 2 : 0; // VRM OFF (0) -> Force OFF (2) | VRM ON (1) -> Auto (0)\n        flow.set('acout2_override', next);\n        flow.set('expected_gx_relay2', actual);\n        node.status({ fill: colors[next], shape: 'dot', text: labels[next] });\n    }\n    return null;\n}\n\n// Otherwise, message came from the Node-RED Inject button: cycle 0 (Auto) -> 1 (Force ON) -> 2 (Force OFF)\nlet current = flow.get('acout2_override') ?? 0;\nlet next = (current + 1) % 3;\nflow.set('acout2_override', next);\nnode.status({\n    fill: colors[next],\n    shape: 'dot',\n    text: labels[next]\n});\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "flow.set('acout2_override', 0);\nnode.status({ fill: 'green', shape: 'dot', text: 'AC Out 2: AUTO (VRM ON / Follows Settings)' });",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 320,
        "wires": []
    },
    {
        "id": "6a95da82011e3029",
        "type": "inject",
        "z": "491e2f6b782fe415",
        "name": "DRY RUN -Toggle Mode (Safe Test Mode)",
        "props": [],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 220,
        "y": 430,
        "wires": [
            [
                "e0ae5b35b474a3e4"
            ]
        ]
    },
    {
        "id": "e0ae5b35b474a3e4",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Set Dry Run Flag",
        "func": "let current = flow.get('dry_run_mode') || false;\nlet next = !current;\nflow.set('dry_run_mode', next);\nnode.status({\n    fill: next ? 'yellow' : 'green',\n    shape: next ? 'ring' : 'dot',\n    text: next ? 'DRY RUN ACTIVE (Relays will NOT switch)' : 'LIVE MODE (Relays WILL switch)'\n});\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "flow.set('dry_run_mode', false);\nnode.status({ fill: 'green', shape: 'dot', text: 'LIVE MODE (Relays WILL switch)' });",
        "finalize": "",
        "libs": [],
        "x": 670,
        "y": 430,
        "wires": []
    },
    {
        "id": "3f3bd3d8778a6ac6",
        "type": "inject",
        "z": "491e2f6b782fe415",
        "name": "5s Master Heartbeat & Poll",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "5",
        "crontab": "",
        "once": true,
        "onceDelay": "1",
        "topic": "",
        "payload": "iso",
        "payloadType": "date",
        "x": 180,
        "y": 500,
        "wires": [
            [
                "8b90bbc4fed8253e",
                "8396166ad3b4925a",
                "37c6f2ed9c3d8b38"
            ]
        ]
    },
    {
        "id": "4d6c088c72ebd823",
        "type": "http request",
        "z": "491e2f6b782fe415",
        "name": "Get Pill Temps (.150)",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 680,
        "y": 500,
        "wires": [
            [
                "9848fdcf4723cd3e"
            ]
        ]
    },
    {
        "id": "9848fdcf4723cd3e",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Parse Pill Temps",
        "func": "let components = (msg.payload && msg.payload.components) ? msg.payload.components : [];\n\nlet data = {};\nfor (let c of components) {\n    if (c.key && c.status && c.status.tC !== undefined) {\n        data[c.key] = c.status.tC;\n    }\n}\n\nlet t200 = data[\"temperature:200\"] !== undefined ? data[\"temperature:200\"] : null;\nlet t201 = data[\"temperature:201\"] !== undefined ? data[\"temperature:201\"] : null;\nlet t202 = data[\"temperature:202\"] !== undefined ? data[\"temperature:202\"] : null;\nlet t203 = data[\"temperature:203\"] !== undefined ? data[\"temperature:203\"] : null;\nlet t204 = data[\"temperature:204\"] !== undefined ? data[\"temperature:204\"] : null;\n\nif (t200 !== null) flow.set('tank_temp_top', t200);\nif (t201 !== null) flow.set('tank_temp_bottom', t201);\nif (t202 !== null) flow.set('temp_202', t202);\nif (t203 !== null) flow.set('temp_203', t203);\nif (t204 !== null) flow.set('temp_204', t204);\n\nnode.status({ fill: 'green', shape: 'dot', text: `Top: ${t200}°C | Bot: ${t201}°C` });\n\nlet msg200 = t200 !== null ? { payload: { \"/Temperature\": t200 } } : null;\nlet msg201 = t201 !== null ? { payload: { \"/Temperature\": t201 } } : null;\nlet msg202 = t202 !== null ? { payload: { \"/Temperature\": t202 } } : null;\nlet msg203 = t203 !== null ? { payload: { \"/Temperature\": t203 } } : null;\nlet msg204 = t204 !== null ? { payload: { \"/Temperature\": t204 } } : null;\n\nreturn [msg200, msg201, msg202, msg203, msg204];",
        "outputs": 5,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 900,
        "y": 500,
        "wires": [
            [
                "43e16b617b8b7036"
            ],
            [
                "13c572f21a77eb3e"
            ],
            [
                "7b342957d8e6e736"
            ],
            [
                "4892e4ed72ca2849"
            ],
            [
                "ad16826ded951357"
            ]
        ]
    },
    {
        "id": "43e16b617b8b7036",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "Tank Top",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "start_disconnected": false,
        "x": 1100,
        "y": 400,
        "wires": [
            []
        ]
    },
    {
        "id": "13c572f21a77eb3e",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "Tank Bottom",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "start_disconnected": false,
        "x": 1110,
        "y": 460,
        "wires": [
            []
        ]
    },
    {
        "id": "7b342957d8e6e736",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "T 202",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "start_disconnected": false,
        "x": 1090,
        "y": 510,
        "wires": [
            []
        ]
    },
    {
        "id": "4892e4ed72ca2849",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "T 203",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "start_disconnected": false,
        "x": 1090,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "ad16826ded951357",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "T 204",
        "outputs": 1,
        "device": "temperature",
        "default_values": true,
        "temperature_type": "5",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "start_disconnected": false,
        "x": 1090,
        "y": 610,
        "wires": [
            []
        ]
    },
    {
        "id": "51f8d9365bc05dd5",
        "type": "http request",
        "z": "491e2f6b782fe415",
        "name": "Poll Shelly 4PM (.151)",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 460,
        "y": 620,
        "wires": [
            [
                "84796aa3d1eea895"
            ]
        ]
    },
    {
        "id": "84796aa3d1eea895",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Parse Shelly 4PM Status & Temps",
        "func": "if (msg.statusCode !== 200 || !msg.payload || !msg.payload[\"switch:0\"]) {\n    flow.set('shelly_online', false);\n    flow.set('shelly_online_since', 0);\n    node.status({ fill: \"grey\", shape: \"ring\", text: \"Shelly 4PM Offline (Unpowered)\" });\n    return null;\n}\n\nlet wasOnline = flow.get('shelly_online') || false;\nlet now = Date.now();\nif (!wasOnline) {\n    flow.set('shelly_online', true);\n    flow.set('shelly_online_since', now);\n}\n\nlet p0 = Number(msg.payload[\"switch:0\"].apower || 0);\nlet p1 = Number(msg.payload[\"switch:1\"].apower || 0);\nlet p2 = Number(msg.payload[\"switch:2\"].apower || 0);\nlet p3 = Number(msg.payload[\"switch:3\"].apower || 0);\nlet immersionTotalW = p0 + p1 + p2;\n\nlet pcbTemp = (msg.payload[\"switch:0\"].temperature && msg.payload[\"switch:0\"].temperature.tC !== undefined)\n    ? Number(msg.payload[\"switch:0\"].temperature.tC)\n    : 25.0;\n\nflow.set('shelly_pcb_temp', pcbTemp);\nflow.set('shelly_total_immersion_power', immersionTotalW);\nflow.set('shelly_aux_power', p3);\nflow.set('shelly_states', [\n    Boolean(msg.payload[\"switch:0\"].output),\n    Boolean(msg.payload[\"switch:1\"].output),\n    Boolean(msg.payload[\"switch:2\"].output),\n    Boolean(msg.payload[\"switch:3\"].output)\n]);\n\nnode.status({\n    fill: pcbTemp >= 75 ? \"red\" : \"green\",\n    shape: \"dot\",\n    text: `Imm: ${immersionTotalW.toFixed(0)}W | Socket: ${p3.toFixed(0)}W | PCB: ${pcbTemp.toFixed(1)}°C`\n});\n\nlet msgImmersionLoad = {\n    payload: {\n        \"/Ac/L1/Power\": immersionTotalW,\n        \"/Ac/Power\": immersionTotalW,\n        \"/Ac/L1/Current\": Number((immersionTotalW / 230).toFixed(1))\n    }\n};\n\nlet msgSocketLoad = {\n    payload: {\n        \"/Ac/L1/Power\": p3,\n        \"/Ac/Power\": p3,\n        \"/Ac/L1/Current\": Number((p3 / 230).toFixed(1))\n    }\n};\n\nreturn [msgImmersionLoad, msgSocketLoad];",
        "outputs": 2,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 720,
        "y": 620,
        "wires": [
            [
                "d5acd26e671fcabc"
            ],
            [
                "8373c5895674249f"
            ]
        ]
    },
    {
        "id": "d5acd26e671fcabc",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "Solar / Genny Immersions Power",
        "outputs": 1,
        "device": "acload",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_auto_energy": false,
        "battery_capacity": "",
        "include_battery_temperature": false,
        "battery_voltage_custom": "",
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "pvinverter_auto_energy": false,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": "",
        "tank_capacity": "",
        "auto_aggregate": false,
        "pulsemeter_multiplier": "",
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": "",
        "start_disconnected": false,
        "x": 1180,
        "y": 660,
        "wires": [
            []
        ]
    },
    {
        "id": "8373c5895674249f",
        "type": "victron-virtual",
        "z": "491e2f6b782fe415",
        "name": "Solar / Genny Socket Power",
        "outputs": 1,
        "device": "acload",
        "default_values": true,
        "acload_position": 0,
        "acload_nrofphases": 1,
        "acload_phasesetting": 1,
        "acload_auto_energy": true,
        "enable_s2support": false,
        "s2_measurement_type": "L1",
        "heatpump_auto_energy": false,
        "battery_capacity": "",
        "include_battery_temperature": false,
        "battery_voltage_custom": "",
        "include_engine_hours": false,
        "include_starter_voltage": false,
        "include_history_energy": false,
        "generator_grid_meter_only": false,
        "include_motor_temp": false,
        "include_controller_temp": false,
        "include_coolant_temp": false,
        "include_motor_rpm": true,
        "include_motor_direction": true,
        "pvinverter_auto_energy": false,
        "include_tank_battery": false,
        "include_tank_temperature": false,
        "tank_battery_voltage": "",
        "tank_capacity": "",
        "auto_aggregate": false,
        "pulsemeter_multiplier": "",
        "ev_vin": "",
        "ev_battery_capacity": "",
        "ev_evcs_device_instance": "",
        "include_humidity": false,
        "include_pressure": false,
        "include_temp_battery": false,
        "temp_battery_voltage": "",
        "start_disconnected": false,
        "x": 1160,
        "y": 720,
        "wires": [
            []
        ]
    },
    {
        "id": "f374d76e8a5f751d",
        "type": "victron-input-digitalinput",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.digitalinput/1",
        "path": "/State",
        "serviceObj": {
            "service": "com.victronenergy.digitalinput/1",
            "name": "Generator",
            "communityTag": "digitalinput"
        },
        "pathObj": {
            "path": "/State",
            "type": "enum",
            "name": "Digital input state",
            "enum": {
                "0": "low",
                "1": "high",
                "2": "off",
                "3": "on",
                "4": "no",
                "5": "yes",
                "6": "open",
                "7": "closed",
                "8": "ok",
                "9": "alarm",
                "10": "running",
                "11": "stopped"
            }
        },
        "name": "Generator Digital Input",
        "onlyChanges": false,
        "roundValues": "no",
        "rateLimit": 0,
        "conditionalMode": false,
        "debounce": "2000",
        "x": 680,
        "y": 160,
        "wires": [
            [
                "75ea33833c067f51"
            ]
        ]
    },
    {
        "id": "75ea33833c067f51",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Generator State",
        "func": "let raw = msg.payload;\nlet isRunning = (raw === 10 || raw === \"running\" || raw === 1 || raw === \"closed\" || raw === true);\n\nflow.set('generator_running', isRunning);\n\nmsg.payload = {\n    \"/StatusCode\": isRunning ? 8 : 0\n};\n\nnode.status({ \n    fill: isRunning ? \"green\" : \"grey\", \n    shape: \"dot\", \n    text: isRunning ? \"Generator RUNNING\" : \"Generator STOPPED\" \n});\n\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 940,
        "y": 160,
        "wires": [
            []
        ]
    },
    {
        "id": "128d7f7b59880313",
        "type": "victron-virtual-switch",
        "z": "491e2f6b782fe415",
        "name": "Switch: Immersion 1",
        "outputs": 3,
        "switch_1_type": 9,
        "switch_1_initial": 0,
        "switch_1_label": "Element 1 (2kW)",
        "switch_1_customname": "Immersion 1 (2kW)",
        "switch_1_group": "Hot Water & Solar",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_show_ui_input": 1,
        "switch_1_passthrough_mode": "auto_only",
        "x": 820,
        "y": 880,
        "wires": [
            [
                "abf8a1aca1d5f376"
            ],
            [
                "237113bcc72576d0"
            ],
            [
                "e5c517b00937ec80"
            ]
        ]
    },
    {
        "id": "abf8a1aca1d5f376",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Sync Ch0 Object",
        "func": "if (msg.payload && typeof msg.payload === 'object') {\n    if (msg.payload['/SwitchableOutput/output_1/Auto'] !== undefined) {\n        flow.set('ch0_auto', Boolean(msg.payload['/SwitchableOutput/output_1/Auto']));\n    }\n    if (msg.payload['/SwitchableOutput/output_1/State'] !== undefined) {\n        flow.set('ch0_manual_state', Boolean(msg.payload['/SwitchableOutput/output_1/State']));\n    }\n}\nreturn null;",
        "outputs": 0,
        "x": 1070,
        "y": 840,
        "wires": []
    },
    {
        "id": "237113bcc72576d0",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch0 Manual State",
        "func": "let s = Boolean(msg.payload);\nflow.set('ch0_manual_state', s);\nlet a = flow.get('ch0_auto') ?? true;\nnode.status({ fill: a ? 'blue' : (s ? 'green' : 'grey'), shape: 'dot', text: a ? 'Mode: AUTO' : (s ? 'MANUAL ON' : 'MANUAL OFF') });\nreturn null;",
        "outputs": 0,
        "x": 1080,
        "y": 875,
        "wires": []
    },
    {
        "id": "e5c517b00937ec80",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch0 Auto Mode",
        "func": "let a = Boolean(msg.payload);\nflow.set('ch0_auto', a);\nlet s = flow.get('ch0_manual_state') || false;\nnode.status({ fill: a ? 'green' : 'yellow', shape: 'dot', text: a ? 'AUTO ENABLED' : `MANUAL (${s ? 'ON' : 'OFF'})` });\nreturn null;",
        "outputs": 0,
        "initialize": "flow.set('ch0_auto', true);",
        "x": 1070,
        "y": 910,
        "wires": []
    },
    {
        "id": "4fc084737390cb06",
        "type": "victron-virtual-switch",
        "z": "491e2f6b782fe415",
        "name": "Switch: Immersion 2",
        "outputs": 3,
        "switch_1_type": 9,
        "switch_1_initial": 0,
        "switch_1_label": "Element 2 (2kW)",
        "switch_1_customname": "Immersion 2 (2kW)",
        "switch_1_group": "Hot Water & Solar",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_show_ui_input": 1,
        "switch_1_passthrough_mode": "auto_only",
        "x": 820,
        "y": 1000,
        "wires": [
            [
                "d35271963868771f"
            ],
            [
                "ec10a87e74b4c4b6"
            ],
            [
                "c0f577f24201d82d"
            ]
        ]
    },
    {
        "id": "d35271963868771f",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Sync Ch1 Object",
        "func": "if (msg.payload && typeof msg.payload === 'object') {\n    if (msg.payload['/SwitchableOutput/output_1/Auto'] !== undefined) {\n        flow.set('ch1_auto', Boolean(msg.payload['/SwitchableOutput/output_1/Auto']));\n    }\n    if (msg.payload['/SwitchableOutput/output_1/State'] !== undefined) {\n        flow.set('ch1_manual_state', Boolean(msg.payload['/SwitchableOutput/output_1/State']));\n    }\n}\nreturn null;",
        "outputs": 0,
        "x": 1070,
        "y": 960,
        "wires": []
    },
    {
        "id": "ec10a87e74b4c4b6",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch1 Manual State",
        "func": "let s = Boolean(msg.payload);\nflow.set('ch1_manual_state', s);\nlet a = flow.get('ch1_auto') ?? true;\nnode.status({ fill: a ? 'blue' : (s ? 'green' : 'grey'), shape: 'dot', text: a ? 'Mode: AUTO' : (s ? 'MANUAL ON' : 'MANUAL OFF') });\nreturn null;",
        "outputs": 0,
        "x": 1080,
        "y": 995,
        "wires": []
    },
    {
        "id": "c0f577f24201d82d",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch1 Auto Mode",
        "func": "let a = Boolean(msg.payload);\nflow.set('ch1_auto', a);\nlet s = flow.get('ch1_manual_state') || false;\nnode.status({ fill: a ? 'green' : 'yellow', shape: 'dot', text: a ? 'AUTO ENABLED' : `MANUAL (${s ? 'ON' : 'OFF'})` });\nreturn null;",
        "outputs": 0,
        "initialize": "flow.set('ch1_auto', true);",
        "x": 1070,
        "y": 1030,
        "wires": []
    },
    {
        "id": "eb5b631c002ae882",
        "type": "victron-virtual-switch",
        "z": "491e2f6b782fe415",
        "name": "Switch: Immersion 3",
        "outputs": 3,
        "switch_1_type": 9,
        "switch_1_initial": 0,
        "switch_1_label": "Element 3 (2kW)",
        "switch_1_customname": "Immersion 3 (2kW)",
        "switch_1_group": "Hot Water & Solar",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_show_ui_input": 1,
        "switch_1_passthrough_mode": "auto_only",
        "x": 820,
        "y": 1120,
        "wires": [
            [
                "0a0920553f44ac4a"
            ],
            [
                "68c1219faabe2ae4"
            ],
            [
                "7a21de6eded86649"
            ]
        ]
    },
    {
        "id": "0a0920553f44ac4a",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Sync Ch2 Object",
        "func": "if (msg.payload && typeof msg.payload === 'object') {\n    if (msg.payload['/SwitchableOutput/output_1/Auto'] !== undefined) {\n        flow.set('ch2_auto', Boolean(msg.payload['/SwitchableOutput/output_1/Auto']));\n    }\n    if (msg.payload['/SwitchableOutput/output_1/State'] !== undefined) {\n        flow.set('ch2_manual_state', Boolean(msg.payload['/SwitchableOutput/output_1/State']));\n    }\n}\nreturn null;",
        "outputs": 0,
        "x": 1070,
        "y": 1080,
        "wires": []
    },
    {
        "id": "68c1219faabe2ae4",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch2 Manual State",
        "func": "let s = Boolean(msg.payload);\nflow.set('ch2_manual_state', s);\nlet a = flow.get('ch2_auto') ?? true;\nnode.status({ fill: a ? 'blue' : (s ? 'green' : 'grey'), shape: 'dot', text: a ? 'Mode: AUTO' : (s ? 'MANUAL ON' : 'MANUAL OFF') });\nreturn null;",
        "outputs": 0,
        "x": 1080,
        "y": 1115,
        "wires": []
    },
    {
        "id": "7a21de6eded86649",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch2 Auto Mode",
        "func": "let a = Boolean(msg.payload);\nflow.set('ch2_auto', a);\nlet s = flow.get('ch2_manual_state') || false;\nnode.status({ fill: a ? 'green' : 'yellow', shape: 'dot', text: a ? 'AUTO ENABLED' : `MANUAL (${s ? 'ON' : 'OFF'})` });\nreturn null;",
        "outputs": 0,
        "initialize": "flow.set('ch2_auto', true);",
        "x": 1070,
        "y": 1150,
        "wires": []
    },
    {
        "id": "bc4df54646cd2960",
        "type": "victron-virtual-switch",
        "z": "491e2f6b782fe415",
        "name": "Switch: Solar Socket 4",
        "outputs": 3,
        "switch_1_type": 9,
        "switch_1_initial": 0,
        "switch_1_label": "Aux Socket (Ch 4)",
        "switch_1_customname": "Solar Socket 4",
        "switch_1_group": "Hot Water & Solar",
        "switch_1_include_measurement": false,
        "switch_1_rgb_color_wheel": false,
        "switch_1_cct_wheel": false,
        "switch_1_rgb_white_dimmer": false,
        "switch_1_show_ui_input": 1,
        "switch_1_passthrough_mode": "auto_only",
        "x": 820,
        "y": 1240,
        "wires": [
            [
                "8b46aabebb6f4360"
            ],
            [
                "0a35a6bae792a6a9"
            ],
            [
                "264145bbc86386b1"
            ]
        ]
    },
    {
        "id": "8b46aabebb6f4360",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Sync Ch3 Object",
        "func": "if (msg.payload && typeof msg.payload === 'object') {\n    if (msg.payload['/SwitchableOutput/output_1/Auto'] !== undefined) {\n        flow.set('ch3_auto', Boolean(msg.payload['/SwitchableOutput/output_1/Auto']));\n    }\n    if (msg.payload['/SwitchableOutput/output_1/State'] !== undefined) {\n        flow.set('ch3_manual_state', Boolean(msg.payload['/SwitchableOutput/output_1/State']));\n    }\n}\nreturn null;",
        "outputs": 0,
        "x": 1070,
        "y": 1200,
        "wires": []
    },
    {
        "id": "0a35a6bae792a6a9",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch3 Manual State",
        "func": "let s = Boolean(msg.payload);\nflow.set('ch3_manual_state', s);\nlet a = flow.get('ch3_auto') ?? true;\nnode.status({ fill: a ? 'blue' : (s ? 'green' : 'grey'), shape: 'dot', text: a ? 'Mode: AUTO' : (s ? 'MANUAL ON' : 'MANUAL OFF') });\nreturn null;",
        "outputs": 0,
        "x": 1080,
        "y": 1235,
        "wires": []
    },
    {
        "id": "264145bbc86386b1",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Ch3 Auto Mode",
        "func": "let a = Boolean(msg.payload);\nflow.set('ch3_auto', a);\nlet s = flow.get('ch3_manual_state') || false;\nnode.status({ fill: a ? 'green' : 'yellow', shape: 'dot', text: a ? 'AUTO ENABLED' : `MANUAL (${s ? 'ON' : 'OFF'})` });\nreturn null;",
        "outputs": 0,
        "initialize": "flow.set('ch3_auto', true);",
        "x": 1070,
        "y": 1270,
        "wires": []
    },
    {
        "id": "37c6f2ed9c3d8b38",
        "type": "delay",
        "z": "491e2f6b782fe415",
        "name": "Wait 500ms for Poll",
        "pauseType": "delay",
        "timeout": "500",
        "timeoutUnits": "milliseconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 150,
        "y": 620,
        "wires": [
            [
                "674cd205db13b2fc"
            ]
        ]
    },
    {
        "id": "674cd205db13b2fc",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "MASTER 4-CHANNEL + QUATTRO ALARM CONTROLLER (Edit Settings Inside)",
        "func": "// ============================================================================\n// USER ADJUSTABLE SETTINGS - EDIT NUMBERS BELOW AS NEEDED\n// ============================================================================\nconst SETTINGS = {\n    // 1. NETWORK ADDRESSES\n    SHELLY_IP: \"192.168.18.151\",      // Shelly Pro 4PM IP address\n    SHELLY_PILL_IP: \"192.168.18.150\",  // Shelly Pill temperature sensors IP address\n\n    // 2. AC OUT 2 (GX RELAY 2) POWER SUPPLY BEHAVIOR IN SUMMER MODE\n    KEEP_AC_OUT2_ON_IN_SUMMER: true,  // true or false - AC Out 2 is on or off - AC Out 2 powers the Shelly controlled Solar excess Immersions + Socket\n\n    // 3. HOT WATER TANK TEMPERATURE LIMITS (°C from Shelly Pill Tank Top probe)\n    TANK_MAX_TEMP_OFF: 90.0,           // Turn OFF all 3 immersions when Tank Top reaches 90°C\n    TANK_RESET_TEMP_ON: 87.0,          // Allow immersions back ON once Tank Top cools to 87°C\n\n    // 4. SHELLY PRO 4PM INTERNAL PCB TEMPERATURE PROTECTION (°C)\n    PCB_HIGH_TEMP_SHED_EL3: 75.0,      // Turn OFF Element 3 if Shelly internal PCB hits 75°C\n    PCB_COOL_TEMP_RESTORE: 70.0,       // Allow Element 3 back ON once Shelly PCB cools to 70°C\n\n    // 5. QUATTRO INTERNAL ALARMS + CHEST TEMPERATURE + EXTERNAL FAN CONTROL\n    // Victron VE.Bus Alarms send: 0 = OK, 1 = Warning (Pre-alarm before trip!), 2 = Alarm\n    QUATTRO_TEMP_WARNING_SHED_ALL: true, // If true, immediately turns OFF all stages if Quattro reports HighTemp Warning (1) or Alarm (2)\n    QUATTRO_ALARM_COOLDOWN_SEC: 180,     // Wait 180s (3 mins) after Quattro internal Temp/Overload warning clears before allowing stages back on\n    CHEST_MAX_TEMP_OFF: 34.0,            // Backup ambient cutout: Turn OFF all solar loads if Battery Chest Ruuvi hits 34°C\n    CHEST_RESET_TEMP_ON: 33.0,           // Allow solar loads back ON once Battery Chest Ruuvi cools to 33°C\n    FAN_ON_CHEST_TEMP: 30.0,             // Output 7 Fan Trigger: Turn ON external extraction fans when Chest Ruuvi >= 30°C (or if Quattro Temp Warning=1)\n    FAN_OFF_CHEST_TEMP: 28.5,            // Turn OFF external fans once Chest Ruuvi cools to <= 28.5°C and Quattro Temp is OK (0)\n\n    // 6. WINTER GENERATOR SEQUENTIAL STARTUP DELAYS (Seconds after Shelly powers up)\n    GEN_DELAY_ELEMENT_1_SEC: 0,        // Wait 1s after Shelly boots -> Turn ON Element 1\n    GEN_DELAY_ELEMENT_2_SEC: 5,        // +3s later (8s total)        -> Turn ON Element 2\n    GEN_DELAY_ELEMENT_3_SEC: 10,       // +3s later (11s total)       -> Turn ON Element 3\n    GEN_DELAY_SOCKET_4_SEC:  15,       // +3s later (14s total)       -> Turn ON Output 4 (Socket)\n\n    // 7. SUMMER SOLAR STAGING & BATTERY BALANCING (DC RIPPLE PROTECTION)\n    SOLAR_PRE_FLOAT_SOC_ON: 92.0,      // Allow ONLY Element 1 (2kW) at 92%+ SOC before Float (absorbs excess solar gently)\n    SOLAR_PRE_FLOAT_MAX_STAGES: 1,     // Max stages before Float - Change to 2 (1=2kW, 2=4kW) if Excess solar throttles MPPTs during balancing\n    SOLAR_FULL_STAGE_SOC_ON: 95.0,     // Once in 'Float' AND above 95% SOC, allow all 4 stages\n    SOLAR_MIN_SOC_CUTOFF: 90.0,        // Turn OFF all solar stages if Battery SOC drops below 90%\n\n    // 8. SOLAR SURPLUS / DEFICIT STAGING & HYSTERESIS TIMERS (Anti-Bounce)\n    SOLAR_STEP_UP_SURPLUS_WATTS: 2100,   // While charging (Bulk/Abs), require +2100W going into battery to add a stage\n    SOLAR_STEP_UP_DELAY_SEC: 25,         // Wait 25s before stepping up a stage\n    SOLAR_STEP_DOWN_DEFICIT_WATTS: -300, // If battery drains faster than -300W, start step-down timer\n    SOLAR_STEP_DOWN_DELAY_SEC: 8,        // Shed 1 stage after 8s of battery drain (< -300W)\n    SOLAR_RETRY_AFTER_DEFICIT_SEC: 300,  // Wait 300s (5 mins) after a solar deficit step-down before probing a step-up in Float\n    QUATTRO_MAX_WATTS_STEP_UP: 4600,     // Allow stepping up to Stage 3 (6kW) + Socket if current Quattro load is < 4600W\n    QUATTRO_OVERLOAD_STEP_DOWN: 6500     // Instant step-down (0s) if total Quattro load exceeds 6500W (e.g. 3 immersions + kettle)\n};\n\n// ============================================================================\n// MAIN CONTROLLER LOGIC\n// ============================================================================\nconst now = Date.now();\n\n// Save IPs into flow context so the HTTP polling prep nodes use them automatically\nflow.set('shelly_pill_ip', SETTINGS.SHELLY_PILL_IP);\nflow.set('shelly_4pm_ip', SETTINGS.SHELLY_IP);\n\nconst shellyOnline       = flow.get('shelly_online') || false;\nconst onlineSince        = flow.get('shelly_online_since') || 0;\nconst genRunning         = flow.get('generator_running') || false;\nconst tankTop            = flow.get('tank_temp_top') ?? 20.0;\nconst pcbTemp            = flow.get('shelly_pcb_temp') ?? 25.0;\nconst chestTemp          = flow.get('chest_temp') ?? 20.0;\nconst soc                = flow.get('battery_soc') ?? 0.0;\nconst battPower          = flow.get('battery_power') ?? 0.0;\nconst battMode           = flow.get('battery_mode') || 'Bulk';\nconst quattroPower       = flow.get('quattro_power') ?? 0;\nconst quattroTempAlarm   = flow.get('quattro_temp_alarm') || 0;     // 0=Ok, 1=Warning, 2=Alarm\nconst quattroOverload    = flow.get('quattro_overload_alarm') || 0; // 0=Ok, 1=Warning, 2=Alarm\nconst override           = flow.get('manual_override') || 0;\nconst acout2Override     = flow.get('acout2_override') ?? 0;         // 0=Auto, 1=Force ON, 2=Force OFF\nconst dryRun             = flow.get('dry_run_mode') || false;\n\n// Per-channel VRM 3-State Virtual Switch settings\nconst chAuto = [\n    flow.get('ch0_auto') ?? true,\n    flow.get('ch1_auto') ?? true,\n    flow.get('ch2_auto') ?? true,\n    flow.get('ch3_auto') ?? true\n];\nconst chManualState = [\n    flow.get('ch0_manual_state') || false,\n    flow.get('ch1_manual_state') || false,\n    flow.get('ch2_manual_state') || false,\n    flow.get('ch3_manual_state') || false\n];\n\n// 1. EVALUATE TEMPERATURE & QUATTRO INTERNAL ALARM INTERLOCKS\n// A. Tank Top 90°C Cutout\nlet tankCut = context.get('tankCut') || false;\nif (!tankCut && tankTop >= SETTINGS.TANK_MAX_TEMP_OFF) tankCut = true;\nelse if (tankCut && tankTop <= SETTINGS.TANK_RESET_TEMP_ON) tankCut = false;\ncontext.set('tankCut', tankCut);\n\n// B. Ambient Battery Chest Ruuvi Cutout\nlet chestCut = context.get('chestCut') || false;\nif (!chestCut && chestTemp >= SETTINGS.CHEST_MAX_TEMP_OFF) chestCut = true;\nelse if (chestCut && chestTemp <= SETTINGS.CHEST_RESET_TEMP_ON) chestCut = false;\ncontext.set('chestCut', chestCut);\n\n// C. Shelly Pro 4PM Internal PCB 75°C Shedding for Element 3\nlet pcbCutEl3 = context.get('pcbCutEl3') || false;\nif (!pcbCutEl3 && pcbTemp >= SETTINGS.PCB_HIGH_TEMP_SHED_EL3) pcbCutEl3 = true;\nelse if (pcbCutEl3 && pcbTemp <= SETTINGS.PCB_COOL_TEMP_RESTORE) pcbCutEl3 = false;\ncontext.set('pcbCutEl3', pcbCutEl3);\n\n// D. Quattro Internal High-Temp & Overload Pre-Alarm / Alarm Lockout + Cooldown Timer\nlet lastQuattroAlarmTime = context.get('lastQuattroAlarmTime') || 0;\nif (quattroTempAlarm > 0 || quattroOverload > 0) {\n    lastQuattroAlarmTime = now;\n    context.set('lastQuattroAlarmTime', lastQuattroAlarmTime);\n}\nlet quattroAlarmCooldownActive = (lastQuattroAlarmTime > 0) && ((now - lastQuattroAlarmTime) < (SETTINGS.QUATTRO_ALARM_COOLDOWN_SEC * 1000));\nlet quattroTempCut = SETTINGS.QUATTRO_TEMP_WARNING_SHED_ALL && (quattroTempAlarm > 0 || (quattroAlarmCooldownActive && context.get('quattroTempTripped')));\nif (quattroTempAlarm > 0) context.set('quattroTempTripped', true);\nelse if (!quattroAlarmCooldownActive) context.set('quattroTempTripped', false);\n\n// E. External Quattro Cooling / Extraction Fan Logic (Output 7)\nlet fanState = context.get('fanState') || 0;\nif (quattroTempAlarm > 0 || chestTemp >= SETTINGS.FAN_ON_CHEST_TEMP) {\n    fanState = 1;\n} else if (quattroTempAlarm === 0 && chestTemp <= SETTINGS.FAN_OFF_CHEST_TEMP) {\n    fanState = 0;\n}\ncontext.set('fanState', fanState);\nlet fanMsg = { payload: fanState };\n\n// 2. DETERMINE GX RELAY 2 (AC OUT 2) STATE\nlet anyManualOn = (!chAuto[0] && chManualState[0]) || (!chAuto[1] && chManualState[1]) || (!chAuto[2] && chManualState[2]) || (!chAuto[3] && chManualState[3]);\nlet gxRelay2State = 0;\nif (override === 2 || acout2Override === 2) {\n    gxRelay2State = 0;\n} else if (override === 1 || acout2Override === 1 || anyManualOn || SETTINGS.KEEP_AC_OUT2_ON_IN_SUMMER) {\n    gxRelay2State = (chestCut || quattroTempCut) ? 0 : 1;\n} else {\n    if (!chestCut && !quattroTempCut && soc >= SETTINGS.SOLAR_PRE_FLOAT_SOC_ON) gxRelay2State = 1;\n    else if (chestCut || quattroTempCut || soc < SETTINGS.SOLAR_MIN_SOC_CUTOFF) gxRelay2State = 0;\n    else gxRelay2State = context.get('gxRelay2State') || 0;\n}\nlet prevExpectedRelay2 = flow.get('expected_gx_relay2');\nif (prevExpectedRelay2 !== gxRelay2State) {\n    flow.set('expected_gx_relay2', gxRelay2State);\n    flow.set('last_gx_relay2_cmd_time', now);\n}\ncontext.set('gxRelay2State', gxRelay2State);\nlet gxRelayMsg = dryRun ? null : { payload: gxRelay2State };\n\nif (!shellyOnline && !dryRun) {\n    node.status({ fill: \"grey\", shape: \"ring\", text: `Waiting for Shelly power... (AC Out 2: ${gxRelay2State ? 'ON' : 'OFF'})` });\n    return [[], gxRelayMsg, null, null, null, null, fanMsg];\n}\n\n// 3. CALCULATE BASE 'AUTO' TARGETS FOR ALL 4 CHANNELS\nlet autoTargets = [false, false, false, false];\nlet modeLabel = \"\";\n\nif (genRunning) {\n    let effectiveStart = onlineSince > 0 ? onlineSince : now;\n    let upTimeSec = (now - effectiveStart) / 1000;\n    modeLabel = `GEN (Up:${upTimeSec.toFixed(0)}s)`;\n\n    if (!tankCut) {\n        if (upTimeSec >= SETTINGS.GEN_DELAY_ELEMENT_1_SEC) autoTargets[0] = true;\n        if (upTimeSec >= SETTINGS.GEN_DELAY_ELEMENT_2_SEC) autoTargets[1] = true;\n        if (upTimeSec >= SETTINGS.GEN_DELAY_ELEMENT_3_SEC && !pcbCutEl3) autoTargets[2] = true;\n    }\n    if (upTimeSec >= SETTINGS.GEN_DELAY_SOCKET_4_SEC) autoTargets[3] = true;\n} else {\n    // ------------------------------------------------------------------------\n    // SUMMER SOLAR EXCESS SEQUENTIAL STAGING WITH HYSTERESIS & QUATTRO ALARMS\n    // ------------------------------------------------------------------------\n    let stage = context.get('solarStage') || 0;\n    let stepUpTimerStart = context.get('stepUpTimerStart') || 0;\n    let stepDownTimerStart = context.get('stepDownTimerStart') || 0;\n    let lastDeficitStepDown = context.get('lastDeficitStepDown') || 0;\n    let retryCooldownActive = (lastDeficitStepDown > 0) && ((now - lastDeficitStepDown) < (SETTINGS.SOLAR_RETRY_AFTER_DEFICIT_SEC * 1000));\n\n    if (quattroTempCut) {\n        stage = 0;\n        stepUpTimerStart = 0;\n        stepDownTimerStart = 0;\n        let remSec = Math.max(0, SETTINGS.QUATTRO_ALARM_COOLDOWN_SEC - ((now - lastQuattroAlarmTime) / 1000)).toFixed(0);\n        modeLabel = `QUATTRO OVERTEMP ALARM (Cool:${remSec}s)`;\n    } else if (chestCut) {\n        stage = 0;\n        stepUpTimerStart = 0;\n        stepDownTimerStart = 0;\n        modeLabel = `CHEST HOT (${chestTemp}°C)`;\n    } else if (soc < SETTINGS.SOLAR_MIN_SOC_CUTOFF) {\n        stage = 0;\n        stepUpTimerStart = 0;\n        stepDownTimerStart = 0;\n        modeLabel = `LOW SOC (${soc}%)`;\n    } else {\n        let maxAllowedStage = 0;\n        if (battMode === 'Float' && soc >= SETTINGS.SOLAR_FULL_STAGE_SOC_ON) {\n            maxAllowedStage = 4;\n        } else if (soc >= SETTINGS.SOLAR_PRE_FLOAT_SOC_ON) {\n            maxAllowedStage = SETTINGS.SOLAR_PRE_FLOAT_MAX_STAGES;\n        }\n\n        // A. INSTANT STEP-DOWN: Quattro Overload Warning/Alarm OR Quattro Watts > 6500W\n        if ((quattroOverload > 0 || quattroPower > SETTINGS.QUATTRO_OVERLOAD_STEP_DOWN) && stage > 0) {\n            stage--;\n            stepUpTimerStart = 0;\n            stepDownTimerStart = 0;\n            context.set('lastDeficitStepDown', now);\n            node.warn(`[SOLAR] Instant step-down to Stage ${stage} (Quattro Load: ${quattroPower}W, Overload Alarm: ${quattroOverload})`);\n        }\n        // B. TIMED STEP-DOWN: Solar generation dropped below base + active loads (Battery draining < -300W)\n        else if (battPower < SETTINGS.SOLAR_STEP_DOWN_DEFICIT_WATTS && stage > 0) {\n            stepUpTimerStart = 0;\n            if (stepDownTimerStart === 0) {\n                stepDownTimerStart = now;\n            } else if ((now - stepDownTimerStart) >= (SETTINGS.SOLAR_STEP_DOWN_DELAY_SEC * 1000)) {\n                stage--;\n                stepDownTimerStart = 0;\n                context.set('lastDeficitStepDown', now);\n                node.warn(`[SOLAR] Solar deficit (Batt: ${battPower}W). Stepped down to Stage ${stage} (5m retry cooldown)`);\n            }\n        }\n        // C. TIMED STEP-UP: Sufficient solar surplus & no recent Quattro alarm cooldown\n        else if (\n            !quattroAlarmCooldownActive &&\n            stage < maxAllowedStage &&\n            quattroPower < SETTINGS.QUATTRO_MAX_WATTS_STEP_UP &&\n            (battPower >= SETTINGS.SOLAR_STEP_UP_SURPLUS_WATTS || (battMode === 'Float' && battPower > -100 && !retryCooldownActive))\n        ) {\n            stepDownTimerStart = 0;\n            if (stepUpTimerStart === 0) {\n                stepUpTimerStart = now;\n            } else if ((now - stepUpTimerStart) >= (SETTINGS.SOLAR_STEP_UP_DELAY_SEC * 1000)) {\n                stage++;\n                stepUpTimerStart = 0;\n            }\n        } else {\n            stepUpTimerStart = 0;\n            stepDownTimerStart = 0;\n        }\n\n        if (stage > maxAllowedStage) stage = maxAllowedStage;\n\n        let tStr = \"\";\n        if (stepUpTimerStart > 0) {\n            let rem = Math.max(0, SETTINGS.SOLAR_STEP_UP_DELAY_SEC - ((now - stepUpTimerStart) / 1000)).toFixed(0);\n            tStr = ` +1 in ${rem}s`;\n        } else if (stepDownTimerStart > 0) {\n            let rem = Math.max(0, SETTINGS.SOLAR_STEP_DOWN_DELAY_SEC - ((now - stepDownTimerStart) / 1000)).toFixed(0);\n            tStr = ` -1 in ${rem}s`;\n        } else if (retryCooldownActive && battMode === 'Float' && stage < maxAllowedStage) {\n            let rem = Math.max(0, SETTINGS.SOLAR_RETRY_AFTER_DEFICIT_SEC - ((now - lastDeficitStepDown) / 1000)).toFixed(0);\n            tStr = ` Wait:${rem}s`;\n        }\n        modeLabel = `SOLAR (${stage}/${maxAllowedStage} | Batt:${battPower >= 0 ? '+' : ''}${battPower}W${tStr})`;\n    }\n\n    context.set('solarStage', stage);\n    context.set('stepUpTimerStart', stepUpTimerStart);\n    context.set('stepDownTimerStart', stepDownTimerStart);\n\n    autoTargets[0] = (stage >= 1) && !tankCut;\n    autoTargets[1] = (stage >= 2) && !tankCut;\n    autoTargets[2] = (stage >= 3) && !tankCut && !pcbCutEl3;\n    autoTargets[3] = (stage >= 4);\n}\n\n// 4. COMBINE PER-CHANNEL VRM SWITCH MODES + HARD SAFETY LIMITS\nlet targets = [false, false, false, false];\n\nif (override === 2) {\n    modeLabel = \"MASTER FORCE OFF\";\n    targets = [false, false, false, false];\n} else if (override === 1) {\n    modeLabel = \"MASTER FORCE ON\";\n    targets = [!tankCut, !tankCut, (!tankCut && !pcbCutEl3), true];\n} else {\n    for (let i = 0; i < 4; i++) {\n        let rawDesired = chAuto[i] ? autoTargets[i] : chManualState[i];\n        if (i < 3 && tankCut) rawDesired = false;\n        if (i === 2 && pcbCutEl3) rawDesired = false;\n        if (chestCut || quattroTempCut) rawDesired = false;\n        targets[i] = rawDesired;\n    }\n}\n\n// 5. UPDATE NODE STATUS BADGE WITH CLEAR TEXT LABELS\nlet names = [\"Immersion1\", \"Immersion2\", \"Immersion3\", \"Socket\"];\nlet chDesc = targets.map((t, idx) => {\n    let mode = chAuto[idx] ? \"Auto\" : \"Man\";\n    let state = t ? \"ON\" : \"OFF\";\n    return `${names[idx]}:${mode}-${state}`;\n}).join(' | ');\n\nlet flags = [];\nif (dryRun) flags.push(\"DRY-RUN\");\nif (acout2Override === 2) flags.push(\"AC_OUT2_FORCED_OFF\");\nif (tankCut) flags.push(\"TANK>=90C\");\nif (pcbCutEl3) flags.push(\"PCB_HOT\");\nif (chestCut) flags.push(\"CHEST_HOT\");\nif (quattroTempAlarm > 0) flags.push(`Q_TEMP_ALM(${quattroTempAlarm})`);\nif (quattroOverload > 0) flags.push(`Q_OVLD_ALM(${quattroOverload})`);\nif (fanState) flags.push(\"FAN:ON\");\nlet flagStr = flags.length > 0 ? ` [${flags.join(',')}]` : \"\";\n\nnode.status({\n    fill: dryRun ? \"yellow\" : (flags.some(f => f !== \"FAN:ON\") ? \"red\" : (targets.some(Boolean) ? \"green\" : \"grey\")),\n    shape: dryRun ? \"ring\" : \"dot\",\n    text: `${modeLabel} — ${chDesc}${flagStr}`\n});\n\n// 6. SEND RPC COMMANDS TO SHELLY PRO 4PM & FEEDBACK TO VRM VIRTUAL SWITCHES\nlet currentActual = flow.get('shelly_states') || [null, null, null, null];\nlet outMsgs = [];\n\nfor (let i = 0; i < 4; i++) {\n    if (currentActual[i] !== targets[i]) {\n        let cmdUrl = `http://${SETTINGS.SHELLY_IP}/rpc/Switch.Set?id=${i}&on=${targets[i]}`;\n        if (dryRun) {\n            node.warn(`[DRY RUN] Would switch Channel ${i} to ${targets[i] ? 'ON' : 'OFF'}: ${cmdUrl}`);\n        } else {\n            outMsgs.push({ url: cmdUrl, channel: i, targetState: targets[i] });\n        }\n    }\n}\n\n// Update VRM Virtual Switch ON/OFF indicator (and force Auto=1 on initial deploy/boot)\nlet initDone = context.get('vswInitDone') || false;\nlet vswFeedback = [null, null, null, null];\n\nfor (let i = 0; i < 4; i++) {\n    if (!initDone) {\n        flow.set(`ch${i}_auto`, true);\n        vswFeedback[i] = {\n            payload: {\n                \"/SwitchableOutput/output_1/Auto\": 1,\n                \"/SwitchableOutput/output_1/State\": targets[i] ? 1 : 0\n            }\n        };\n    } else if (chAuto[i]) {\n        vswFeedback[i] = {\n            payload: {\n                \"/SwitchableOutput/output_1/State\": targets[i] ? 1 : 0\n            }\n        };\n    }\n}\ncontext.set('vswInitDone', true);\n\n// Outputs:\n// 1: Shelly HTTP RPC commands\n// 2: GX Relay 2 (AC Out 2)\n// 3..6: VRM Virtual Switch 1..4 State Feedback\n// 7: External Quattro Cooling Fan Trigger (1 = ON, 0 = OFF)\nreturn [outMsgs, gxRelayMsg, vswFeedback[0], vswFeedback[1], vswFeedback[2], vswFeedback[3], fanMsg];",
        "outputs": 7,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 340,
        "y": 760,
        "wires": [
            [
                "b65ef16a586a62a0",
                "5e13d769250b6443"
            ],
            [
                "c30f9545587a086f"
            ],
            [
                "128d7f7b59880313"
            ],
            [
                "4fc084737390cb06"
            ],
            [
                "eb5b631c002ae882"
            ],
            [
                "bc4df54646cd2960"
            ],
            [
                "d7410df47b4f1acf"
            ]
        ]
    },
    {
        "id": "b65ef16a586a62a0",
        "type": "http request",
        "z": "491e2f6b782fe415",
        "name": "Send Switch Command to 4PM",
        "method": "GET",
        "ret": "obj",
        "paytoqs": "ignore",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 850,
        "y": 720,
        "wires": [
            []
        ]
    },
    {
        "id": "c30f9545587a086f",
        "type": "victron-output-relay",
        "z": "491e2f6b782fe415",
        "outputs": 0,
        "service": "com.victronenergy.system/0",
        "path": "/Relay/1/State",
        "serviceObj": {
            "service": "com.victronenergy.system/0",
            "name": "Venus device"
        },
        "pathObj": {
            "path": "/Relay/1/State",
            "type": "enum",
            "name": "Venus relay 2 state",
            "enum": {
                "0": "Open",
                "1": "Closed"
            },
            "writable": true
        },
        "initial": "",
        "name": "GX Relay 2 (AC Out 2 Power)",
        "onlyChanges": true,
        "x": 840,
        "y": 800,
        "wires": []
    },
    {
        "id": "5e13d769250b6443",
        "type": "debug",
        "z": "491e2f6b782fe415",
        "name": "Switching Debug Log",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 820,
        "y": 760,
        "wires": []
    },
    {
        "id": "47beda0704afc645",
        "type": "victron-input-battery",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.battery/275",
        "path": "/Dc/0/Power",
        "serviceObj": {
            "service": "com.victronenergy.battery/275",
            "name": "B SmartShunt"
        },
        "pathObj": {
            "path": "/Dc/0/Power",
            "type": "float",
            "name": "Power (W)"
        },
        "initial": "",
        "name": "SmartShunt Power (W)",
        "onlyChanges": false,
        "roundValues": "0",
        "x": 140,
        "y": 270,
        "wires": [
            [
                "d4b3cb3cf444a02e"
            ]
        ]
    },
    {
        "id": "d4b3cb3cf444a02e",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Battery Power",
        "func": "let p = Number(msg.payload);\nflow.set('battery_power', p);\nnode.status({\n    fill: p >= 0 ? 'green' : 'yellow',\n    shape: 'dot',\n    text: `${p >= 0 ? '+' : ''}${p} W (${p >= 0 ? 'Charging' : 'Draining'})`\n});\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 270,
        "wires": []
    },
    {
        "id": "29b0b4bc8c77464b",
        "type": "victron-input-vebus",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.vebus/274",
        "path": "/Alarms/HighTemperature",
        "serviceObj": {
            "service": "com.victronenergy.vebus/274",
            "name": "Quattro 24/8000/200-2x100"
        },
        "pathObj": {
            "path": "/Alarms/HighTemperature",
            "type": "enum",
            "name": "High Temperature alarm",
            "enum": {
                "0": "Ok",
                "1": "Warning",
                "2": "Alarm"
            }
        },
        "name": "Quattro High Temp Alarm",
        "onlyChanges": false,
        "x": 690,
        "y": 40,
        "wires": [
            [
                "5f3ca93a0b55daf1"
            ]
        ]
    },
    {
        "id": "5f3ca93a0b55daf1",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Quattro Temp Alarm",
        "func": "// 0 = Ok, 1 = Warning (Pre-alarm), 2 = Alarm\nlet val = Number(msg.payload) || 0;\nflow.set('quattro_temp_alarm', val);\nlet labels = ['OK (0)', 'WARNING (1)', 'ALARM (2)'];\nnode.status({\n    fill: val === 0 ? 'green' : (val === 1 ? 'yellow' : 'red'),\n    shape: 'dot',\n    text: `Temp: ${labels[val] || val}`\n});\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "flow.set('quattro_temp_alarm', 0);",
        "finalize": "",
        "libs": [],
        "x": 950,
        "y": 40,
        "wires": []
    },
    {
        "id": "ee79846b5a79a975",
        "type": "victron-input-vebus",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.vebus/274",
        "path": "/Alarms/Overload",
        "serviceObj": {
            "service": "com.victronenergy.vebus/274",
            "name": "Quattro 24/8000/200-2x100"
        },
        "pathObj": {
            "path": "/Alarms/Overload",
            "type": "enum",
            "name": "Overload alarm",
            "enum": {
                "0": "Ok",
                "1": "Warning",
                "2": "Alarm"
            }
        },
        "name": "Quattro Overload Alarm",
        "onlyChanges": false,
        "x": 680,
        "y": 100,
        "wires": [
            [
                "76c424c14debf9fd"
            ]
        ]
    },
    {
        "id": "76c424c14debf9fd",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Store Quattro Overload Alarm",
        "func": "// 0 = Ok, 1 = Warning (Pre-alarm), 2 = Alarm\nlet val = Number(msg.payload) || 0;\nflow.set('quattro_overload_alarm', val);\nlet labels = ['OK (0)', 'WARNING (1)', 'ALARM (2)'];\nnode.status({\n    fill: val === 0 ? 'green' : (val === 1 ? 'yellow' : 'red'),\n    shape: 'dot',\n    text: `Overload: ${labels[val] || val}`\n});\nreturn null;",
        "outputs": 0,
        "timeout": "",
        "noerr": 0,
        "initialize": "flow.set('quattro_overload_alarm', 0);",
        "finalize": "",
        "libs": [],
        "x": 970,
        "y": 100,
        "wires": []
    },
    {
        "id": "d7410df47b4f1acf",
        "type": "debug",
        "z": "491e2f6b782fe415",
        "name": "External Cooling Fan Trigger (1=ON, 0=OFF)",
        "active": false,
        "tosidebar": true,
        "console": false,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 430,
        "y": 900,
        "wires": []
    },
    {
        "id": "8b90bbc4fed8253e",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Set Pill IP URL",
        "func": "let ip = flow.get('shelly_pill_ip') || \"192.168.18.150\";\nmsg.url = `http://${ip}/rpc/Shelly.GetComponents?dynamic_only=true&include=[\"status\"]`;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 500,
        "wires": [
            [
                "4d6c088c72ebd823"
            ]
        ]
    },
    {
        "id": "8396166ad3b4925a",
        "type": "function",
        "z": "491e2f6b782fe415",
        "name": "Set 4PM IP URL",
        "func": "let ip = flow.get('shelly_4pm_ip') || \"192.168.18.151\";\nmsg.url = `http://${ip}/rpc/Shelly.GetStatus`;\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 440,
        "y": 560,
        "wires": [
            [
                "51f8d9365bc05dd5"
            ]
        ]
    },
    {
        "id": "7cfdc10a9d064295",
        "type": "victron-input-relay",
        "z": "491e2f6b782fe415",
        "outputs": 1,
        "service": "com.victronenergy.system/0",
        "path": "/Relay/1/State",
        "serviceObj": {
            "service": "com.victronenergy.system/0",
            "name": "Venus device"
        },
        "pathObj": {
            "path": "/Relay/1/State",
            "type": "enum",
            "name": "Venus relay 2 state",
            "enum": {
                "0": "Open",
                "1": "Closed"
            }
        },
        "initial": "",
        "name": "Read GX Relay 2 (VRM AC OUT 2 Switch)",
        "onlyChanges": true,
        "x": 740,
        "y": 260,
        "wires": [
            [
                "f8ee19cddf6e407c"
            ]
        ]
    },
    {
        "id": "67524e565ede194a",
        "type": "global-config",
        "env": [],
        "modules": {
            "@victronenergy/node-red-contrib-victron": "1.7.27"
        }
    }
]