Help with multiple inputs to a function node!

is there another way of getting more than one input on a function node except via the join node?
That would solve some issues if one could do JS on more than one input and output.

Yes, as I said, you can do it in a function node by saving values to the node context. remember though that there are processing overheads in using function nodes so it is not only easier and less bug prone to use a join node than a function node, even if extra nodes are needed to get the data in the right place. More importantly it is surprisingly easy to introduce bugs once you start saving data. You have to cope with startup with undefined data for example.

Here is a skeleton function node that I used before the Join node had the key/value pairs feature. To use it you can just change the requiredInputs section to define the topics expected then do what you want in the if (allOK) block

// these are the topics from the different messages coming in
// this expects to receive messages with topics temperature, humidity, air_speed and mrt
var requiredInputs = {
    "temperature": "temperature",
    "humidity": "humidity",
    "air_speed": "air_speed",
    "mrt": "mrt"    // Mean Radiant Temperature
};
for (var topic in requiredInputs) {
    if (msg.topic == topic) {
        // yes it is so save it and update the schedule
        context.set(requiredInputs[topic], msg.payload);
        break;
    }
}
// do we have a full set of inputs?
var allOK = true;
for (var topic in requiredInputs) {
    if (typeof context.get(requiredInputs[topic]) === 'undefined') {
        allOK = false;
        break;
    }
}

if (allOK) {
    // we have values for all the topics so go ahead and do whatever is necessary fetching the values using context.get("temperature") etc
    msg.payload = "some function of the saved data";
} else {
    msg = null;
}
return msg;
1 Like

The overheads are minimal for 99% of users and use cases... if it makes sense to do so - just use a function node, (especially if that is the topic of the thread),

well, thats why I'm asking, is there a different, easier way of doing what I'm trying to do...
This seems a lot of nodes for what I'm trying to accomplish.
Forwarding a button with a notification based on a state stored on a MQTT server.
12

IS there an easier way?
I will need that logic around 50 times in my project...

Possibly one of the Gate nodes would be simpler. There are a number of these on flows.nodered.org.