How to send multiple values in node-red

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 ...

would you please write little example
thanx

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

I have written this

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

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.

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.

This suggestion, would solve your problem. Take a look at the documentation for dealing with messages first.

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.

Rather than creating all the different variables

Create 1 eg results

In your if statements

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.

1 Like

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.

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.

1 Like

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...

Yes sir I got your point.

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

1 Like