# 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:** 10\
**Page:** 2

<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 09:23 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/21 "2019-09-05T09:23:13Z")

</div>

Then you could test each one separately if it is true then add it to msg.payload.

At the end if msg.payload has any length then send ...

---

<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:42 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/22 "2019-09-05T09:42:37Z")

</div>

would you please write little example  
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 09:49 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/23 "2019-09-05T09:49:23Z")

</div>

Have a go, it's basic javascript...

---

<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 10:54 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/24 "2019-09-05T10:54:54Z")

</div>

I have written this

```auto
var Temprature = '';
var Humidity = '';
var RMS_x = '';
var RMS_y = '';
var RMS_z = '';
var MAX_x = '';
var MAX_y = '';
var MAX_z = '';
var MIN_x = '';
var MIN_y = '';
var MIN_z = '';

if (msg.payload.temperature > 28) //You can add value according to your need
{
     Temprature = "Temprature "+msg.payload.temperature;
   
}

if (msg.payload.humidity > 80) 
{
   Humidity = "Humidity: "+msg.payload.humidity;
   
}

if (msg.payload.rms_x > 100) 
{
     RMS_x = "RMS_x: "+msg.payload.rms_x;
   
}
if (msg.payload.rms_x > 100) 
{
     RMS_y = "RMS_y: "+msg.payload.rms_y;
   
}
if (msg.payload.rms_x > 100) 
{
    RMS_z = "RMS_z: "+msg.payload.rms_z;
   
}
if (msg.payload.max_x > 100) 
{
     MAX_x = "MAX_x: "+msg.payload.max_x;
   
}
if (msg.payload.max_y > 100) 
{
     MAX_y = "MAX_y: "+msg.payload.max_y;
   
}
if (msg.payload.max_z > 100) 
{
    MAX_z = "MAX_z: "+msg.payload.max_z;
   
}
if (msg.payload.min_x < -100 ) 
{
    MIN_x = "MIN_x: "+msg.payload.min_x;
   
}
if (msg.payload.min_y < -100) 
{
     MIN_y = "MIN_y: "+msg.payload.min_y;
   
}
if (msg.payload.min_z < -100) 
{
     MIN_z = "MIN_z: "+msg.payload.min_z;
   
}

node.send({
      topic: "Subject: System value has been exceeded ",
      payload: "Property:" + Temprature+ " " + Humidity + " " + RMS_x + " " + RMS_y + " " + RMS_z +" " + MAX_x+ " " + MAX_y+ " " + MAX_z + " " + MIN_x +" " + MIN_y +" " + MIN_z ,
   });

return;

```

but when there is no values,then also it is sending data

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [5 September 2019 11:04 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/25 "2019-09-05T11:04:55Z")

</div>

> [@adamf](#):
>
> 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

Just for clarification, are you saying it should only send the email when all the conditions are true?  
So in text, when `rms_x` is bigger than 500, **and** `rms_y` is bigger than 800, **and** `rms_z` bigger than 500, **and** `max_x` bigger than 50, **and**... and so on.

> [@adamf](#):
>
> How can i send only mail containing all the values which are true

The code you posted below that will send an email every time one of those values is exceeding, and posts them for all. The suggestion @ukmoose then added would result in only getting an email when all of those values were true.

> [@ukmoose](#):
>
> Then you could test each one separately if it is true then add it to msg.payload.

This suggestion, would solve your problem. Take a look at the documentation for [dealing with messages first](https://nodered.org/docs/user-guide/messages).

The basic idea is based on using `msg.payload` as object, so start with creating a copy of the contents of msg.payload so you can keep those in your checks.  
Then create a new empty object to use as payload: `var basePayload = {}`.  
Next you add those checks like you did in your last post, except instead of writing to separate values, you would write those to your new `basePayload` object. Since it's an object already, you won't have to define properties on it.  
Finally, after all those if statements for the checks, test if your `basePayload` is still an empty object. If so, nothing exceeded, so nothing has to be send. If it isn't, use it to format your email with the values. They're in your `basePayload`, you can set them now to be send the way you would like.

---

<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 11:07 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/26 "2019-09-05T11:07:00Z")

</div>

Rather than creating all the different variables

Create 1 eg results

In your if statements

```auto
results = results + msg.payload.whatever

```

Then at the end of the if statements do another if statement that checks that results length is more than 0

if it is do the send...

if it isn't none of the values were above the threshold and theres nothing to send...

There are other ways to do this, but the chances are you'll be able to understand this way in 6 months time.

---

<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 11:14 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/27 "2019-09-05T11:14:44Z")

</div>

i just want to send an email containing all those values which increases,  
in that one i am sending many mails

Can you please write some example.

---

<div class="post-metadata">

**Author:** ![afelix](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/afelix/32/9743_2.png) [@afelix](https://discourse.nodered.org/u/afelix)\
**Post date:** [5 September 2019 11:17 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/28 "2019-09-05T11:17:03Z")

</div>

Follow my steps, or that one from @ukmoose. That one is actually easier than my suggestion so it might be a good place to get started. I'm not going to write your code for you, and if you'd like to be able to do this or variations on this in the future yourself, you'll have to understand what you're doing. I'm willing to post suggestions on where to start looking in documentation, but what is posted here should be enough if you have basic javascript knowledge. The set of if statements from your previous post with code shows that you have enough basic javascript knowledge to work this out.

Please read those over again carefully. The answer is already in here, but you will have to write the actual code yourself.

---

<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 11:19 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/29 "2019-09-05T11:19:49Z")

</div>

> [@adamf](#):
>
> i just want to send an email containing all those values which increases,  
> in that one i am sending many mails

If you follow the suggestion it should only send on one Email per message, if you are sending many emails. You are either getting many messages very quickly or you are getting a separate message per variable.

You need to put debug flows into your flow to check what you are getting...

---

<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 11:31 UTC](https://discourse.nodered.org/t/how-to-send-multiple-values-in-node-red/13889/30 "2019-09-05T11:31:47Z")

</div>

Yes sir I got your point.

```auto
var results = '';

if (msg.payload.temperature > 28) //You can add value according to your need
{
     //Temprature = "Temprature "+msg.payload.temperature;
    results = results + "Temprature "+msg.payload.temperature;
}

if (msg.payload.humidity > 80) 
{
   results = results +" Humidity: "+msg.payload.humidity;
   
}

if (msg.payload.rms_x > 100) 
{
    results += " RMS_x: "+msg.payload.rms_x;
    // RMS_x = " RMS_x: "+msg.payload.rms_x;
   
}
if (msg.payload.rms_x > 100) 
{
    results+= " RMS_y: "+msg.payload.rms_y;
     //RMS_y = "RMS_y: "+msg.payload.rms_y;
   
}
if (msg.payload.rms_x > 100) 
{
    results+= " RMS_z: "+msg.payload.rms_z;
    //RMS_z = "RMS_z: "+msg.payload.rms_z;
   
}
if (msg.payload.max_x > 100) 
{
    results+= " MAX_x: "+msg.payload.max_x;
     //MAX_x = "MAX_x: "+msg.payload.max_x;
   
}
if (msg.payload.max_y > 100) 
{
    results+= " MAX_y: "+msg.payload.max_y;
    // MAX_y = "MAX_y: "+msg.payload.max_y;
   
}
if (msg.payload.max_z > 100) 
{
    results+= " MAX_z: "+msg.payload.max_z;
   // MAX_z = "MAX_z: "+msg.payload.max_z;
   
}
if (msg.payload.min_x < -100 ) 
{
    results+= " MIN_x: "+msg.payload.min_x;
   // MIN_x = "MIN_x: "+msg.payload.min_x;
   
}
if (msg.payload.min_y < -100) 
{
    results+= " MIN_y: "+msg.payload.min_y;
     //MIN_y = "MIN_y: "+msg.payload.min_y;
   
}
if (msg.payload.min_z < -100) 
{
    results+= " MIN_z: "+msg.payload.min_z;
    // MIN_z = "MIN_z: "+msg.payload.min_z;
   
}
if(results !==""){
  node.send({
      topic: "Subject: Emergency ",
     payload: results    
   });  
}
return;

```

I wrote this now and sending only one mail  
thanx

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