node-red-contrib-conditional-trigger
Version:
A Node-RED subflow for triggering conditional events based on multiple input messages. The subflow evaluates if two incoming messages meet specific conditions (e.g., both msg.payload values are true) and routes the result to different outputs. Ideal for s
118 lines (117 loc) • 3.66 kB
JSON
[{
"id": "cda03df45f84c721",
"type": "subflow",
"name": "conditional-trigger",
"info": "check 2 inputs using msg.topic.\r\nInput names must be input1 and input2.\r\n\r\nTesting the Flow\r\nClick Inject 1 true → Sends { topic: \"input1\", input: true }.\r\nClick Inject 2 true → Sends { topic: \"input2\", input: true }.\r\n\r\njoin example input to logica:\r\n{\r\n \"input1\": true,\r\n \"input2\": true\r\n}\r\n",
"category": "",
"in": [{
"x": 60,
"y": 80,
"wires": [{
"id": "cfd9da19a62035bf"
}
]
}
],
"out": [{
"x": 780,
"y": 80,
"wires": [{
"id": "cd9df17ada06dc16",
"port": 0
}
]
}, {
"x": 780,
"y": 80,
"wires": [{
"id": "cd9df17ada06dc16",
"port": 1
}
]
}
],
"env": [],
"meta": {},
"color": "#DDAA99",
"status": {
"x": 580,
"y": 140,
"wires": [{
"id": "ae8c90e922404bde",
"port": 0
}
]
}
}, {
"id": "cfd9da19a62035bf",
"type": "join",
"z": "cda03df45f84c721",
"name": "join msg.topic",
"mode": "custom",
"build": "object",
"property": "input",
"propertyType": "msg",
"key": "topic",
"joiner": "\\n",
"joinerType": "str",
"useparts": false,
"accumulate": false,
"timeout": "",
"count": "2",
"reduceRight": false,
"reduceExp": "",
"reduceInit": "",
"reduceInitType": "",
"reduceFixup": "",
"x": 220,
"y": 80,
"wires": [["ae8c90e922404bde"]]
}, {
"id": "ae8c90e922404bde",
"type": "function",
"z": "cda03df45f84c721",
"name": "check join",
"func": "// Check if both inputs are true\nif (msg.input.input1 === true && msg.input.input2 === true) {\n return { topic: \"both_true\", payload: \"fire_event_1\" }; // Both are true\n} else {\n return { topic: \"not_both_true\", payload: \"fire_event_2\" }; // At least one is not true\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 420,
"y": 80,
"wires": [["cd9df17ada06dc16"]]
}, {
"id": "cd9df17ada06dc16",
"type": "switch",
"z": "cda03df45f84c721",
"name": "true or false ",
"property": "topic",
"propertyType": "msg",
"rules": [{
"t": "eq",
"v": "both_true",
"vt": "str"
}, {
"t": "eq",
"v": "not_both_true",
"vt": "str"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 630,
"y": 80,
"wires": [[], []]
}, {
"id": "db5f412b7840a964",
"type": "subflow:cda03df45f84c721",
"z": "dca456b64924d38b",
"name": "",
"x": 610,
"y": 2280,
"wires": [["3ff17df553f58407"], ["a72101a6bb03a51a"]]
}
]