Is there a node that functions like a normally open relay

I was hoping to find a node with two inputs and one output. If the first input is high the msg passes from second input to output. If the first input is low then it blocks msg from second input to output.

1 Like

If I understand correctly, you may be able to use node-red-contrib-simple-gate

Nodes generally have one input and one or more outputs They only know about the message which they are currently processing..

One way around this is to use a join node to join two or more sequential messages into a single one. For example

[{"id":"65d202a6755fb010","type":"inject","z":"ee4bd702d40b1e30","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pass","payload":"true","payloadType":"bool","x":100,"y":140,"wires":[["79b367d50beca4b9"]]},{"id":"ac870f90bd912403","type":"inject","z":"ee4bd702d40b1e30","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"data","payload":"Something","payloadType":"str","x":120,"y":180,"wires":[["79b367d50beca4b9"]]},{"id":"79b367d50beca4b9","type":"join","z":"ee4bd702d40b1e30","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":200,"wires":[["95f23ff7b1bcc2b3","22d4695a0366fdc2"]]},{"id":"c32d17da62bfa27e","type":"inject","z":"ee4bd702d40b1e30","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"data","payload":"Something else","payloadType":"str","x":130,"y":220,"wires":[["79b367d50beca4b9"]]},{"id":"be9d927343040cb9","type":"inject","z":"ee4bd702d40b1e30","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"pass","payload":"false","payloadType":"bool","x":100,"y":260,"wires":[["79b367d50beca4b9"]]},{"id":"3e7ee306f7a09524","type":"debug","z":"ee4bd702d40b1e30","name":"output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload.data","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":200,"wires":[]},{"id":"95f23ff7b1bcc2b3","type":"switch","z":"ee4bd702d40b1e30","name":"payload.pass == true?","property":"payload.pass","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":200,"wires":[["3e7ee306f7a09524"]]},{"id":"22d4695a0366fdc2","type":"debug","z":"ee4bd702d40b1e30","name":"compound message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":540,"y":160,"wires":[]}]

The data "Something" or "Something else" will only arrive at the debug output after a message with topic "pass" and payload "true".

There are third party contributed gate nodes which have this ability depending on messages with topic "control". Search for "gate" on flows.nodered.org.

And there are a few nodes which do retain knowledge of the previous message. An example is the filter node which can pass messages only if they are greater than 10% different from the previous one.

This might just work thanks

this is how I had to do it....

    {
        "id": "aeda15defdb019f1",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "1",
        "type": "inject",
        "z": "aeda15defdb019f1",
        "name": "Set Relay True",
        "props": [
            {
                "p": "payload",
                "v": "true",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 200,
        "y": 120,
        "wires": [
            [
                "2"
            ]
        ]
    },
    {
        "id": "2",
        "type": "change",
        "z": "aeda15defdb019f1",
        "name": "Set Relay State",
        "rules": [
            {
                "t": "set",
                "p": "relayState",
                "pt": "flow",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 400,
        "y": 120,
        "wires": [
            [
                "5"
            ]
        ]
    },
    {
        "id": "3",
        "type": "inject",
        "z": "aeda15defdb019f1",
        "name": "Set Relay False",
        "props": [
            {
                "p": "payload",
                "v": "false",
                "vt": "bool"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "x": 200,
        "y": 180,
        "wires": [
            [
                "2"
            ]
        ]
    },
    {
        "id": "4",
        "type": "inject",
        "z": "aeda15defdb019f1",
        "name": "Input Signal",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "Some Data",
        "payloadType": "str",
        "x": 200,
        "y": 260,
        "wires": [
            [
                "5"
            ]
        ]
    },
    {
        "id": "5",
        "type": "function",
        "z": "aeda15defdb019f1",
        "name": "Relay Function",
        "func": "// Get the current relay state\nconst relayState = flow.get('relayState') || false;\n\n// If relayState is true, pass the message, otherwise block it\nif (relayState) {\n    return msg; // Pass the message\n} else {\n    return null; // Block the message\n}",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 400,
        "y": 260,
        "wires": [
            [
                "6"
            ]
        ]
    },
    {
        "id": "6",
        "type": "debug",
        "z": "aeda15defdb019f1",
        "name": "Relay Output",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 600,
        "y": 260,
        "wires": []
    }
]

Thanks for your help, it got me going in the right direction.

to general solve simple cases when I need to gate inputs to subflow I made this utilite

it has default 7 channels to pass based on input_id ,

example
[
    {
        "id": "96df5c840c0e1dd6",
        "type": "subflow",
        "name": "input portal in",
        "info": "",
        "category": "Utils",
        "in": [
            {
                "x": 80,
                "y": 120,
                "wires": [
                    {
                        "id": "9d7a229f3a60fc38"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 430,
                "y": 120,
                "wires": [
                    {
                        "id": "9d7a229f3a60fc38",
                        "port": 0
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#C0DEED",
        "inputLabels": [
            "msg to pass"
        ],
        "outputLabels": [
            "to supported input"
        ],
        "icon": "node-red-dashboard/ui_numeric.png"
    },
    {
        "id": "9d7a229f3a60fc38",
        "type": "function",
        "z": "96df5c840c0e1dd6",
        "name": "input portal in",
        "func": "const input_portal_input = Number(env.get('NR_SUBFLOW_NAME')) - 1\nif (isNaN(input_portal_input)) {\n    throw new Error('input_portal_input is not defined or bad value')\n}\nmsg._input_portal_input = input_portal_input\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 220,
        "y": 120,
        "wires": [
            []
        ]
    },
    {
        "id": "3db6878f8864dcd2",
        "type": "subflow",
        "name": "input portal out",
        "info": "",
        "category": "Utils",
        "in": [
            {
                "x": 80,
                "y": 260,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 480,
                "y": 100,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 0
                    }
                ]
            },
            {
                "x": 480,
                "y": 160,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 1
                    }
                ]
            },
            {
                "x": 480,
                "y": 220,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 2
                    }
                ]
            },
            {
                "x": 480,
                "y": 280,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 3
                    }
                ]
            },
            {
                "x": 480,
                "y": 340,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 4
                    }
                ]
            },
            {
                "x": 480,
                "y": 400,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 5
                    }
                ]
            },
            {
                "x": 480,
                "y": 460,
                "wires": [
                    {
                        "id": "ed948d6633b44f1c",
                        "port": 6
                    }
                ]
            }
        ],
        "env": [],
        "meta": {},
        "color": "#A6BBCF",
        "inputLabels": [
            "single use msg._input_portal_input - output number"
        ],
        "outputLabels": [
            "1",
            "2",
            "3",
            "4",
            "5",
            "6",
            "7"
        ],
        "icon": "node-red/switch.svg"
    },
    {
        "id": "ed948d6633b44f1c",
        "type": "function",
        "z": "3db6878f8864dcd2",
        "name": "input portal out",
        "func": "const input_id = msg._input_portal_input;\ndelete msg._input_portal_input;\n\nif (isNaN(input_id) || input_id < 0) {\n    throw new Error(\"No input portal found or invalid input portal ID\");\n}\nconst msgs = [];\nmsgs[input_id] = msg;\n// node.warn({msgs});\nreturn msgs;",
        "outputs": 7,
        "timeout": 0,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 240,
        "y": 260,
        "wires": [
            [],
            [],
            [],
            [],
            [],
            [],
            []
        ]
    },
    {
        "id": "c63183a8f66f617d",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "1",
        "x": 210,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "bd7afabce1f15041",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "2",
        "x": 210,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "0c715ce30844f56c",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "3",
        "x": 210,
        "y": 600,
        "wires": [
            []
        ]
    },
    {
        "id": "989aff795d7fca22",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "4",
        "x": 210,
        "y": 640,
        "wires": [
            []
        ]
    },
    {
        "id": "2b1b4b102fd1c5df",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "5",
        "x": 330,
        "y": 520,
        "wires": [
            []
        ]
    },
    {
        "id": "4de0c44b083680cb",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "6",
        "x": 330,
        "y": 560,
        "wires": [
            []
        ]
    },
    {
        "id": "ef822267811b7754",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3db6878f8864dcd2",
        "d": true,
        "name": "7",
        "x": 330,
        "y": 600,
        "wires": [
            []
        ]
    },
    {
        "id": "24d1c1de7dda3d12",
        "type": "subflow:3db6878f8864dcd2",
        "z": "3832fb7f90f29c70",
        "name": "",
        "x": 644.9999885559082,
        "y": 5086.000148773193,
        "wires": [
            [
                "81d77c98ded47f7d"
            ],
            [
                "7ed0cbe8f5a4df0d"
            ],
            [],
            [],
            [],
            [],
            [
                "807a80c955a0a837"
            ]
        ]
    },
    {
        "id": "9689332363c3f9e6",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3832fb7f90f29c70",
        "name": "1",
        "x": 414.9999885559082,
        "y": 5066.000148773193,
        "wires": [
            [
                "24d1c1de7dda3d12"
            ]
        ]
    },
    {
        "id": "0460990e18abcd16",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3832fb7f90f29c70",
        "name": "2",
        "x": 414.9999885559082,
        "y": 5106.000148773193,
        "wires": [
            [
                "24d1c1de7dda3d12"
            ]
        ]
    },
    {
        "id": "81d77c98ded47f7d",
        "type": "debug",
        "z": "3832fb7f90f29c70",
        "name": "debug 139",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 914.9999885559082,
        "y": 5066.000148773193,
        "wires": []
    },
    {
        "id": "7ed0cbe8f5a4df0d",
        "type": "debug",
        "z": "3832fb7f90f29c70",
        "name": "debug 140",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 914.9999885559082,
        "y": 5126.000148773193,
        "wires": []
    },
    {
        "id": "807a80c955a0a837",
        "type": "debug",
        "z": "3832fb7f90f29c70",
        "name": "debug 141",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 914.9999885559082,
        "y": 5186.000148773193,
        "wires": []
    },
    {
        "id": "09a789711e78680a",
        "type": "subflow:96df5c840c0e1dd6",
        "z": "3832fb7f90f29c70",
        "name": "7",
        "x": 414.9999885559082,
        "y": 5146.000148773193,
        "wires": [
            [
                "24d1c1de7dda3d12"
            ]
        ]
    },
    {
        "id": "f34211e5fabc186d",
        "type": "inject",
        "z": "3832fb7f90f29c70",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 284.9999885559082,
        "y": 5026.000148773193,
        "wires": [
            [
                "9689332363c3f9e6"
            ]
        ]
    },
    {
        "id": "48b3d5f139c1a59e",
        "type": "inject",
        "z": "3832fb7f90f29c70",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 264.9999885559082,
        "y": 5106.000148773193,
        "wires": [
            [
                "0460990e18abcd16"
            ]
        ]
    },
    {
        "id": "dbf6eedc7697a34b",
        "type": "inject",
        "z": "3832fb7f90f29c70",
        "name": "",
        "props": [
            {
                "p": "payload"
            },
            {
                "p": "topic",
                "vt": "str"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 284.9999885559082,
        "y": 5166.000148773193,
        "wires": [
            [
                "09a789711e78680a"
            ]
        ]
    }
]

Nice, although that's not what I needed I will keep it in my back pocket for another project coming up.

You might want to look at Node Red Contrib ultimate boolean - great set of nodes with a YT explainer and good online help

Craig

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