# Getting information from 2 different msg and putting out a msg that can be charted

**URL:** <https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011>\
**Category:** General\
**Tags:** function-node\
**Created:** [24 May 2022 14:43 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011 "2022-05-24T14:43:51Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CAG](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@CAG](https://discourse.nodered.org/u/CAG)\
**Post date:** [24 May 2022 14:43 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011/1 "2022-05-24T14:43:51Z")

</div>

ok, here is what I am doing.  
I have HomeSeer (z-wave hub) and Ambient Weather.  
I can read both of these just fine, what I am trying to do is:  
Check the thermostat to see if it is on/off

- if it is on then chart the Cooling Temp setting from the Thermostat on the chart with the inside and outside temps.  
i.e. - Outside Temp - 60  
Inside Temp - 80  
Cooling Temp - 75, Fan On  
What I want to see is a chart with all of the current Temps (Outside, Inside, Cooling (75)  
if the Fan is off then set the Cooling Temp to 0 or simply not display it.

I think that my problem is the Fan returns a status of "On" or "Off" while the Thermostat returns a number - 75

Here is the function I am using -

```auto
context.data = context.data || {};
switch (msg.topic) {
    case "BarnFan":
        context.data.BarnFan = msg.payload;
        node.warn("Fan Status Received")
        msg = null;
        break;
    case "BarnCooling":
        context.data.BarnCooling =msg.payload;
        node.warn("Cooling Temp Received")
        msg = null;
        break;
    default:
        msg = null;
        break;
}

if (context.data.task1 != null && context.data.task2 != null) {
node.warn("Both received")
    if (context.data.task1 == "On") {
        return {payload:0};
    } else return {payload:context.data.BarnCooling};
} else return msg;
    

```

![Screenshot 2022-05-24 074226](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/1892352e2ae642e2396dfa7dc726aefdf327fadd.jpeg)

---

<div class="post-metadata">

**Author:** ![CAG](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@CAG](https://discourse.nodered.org/u/CAG)\
**Post date:** [24 May 2022 14:53 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011/2 "2022-05-24T14:53:30Z")

</div>

Ok, I fixed it. Cafeful when you copy examples and drink more tea 🙂

```auto
context.data = context.data || {};
switch (msg.topic) {
    case "BarnFan":
        context.data.BarnFan = msg.payload;
        node.warn("Fan Status Received")
        msg = null;
        break;
    case "BarnCooling":
        context.data.BarnCooling =msg.payload;
        node.warn("Cooling Temp Received")
        msg = null;
        break;
    default:
        msg = null;
        break;
}

if (context.data.BarnFan != null && context.data.BarnCooling != null) {
node.warn("Both received")
    if (context.data.BarnFan == "Off") {
        return {payload:0};
    } else return {payload:context.data.BarnCooling};
    // var ratio = context.data.task1 / context.data.task2;
    // context.data=null;
    // return {payload:ratio};
    } else return msg;
    

```

---

<div class="post-metadata">

**Author:** ![CAG](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@CAG](https://discourse.nodered.org/u/CAG)\
**Post date:** [24 May 2022 15:23 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011/3 "2022-05-24T15:23:29Z")

</div>

Ok, next step  
I want to only plot on the chart if the Fan is On.  
I tried setting the payload to null that doesn't work, it is an error.

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [25 May 2022 13:37 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011/4 "2022-05-25T13:37:04Z")

</div>

Do not set the payload to null, if you want to send nothing specify

`return null;`

So no object will be returned.

---

<div class="post-metadata">

**Author:** ![CAG](https://avatars.discourse-cdn.com/v4/letter/c/a9adbd/32.png) [@CAG](https://discourse.nodered.org/u/CAG)\
**Post date:** [25 May 2022 16:38 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011/5 "2022-05-25T16:38:57Z")

</div>

Thanks, I will try that.  
I am using the dashboard Chart Node and want a gap in the line when the fan is off and when the fan is on, the Cooling Temp setting.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [8 June 2022 16:39 UTC](https://discourse.nodered.org/t/getting-information-from-2-different-msg-and-putting-out-a-msg-that-can-be-charted/63011/6 "2022-06-08T16:39:32Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
