# How to send multiple values in node-red

**URL:** <https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889>\
**Category:** General\
**Created:** [1 August 2019 06:44 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889 "2019-08-01T06:44:25Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 06:44 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/1 "2019-08-01T06:44:25Z")

</div>

Hi, I am a noob in this. I am working with [wireless Vibration and temperature](https://store.ncd.io/product/iot-long-range-wireless-vibration-and-temperature-sensor/) sensor. I want to send an email alert of vibration and temperature.

I have created a function node to send a single value.

 ![error1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9976f930058ee6d176a9daa19fda1be32b1d7c3e.jpeg)

it's working.

but I want to send multiple values in a single function node.  
 ![error2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c22fe76a509eaddb1c352c60f4898791d8c5b4a2.jpeg)

Any leads will be a great help.  
Thanx in advance

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 August 2019 06:47 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/2 "2019-08-01T06:47:13Z")

</div>

The docs describe how to send multiple messages from a function node: [https://nodered.org/docs/user-guide/writing-functions#multiple-messages](https://nodered.org/docs/user-guide/writing-functions#multiple-messages)

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 07:30 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/3 "2019-08-01T07:30:26Z")

</div>

I have created this but, it is sending only one value.  
 ![error3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/9/9711b3825137812c0ac40938f882b8e5f56d7fb2.jpeg)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [1 August 2019 07:33 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/4 "2019-08-01T07:33:21Z")

</div>

Try setting your debug to display all the message rather than just msg.payload

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 07:35 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/5 "2019-08-01T07:35:19Z")

</div>

Now this is the output  
 ![error4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d4a7c8361bb367f1d52d326ba04956fb071a5984.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 August 2019 07:41 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/6 "2019-08-01T07:41:42Z")

</div>

Go and look at the link on sending messages again. You have written it to send each message to a different output (but have only allowed one). You want to send all the messages to one output.

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 07:57 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/7 "2019-08-01T07:57:39Z")

</div>

I have connected debug node to this function node only  
 ![error5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/2d6c7f3893c04a064b755a404e1c4fcca4c67fdc.jpeg)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 August 2019 08:00 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/8 "2019-08-01T08:00:16Z")

</div>

Is that comment a reply to my point about the fact that have coded it to send one output to multiple outputs instead of multiple messages to one output? If so then I don't understand the relevance of it.

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 08:03 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/9 "2019-08-01T08:03:36Z")

</div>

I want to send multiple values in a single function.otherwise I have to create multiple function nodes to send multiple values.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [1 August 2019 08:05 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/10 "2019-08-01T08:05:36Z")

</div>

So you want to send multiple values in one message?  
i.e just as they arrived in your function node?

Or do you want to send different values in different messages along one wire to the next node

Or do you want to send different values in different messages to different nodes?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 August 2019 08:09 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/11 "2019-08-01T08:09:43Z")

</div>

Do you want to send multiple messages each containing one value, or one message containing multiple values? We have assumed here that you are trying to send multiple messages as that is what you seemed to be asking and what you coded into your function node. Your data coming in is already multiple values in one message so it is not at all clear what you are trying to do.

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 08:16 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/12 "2019-08-01T08:16:32Z")

</div>

I want to create email alerts for a particular value of vibration and temperature.  
But Vibration comes in different values like rms\_x,rms\_y,rms\_z etc  
 ![error2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c22fe76a509eaddb1c352c60f4898791d8c5b4a2.jpeg)

I have created a function for sending temperature value

 ![error6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/1/1bf233e7a61117b051ca51bfa59d5dd901f6724c.jpeg)

like this i want to create alerts for different vibration values.  
But the problem is i have to create multiple functions for each value.

So i want to create a single function for multiple values ,like above example

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 August 2019 08:17 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/13 "2019-08-01T08:17:17Z")

</div>

Hi @adamf

If you want each of those messages to be sent, one after the other, from the single output of the Function node, then all you need to do is change:

```auto
return [RMS_X, ..., Temperature] ;

```

to

```auto
return [[ RMS_X, ..., Temperature] ] ;

```

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [1 August 2019 08:20 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/14 "2019-08-01T08:20:33Z")

</div>

Alternatively, if you want to conditionally send some messages you could do:

```auto
if (msg.payload.temperature > 25) {
   node.send({
      topic: "Subject: System .... ",
      payload: "Temperature:" + msg.payload.temperature;
   });
}

if (msg.payload.otherProperty > 10) {
   node.send({
      topic: "Subject: Something something .... ",
      payload: "Something:" + msg.payload.otherProperty;
   });
};

return;

```

By the way - please try to avoid sharing screenshots of code. It makes it impossible for us to suggest changes without retyping your code. As longs as they are relatively short, paste in your code here with ``` on a new line before and after.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [1 August 2019 08:20 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/15 "2019-08-01T08:20:52Z")

</div>

> [@adamf](#):
>
> i want to create a single function for multiple values ,like above example

In that case you were nearly right in the function posted, except you have told it to send them to multiple outputs. As I said look again at the link posted. You need to send an array containing an array, so change the last line to something like

```auto
return [[RMS_X, RMS_Y, ...]]

```

Also please don't use the word values when you mean messages (each containing a value).

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [1 August 2019 08:32 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/16 "2019-08-01T08:32:10Z")

</div>

Thanx for the help, I'll try this.

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [5 September 2019 08:14 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/17 "2019-09-05T08:14:21Z")

</div>

This is good solution,but if 6 or 7 values are true at same time,then it shows error

```auto
SMTP Error: 454 4.7.0 Too many login attempts, please try again later

```

or

```auto
"Error: Invalid login: 454 4.7.0 Too many login attempts, please try again later. d6sm2996397pgf.55 - gsmtp"

```

but it is sending emails also  
now the problem is,it is sending different mail to different value like rms\_x,rms\_y,min\_x etc.

How can i send only mail containing all the values which are true

I also tried this code

```auto
if (msg.payload.rms_x >500 || msg.payload.rms_y >800 || msg.payload.rms_z >500 || msg.payload.max_x >50 || msg.payload.max_y >50 || msg.payload.max_z >500 || msg.payload.min_x <0 || msg.payload.min_y <50 || msg.payload.min_z <50 )
 {
     msg.topic = "Subject Vibration has been exceeded";
     msg.payload = "Vibration:" + String(msg.payload.rms_x,msg.payload.rms_y,msg.payload.rms_z,msg.payload.max_x,msg.payload.max_y,msg.payload.max_z,msg.payload.min_x,msg.payload.min_y,msg.payload.min_z);
 
     return msg;
 }

```

Output

```auto
object
topic: "Subject Vibration has been exceeded"
data: object
nodeId: 0
firmware: 1
battery: 3.2940600000000004
counter: 84
sensor_type: 8
sensor_data: object
sensor_name: "Vibration"
type: "sensor_data"
addr: "00:13:a2:00:41:91:25:d4"
received: 1567671204814
original: object
payload: "Vibration:134.47"
_msgid: "3a2270bc.fa72d"

```

only sending first value.  
please help me with this

Thanx

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [5 September 2019 08:28 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/18 "2019-09-05T08:28:34Z")

</div>

Try changing your logical operators for or to and

[https://www.w3schools.com/js/js\_comparisons.asp](https://www.w3schools.com/js/js_comparisons.asp)

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [5 September 2019 09:20 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/19 "2019-09-05T09:20:10Z")

</div>

Yes Sir,I know that,I have used that one also,but it requires all the values to be true.

then only it will send mails

---

<div class="post-metadata">

**Author:** ![adamf](https://avatars.discourse-cdn.com/v4/letter/a/cab0a1/32.png) [@adamf](https://discourse.nodered.org/u/adamf)\
**Post date:** [5 September 2019 09:22 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/20 "2019-09-05T09:22:20Z")

</div>

can we do with this solution to send all the values in one mail

[Next page](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889.md?page=2)
