# Two inputs in one function

**URL:** <https://discourse.nodered.org/t/two-inputs-in-one-function/31884>\
**Category:** General\
**Created:** [22 August 2020 18:11 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884 "2020-08-22T18:11:28Z")\
**Posts on this page:** 12\
**Page:** 2

<div class="post-metadata">

**Author:** ![MDAR](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mdar/32/10700_2.png) [@MDAR](https://discourse.nodered.org/u/MDAR)\
**Post date:** [23 August 2020 16:05 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/21 "2020-08-23T16:05:13Z")

</div>

You could always store the values in global variables, then use a `get.global` command within the function?

---

<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:** [23 August 2020 17:16 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/22 "2020-08-23T17:16:01Z")

</div>

As I said 19 hours ago,  
change the `join` option 'to create' to 'an Array'  
and the resultant msg.payload will be an array with the first msg.payload to arrive will be the first entry in the array and the second msg.payload will be the second entry in the array.

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [23 August 2020 19:47 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/23 "2020-08-23T19:47:36Z")

</div>

Hi

your flow did the trick, but my problem now is that i cant find anyware to insert a topic to my Hue bulb,  
Can you help

```auto
[{"id":"5b711416.372d9c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"2d538999.8fb956","type":"debug","z":"5b711416.372d9c","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":750,"y":200,"wires":[]},{"id":"d42efb44.448ca8","type":"join","z":"5b711416.372d9c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":550,"y":200,"wires":[["2d538999.8fb956"]]},{"id":"6308d1cc.33e48","type":"inject","z":"5b711416.372d9c","name":"Light Request (Buffer)","topic":"request","payload":"[28,2,0,97,0,0,255,130]","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":160,"wires":[["d42efb44.448ca8"]]},{"id":"130cb646.bfb3aa","type":"inject","z":"5b711416.372d9c","name":"Light Reply (JSON)","topic":"reply","payload":"{\"on\":true,\"brightness\":33,\"reachable\":true,\"rgb\":[255,178,76],\"hex\":\"ffb24c\",\"color\":\"orange\",\"colorTemp\":497,\"updated\":\"2020-08-22T20:56:26+02:00\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":340,"wires":[[]]},{"id":"3a875562.2802ba","type":"hue-light","z":"5b711416.372d9c","name":"Gulvlampe","bridge":"92011666.d44778","lightid":"2","colornamer":true,"skipevents":false,"x":190,"y":220,"wires":[["d42efb44.448ca8"]]},{"id":"92011666.d44778","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.0.11","key":"TEhdryuqFDW60NeiMR7kWSiXT-h0VwNrKAW4IeGc","interval":"3000","disableupdates":false}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/c/8cd2b5ebf31e416a891d213b7bfc631a0e3007c3.png)

---

<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:** [23 August 2020 19:52 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/24 "2020-08-23T19:52:36Z")

</div>

use a `change` node to change the topic

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [23 August 2020 20:10 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/25 "2020-08-23T20:10:24Z")

</div>

could you give me a hint, i dont know what to do with the change node

---

<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:** [23 August 2020 20:13 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/26 "2020-08-23T20:13:51Z")

</div>

have you read the documentation about the change node? [https://nodered.org/docs/user-guide/nodes#change](https://nodered.org/docs/user-guide/nodes#change)

If you haven't, go read it.  
If you have, what don't you understand about how to use it? What have you tried?

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [23 August 2020 20:26 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/27 "2020-08-23T20:26:31Z")

</div>

I did try to find something about setting a topic, but i cant find anything.

I did try this

```auto
[{"id":"5b711416.372d9c","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"2d538999.8fb956","type":"debug","z":"5b711416.372d9c","name":"Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":930,"y":380,"wires":[]},{"id":"d42efb44.448ca8","type":"join","z":"5b711416.372d9c","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"num","reduceFixup":"","x":710,"y":300,"wires":[["2d538999.8fb956"]]},{"id":"6308d1cc.33e48","type":"inject","z":"5b711416.372d9c","name":"Light Request (Buffer)","topic":"request","payload":"[28,2,0,97,0,0,255,130]","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":120,"y":240,"wires":[["d42efb44.448ca8"]]},{"id":"130cb646.bfb3aa","type":"inject","z":"5b711416.372d9c","name":"Light Reply (JSON) TEST","topic":"","payload":"{\"on\":true,\"brightness\":33,\"reachable\":true,\"rgb\":[255,178,76],\"hex\":\"ffb24c\",\"color\":\"orange\",\"colorTemp\":497,\"updated\":\"2020-08-22T20:56:26+02:00\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":400,"wires":[["1efaab1f.548975"]]},{"id":"3a875562.2802ba","type":"hue-light","z":"5b711416.372d9c","name":"Gulvlampe","bridge":"92011666.d44778","lightid":"2","colornamer":true,"skipevents":false,"x":150,"y":320,"wires":[["1efaab1f.548975"]]},{"id":"1efaab1f.548975","type":"change","z":"5b711416.372d9c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.light","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":400,"wires":[["d42efb44.448ca8","2d538999.8fb956"]]},{"id":"92011666.d44778","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.0.11","key":"TEhdryuqFDW60NeiMR7kWSiXT-h0VwNrKAW4IeGc","interval":"3000","disableupdates":false}]

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/8/08c5de075dbf7cce8561544beb20155ab7b18b6d.png)

---

<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:** [23 August 2020 20:28 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/28 "2020-08-23T20:28:27Z")

</div>

Move the change node to after the join node  
Where it says msg.payload, you can change ‘payload’ to ‘topic’

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [23 August 2020 20:31 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/29 "2020-08-23T20:31:15Z")

</div>

the Join node wont run because the JSON/Hue Bulb dont have a topic

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/0/404f1068c94cc1409c564ae669ae2700204abf35.png)

---

<div class="post-metadata">

**Author:** ![zamzon](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zamzon/32/15521_2.png) [@zamzon](https://discourse.nodered.org/u/zamzon)\
**Post date:** [23 August 2020 20:44 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/30 "2020-08-23T20:44:42Z")

</div>

I got it

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/d/9dc1b71142d3637fa08f8639f417ab15c4f1c501.png)

---

<div class="post-metadata">

**Author:** ![UnborN](https://avatars.discourse-cdn.com/v4/letter/u/4491bb/32.png) [@UnborN](https://discourse.nodered.org/u/UnborN)\
**Post date:** [23 August 2020 23:49 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/31 "2020-08-23T23:49:12Z")

</div>

> [@zenofmud](#):
>
> change the `join` option 'to create' to 'an Array'

I know .. that can work .. but with a disadvantage.  
.. the disadvantage of merging to an array, is that, when two messages arrive in the join node from the same source .. lets say 'buffer' for this example .. you will get an array with two "buffers".

![Screenshot_2020-08-24 Node-RED 192 168 1 160](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f98bb20de1b3fd81ff5b207a55f7a51ab7354b15.png)

Setting the Join to key/value object and 'number of message parts' : 2 and with 'every subsequent message' checked .. you get one msg, only the case of two subsequent messages from the two different sources.  
but it depends on the use case .. i find it safer with a key/value object.

---

<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:** [22 October 2020 23:49 UTC](https://discourse.nodered.org/t/two-inputs-in-one-function/31884/32 "2020-10-22T23:49:25Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/two-inputs-in-one-function/31884.md?page=1)
