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
}
]