# Combine two messages with two topics

**URL:** <https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969>\
**Category:** General\
**Created:** [27 July 2021 16:15 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969 "2021-07-27T16:15:29Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![myozone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myozone/32/8904_2.png) [@myozone](https://discourse.nodered.org/u/myozone)\
**Post date:** [27 July 2021 16:15 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969/1 "2021-07-27T16:15:29Z")

</div>

I've got a flow that creates two values with two topics and I would like to divide one by the other. Basically I've forgotten how to do it 🙄

The two topics are "on" and "off" which the payload is the on and off times in seconds of my fridge/freezer, I used my whole house power monitor to get the data at night when the power levels are more stable so I use the Hysteresis node and the interval timer node to get the on and off times.

I looked around but can't find a similar example.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 July 2021 16:22 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969/2 "2021-07-27T16:22:56Z")

</div>

See [this article in the cookbook](https://cookbook.nodered.org/basic/join-streams) for an example of how to join messages into one object.

---

<div class="post-metadata">

**Author:** ![myozone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myozone/32/8904_2.png) [@myozone](https://discourse.nodered.org/u/myozone)\
**Post date:** [27 July 2021 16:26 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969/3 "2021-07-27T16:26:19Z")

</div>

But how do I then divide one value by the other once combined ?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [27 July 2021 16:27 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969/4 "2021-07-27T16:27:54Z")

</div>

Feed the result of the join node into a function and divide the values then feed the answer into msg.payload and return the msg.

Attach a debug to the output of the join node to see what your joined data looks like.

---

<div class="post-metadata">

**Author:** ![myozone](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myozone/32/8904_2.png) [@myozone](https://discourse.nodered.org/u/myozone)\
**Post date:** [27 July 2021 16:31 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969/5 "2021-07-27T16:31:58Z")

</div>

Ah ok thanks, I remember now it's been a while since I fiddled with NR got it now.

```auto
msg.payload = msg.payload.one / msg.payload.two
return msg;

```

Simple when you remember 😄

---

<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:** [10 August 2021 16:32 UTC](https://discourse.nodered.org/t/combine-two-messages-with-two-topics/48969/6 "2021-08-10T16:32:24Z")

</div>

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