# 2 input messages into 1 output line 1 and line 2?

**URL:** <https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304>\
**Category:** General\
**Created:** [20 September 2018 11:27 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304 "2018-09-20T11:27:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 September 2018 11:27 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/1 "2018-09-20T11:27:23Z")

</div>

Hello again  
i need to have the input messages to go to the same location every time on output

array 1 night/day  
array 2 brightness

im confussed tried to add a dellay to solve it can i do it through function?

```auto
[{"id":"b84a7f9a.24408","type":"server-events","z":"cf1115c.2dcd6e8","name":"HA All Events","server":"d0be6c93.2903a","x":270,"y":1320,"wires":[["fd7c9ec6.5f502"]]},{"id":"29e7db9a.11e0a4","type":"function","z":"cf1115c.2dcd6e8","name":"Brightness Value","func":"var temp=msg.payload.event.new_state.attributes.brightness;\nvar msg = {payload:temp};\nmsg.topic = \"brightness\"\nreturn msg;","outputs":1,"noerr":0,"x":890,"y":1320,"wires":[["48d98f79.41b7a","363b56eb.16082a","a435cd2b.f58f9"]]},{"id":"fd7c9ec6.5f502","type":"switch","z":"cf1115c.2dcd6e8","name":"Filter Kitchen lights","property":"payload.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"light.kitchen_lights","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":1320,"wires":[["b8864352.8aa0a"],[]]},{"id":"48d98f79.41b7a","type":"api-current-state","z":"cf1115c.2dcd6e8","name":"","server":"d0be6c93.2903a","halt_if":"","override_topic":false,"override_payload":false,"entity_id":"binary_sensor.sun_up","x":1190,"y":1220,"wires":[["aaeebb7d.751588"]],"outputLabels":["sunnny"]},{"id":"b8864352.8aa0a","type":"rbe","z":"cf1115c.2dcd6e8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":690,"y":1320,"wires":[["29e7db9a.11e0a4","8525153c.c3f018"]]},{"id":"51dc5e5f.29237","type":"debug","z":"cf1115c.2dcd6e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1990,"y":1300,"wires":[]},{"id":"9148ce4e.b341","type":"rbe","z":"cf1115c.2dcd6e8","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":1590,"y":1320,"wires":[["54d0fcae.af7164"]]},{"id":"54d0fcae.af7164","type":"delay","z":"cf1115c.2dcd6e8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"2","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1760,"y":1320,"wires":[["bd8cdda.f7d072","51dc5e5f.29237"]]},{"id":"363b56eb.16082a","type":"debug","z":"cf1115c.2dcd6e8","name":"","active":true,"tosidebar":true,"console":true,"tostatus":true,"complete":"payload","x":1840,"y":1200,"wires":[]},{"id":"50646725.16c588","type":"comment","z":"cf1115c.2dcd6e8","name":"Kitchen - Full 30m / Dimming 10s Auto Off 15m","info":"","x":220,"y":1220,"wires":[]},{"id":"8525153c.c3f018","type":"debug","z":"cf1115c.2dcd6e8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":890,"y":1240,"wires":[]},{"id":"aaeebb7d.751588","type":"change","z":"cf1115c.2dcd6e8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"day","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"night","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1120,"y":1260,"wires":[["b426470c.53a0c8"]]},{"id":"b426470c.53a0c8","type":"delay","z":"cf1115c.2dcd6e8","name":"","pauseType":"delay","timeout":"40","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1290,"y":1260,"wires":[["a435cd2b.f58f9","363b56eb.16082a"]]},{"id":"62495b0d.a79694","type":"change","z":"cf1115c.2dcd6e8","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1590,"y":1260,"wires":[[]]},{"id":"a435cd2b.f58f9","type":"join","z":"cf1115c.2dcd6e8","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"payload","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":1470,"y":1320,"wires":[["9148ce4e.b341"]]},{"id":"d0be6c93.2903a","type":"server","z":"","name":"Home Assistant","url":"http://hassio/homeassistant","pass":"dc3135e532cbaf42e85360934d4d6c8db1eff8d668bf130879152a8797022145"}]

```

message 1

```auto
binary_sensor.sun_up : msg.payload : string[3]

"day"

```

message 2

```auto
brightness : msg.payload : number
72

```

combined

```auto
binary_sensor.sun_up : msg.payload : array[2]

array[2]

0: 72

1: "day"

```

---

<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:** [20 September 2018 11:56 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/2 "2018-09-20T11:56:17Z")

</div>

I'm confused as to how the flow you posted relates to the question you asked.  
The flow has 3 inputs ( 2 alexa and one MQTT which looks like a switch)  
so where does `day` and `brightness` come into your flow?

But if you want to direct `message 1` and `message 2` to different places use a `switch` node  
as one payload is a number you can set a switch to `is of type` `number`

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2018 11:57 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/3 "2018-09-20T11:57:39Z")

</div>

Could you be a bit more descriptive? Even lookng at your flow, I don't know whart you want. Explain the issue and use the type/names of nodes you are using in your flow

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 September 2018 11:58 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/4 "2018-09-20T11:58:49Z")

</div>

updated flow wrong one my mistake  
sorry

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 September 2018 12:17 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/5 "2018-09-20T12:17:53Z")

</div>

Ok, when you are posting a flow for others to look at you should assume that any nodes - other than the standard flows - are not installed by others asnd you should provice the full node names so they won't have to spend their time figuring out what you have not provided.

You should also try to create the issue with a minimum number of nodes (use inject nodes to inject data from a sensor etc) and provide the platform, os, os release and the NR and node.js versions

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 September 2018 12:26 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/6 "2018-09-20T12:26:17Z")

</div>

ok all i need is message 1 and 2 in the same message but in the same location in the message every time  
can you help from the information provided?

---

<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:** [20 September 2018 12:32 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/7 "2018-09-20T12:32:39Z")

</div>

What are you trying to do with the message afterwards?

Do you need an output message every time a new message either type comes in?  
Or only when a new mesage1 or message2 comes in?

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 September 2018 12:37 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/8 "2018-09-20T12:37:41Z")

</div>

only when 1 and 2 come in not either message

then i have other flows working on the payload 1 and payload 2 but need the together in one message

---

<div class="post-metadata">

**Author:** ![chris1988](https://avatars.discourse-cdn.com/v4/letter/c/45deac/32.png) [@chris1988](https://discourse.nodered.org/u/chris1988)\
**Post date:** [20 September 2018 12:39 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/9 "2018-09-20T12:39:44Z")

</div>

![Capture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/4/42429506632310dcb125420eb29ca99607da43b3.png)

---

<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:** [20 September 2018 17:15 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/10 "2018-09-20T17:15:14Z")

</div>

You can use a Join node to combine two message payloads with different topics into a single message containing key/value pairs.

---

<div class="post-metadata">

**Author:** ![shrickus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/shrickus/32/517_2.png) [@shrickus](https://discourse.nodered.org/u/shrickus)\
**Post date:** [20 September 2018 19:33 UTC](https://discourse.nodered.org/t/2-input-messages-into-1-output-line-1-and-line-2/3304/11 "2018-09-20T19:33:03Z")

</div>

> [@chris1988](#):
>
> all i need is message 1 and 2 in the same message but in the same location in the message every time

Node-red msgs are javascript objects, so I'm not sure that what you are asking is even relevant, since the order of properies in an object are not guaranteed. Perhaps you are trying to force a sqaure peg into a round hole... can you provide some _formatted_ json examples of one msg that is ok, compared to another that is not what you want?

As Colin mentions, if you are trying to place objects into an specific indexes in a payload array, it would be safer to use named properties in a single key/value object (which the `join` node will do for you). Just set the `msg.topic` for each sensor to be the "key" to use as the property name -- then it doesn't matter what order the msgs arrive.
