You can wire in any number of inputs to any node -- just be aware that your node will only see one input msg at a time. There is no inherent msg aggregation simply because there are multiple input wires.
Instead, the task of aggregating multiple input msgs is handled by certain nodes -- some of which are built in to the core node-red server, and some that have been contributed by the community. Which one you should choose will depend upon the specific use case. For instance, should two objects be appended into an array, or merged into one big object? Only you will know what you want -- node-red does not make any assumptions, but gives you different nodes to handle many common use cases. For any other use cases, there is always the generic function
node, in which you can use javascript to implement whatever behavior you need.
For your original question, you are looking for a way to merge 2 payloads from different sensors into a single object. The core join
and change
nodes can be used for that, as can the node-red-contrib-bool-gate
and node-red-contrib-aggregator
nodes, found on the flow library site.
Here's an example of combining two sensor inputs using the join
node, and then using a switch
node with the expression payload.temp > 70 and payload.smoke
to determine whether to send the msg down the flow:
[
{
"id": "87df68f8.51ad58",
"type": "inject",
"z": "f9a2eec9.c2e26",
"name": "",
"topic": "smoke",
"payload": "true",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 160,
"y": 1180,
"wires": [
[
"da4182a8.47939"
]
]
},
{
"id": "3ad419ec.1453a6",
"type": "inject",
"z": "f9a2eec9.c2e26",
"name": "",
"topic": "smoke",
"payload": "false",
"payloadType": "bool",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 170,
"y": 1140,
"wires": [
[
"da4182a8.47939"
]
]
},
{
"id": "a45b3cb0.f3312",
"type": "inject",
"z": "f9a2eec9.c2e26",
"name": "",
"topic": "temp",
"payload": "65",
"payloadType": "num",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 160,
"y": 1220,
"wires": [
[
"da4182a8.47939"
]
]
},
{
"id": "a3b07d81.e6b17",
"type": "inject",
"z": "f9a2eec9.c2e26",
"name": "",
"topic": "temp",
"payload": "75",
"payloadType": "num",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"x": 160,
"y": 1260,
"wires": [
[
"da4182a8.47939"
]
]
},
{
"id": "da4182a8.47939",
"type": "join",
"z": "f9a2eec9.c2e26",
"name": "join payloads",
"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": 430,
"y": 1200,
"wires": [
[
"315c9ce3.570d64",
"50f981b4.be654"
]
]
},
{
"id": "315c9ce3.570d64",
"type": "switch",
"z": "f9a2eec9.c2e26",
"name": "Trigger Alarm?",
"property": "payload.temp > 70 and payload.smoke",
"propertyType": "jsonata",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 640,
"y": 1200,
"wires": [
[
"50f981b4.be654"
]
]
},
{
"id": "50f981b4.be654",
"type": "debug",
"z": "f9a2eec9.c2e26",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"x": 690,
"y": 1260,
"wires": [
]
}
]