Lead/lag pump failover

happy holiday weekend everyone, running into some trouble getting a pump failover flow to work. ive tried numerouse configurations. this has gotten me the closest. what im trying to achieve is having the lead pump always ON and the lag pump to come on when lead fails or is commanded OFF. both pumps can not run at the same time.

[
    {
        "id": "lead-pump",
        "type": "rpi-gpio out",
        "z": "af0be22a6274a37c",
        "name": "Lead pump",
        "pin": "12",
        "set": false,
        "level": "1",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 100,
        "y": 200,
        "wires": ["failover"]
    },
    {
        "id": "lag-pump",
        "type": "rpi-gpio out",
        "z": "af0be22a6274a37c",
        "name": "Lag pump",
        "pin": "19",
        "set": false,
        "level": "1",
        "freq": "",
        "out": "out",
        "bcm": true,
        "x": 100,
        "y": 300,
        "wires": ["failover"]
    },
    {
        "id": "lead-switch",
        "type": "ui_switch",
        "z": "af0be22a6274a37c",
        "name": "Lead Pump Control",
        "group": "9c90a075584ede2b",
        "onvalue": "true",
        "onvalueType": "bool",
        "offvalue": "false",
        "offvalueType": "bool",
        "x": 100,
        "y": 100,
        "wires": ["failover"]
    },
    {
        "id": "failover",
        "type": "function",
        "z": "af0be22a6274a37c",
        "name": "Failover",
        "func": "if (msg.payload === true) {\n    // Lead pump control is ON\n    if (!flow.get('leadPumpRunning')) {\n        flow.set('leadPumpRunning', true);\n        flow.set('lagPumpRunning', false);\n        return { payload: true };\n    } else if (flow.get('lagPumpRunning')) {\n        // Turn off lag pump if it's running\n        flow.set('lagPumpRunning', false);\n        return { payload: true };\n    } else {\n        // Lead pump is already running\n        return null;\n    }\n} else if (msg.payload === false) {\n    // Lead pump control is OFF\n    if (flow.get('leadPumpRunning')) {\n        flow.set('leadPumpRunning', false);\n        return { payload: false };\n    } else if (!flow.get('lagPumpRunning')) {\n        // Turn on lag pump if it's not running\n        flow.set('lagPumpRunning', true);\n        return { payload: false };\n    } else {\n        // Lag pump is already running\n        return null;\n    }\n}\n",
        "outputs": 2,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 300,
        "y": 200,
        "wires": [["lead-pump"], ["lag-pump"]]
    },
    {
        "id": "9c90a075584ede2b",
        "type": "ui_group",
        "name": "Activity Room",
        "tab": "f394bc89e321d6f1",
        "order": 1,
        "disp": false,
        "width": 19,
        "collapse": false,
        "className": ""
    },
    {
        "id": "f394bc89e321d6f1",
        "type": "ui_tab",
        "name": "AutoMata @ Heritage  Activity Room",
        "icon": "dashboard",
        "disabled": false,
        "hidden": true
    }
]

[{"id":"failover","type":"function","z":"72f2cb9303562c8a","name":"Failover","func":"let msg1 = {}\nlet msg2 = {}\n\nif (msg.payload === true) {\n    // Lead pump control is ON\n        flow.set('leadPumpRunning', true);\n        flow.set('lagPumpRunning', false);\n        msg1.payload = 1\n        msg2.payload = 0\n        return [msg1, msg2]\n\n} else if (msg.payload === false) {\n    // Lead pump control is OFF\n        flow.set('lagPumpRunning', true);\n        flow.set('leadPumpRunning', false);\n        msg1.payload = 0\n        msg2.payload = 1\n        return [msg1, msg2]\n}\n","outputs":2,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":500,"wires":[["lead-pump"],["lag-pump"]]},{"id":"71d9f7c187c6d05a","type":"junction","z":"72f2cb9303562c8a","x":360,"y":500,"wires":[["failover"]]},{"id":"lead-pump","type":"rpi-gpio out","z":"72f2cb9303562c8a","name":"Lead pump","pin":"12","set":false,"level":"1","freq":"","out":"out","bcm":true,"x":670,"y":460,"wires":[]},{"id":"lag-pump","type":"rpi-gpio out","z":"72f2cb9303562c8a","name":"Lag pump","pin":"25","set":false,"level":"1","freq":"","out":"out","bcm":true,"x":670,"y":520,"wires":[]},{"id":"lead-switch","type":"ui_switch","z":"72f2cb9303562c8a","name":"Lead Pump Control","group":"9c90a075584ede2b","onvalue":"true","onvalueType":"bool","offvalue":"false","offvalueType":"bool","x":230,"y":460,"wires":[["71d9f7c187c6d05a"]]},{"id":"cf64b6ae55d10e66","type":"inject","z":"72f2cb9303562c8a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":210,"y":500,"wires":[["71d9f7c187c6d05a"]]},{"id":"37407d3315e4ffcc","type":"inject","z":"72f2cb9303562c8a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":210,"y":540,"wires":[["71d9f7c187c6d05a"]]},{"id":"9c90a075584ede2b","type":"ui_group","name":"Activity Room","tab":"f394bc89e321d6f1","order":1,"disp":false,"width":19,"collapse":false,"className":""},{"id":"f394bc89e321d6f1","type":"ui_tab","name":"AutoMata @ Heritage  Activity Room","icon":"dashboard","disabled":false,"hidden":true}]

Maybe this can be used?
Adjust gpio for your purpose.

1 Like

The 'logic' inside your code is very easy to understand - I like it.

Depending on how people like to 'style' their code, (in this particular situation) the 'return' statement could be moved to the end of the function node. Or can be left in its original place as that would deal with the situation where msg.payload is neither 'true' or 'false' (so leave the pumps settings unchanged).

let msg1 = {}
let msg2 = {}

if (msg.payload === true) {
    // Lead pump control is ON
        flow.set('leadPumpRunning', true);
        flow.set('lagPumpRunning', false);
        msg1.payload = 1
        msg2.payload = 0
        //return [msg1, msg2]

} else if (msg.payload === false) {
    // Lead pump control is OFF
        flow.set('lagPumpRunning', true);
        flow.set('leadPumpRunning', false);
        msg1.payload = 0
        msg2.payload = 1
        //return [msg1, msg2]
}
return [msg1, msg2]

2 Likes

How do you determine when the lead pump fails?

i am using a flow switch to determine pump failure/off and to command the other pump on. i have attached my entire flow so you make take a gander. This has been in operation for 3 weeks without issues. i recently tied in VFD SS command to the pumps from manual ui switch, which allows the vfds to operate in their Auto mode. I am working on this lead lag situation. i beleive i have it and have also incorporated a flow switch that seems to be functional in testing though have not integrated in the field as of yet. im getting closer and closer . Dashboard is looking decent. have yet to integrate into Influx and grafana but thats my next learning bit.
HvacV2.json (71.7 KB)

I am using a water flow switch instead of a current sensor. another issue i was having was resend the on command once gate was open {flow switch made}. i believe i managed to fix this with a gate monitor which resends the message. i have attached the entire flow. feel free to play with the dashboard and lmk thoughts as well. thanks in advance.
HvacV2.json (71.7 KB)

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.