# Forward message based on a dropdown menu status

**URL:** <https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326>\
**Category:** General\
**Created:** [11 March 2024 07:25 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326 "2024-03-11T07:25:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![htlvale](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@htlvale](https://discourse.nodered.org/u/htlvale)\
**Post date:** [11 March 2024 07:25 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326/1 "2024-03-11T07:25:15Z")

</div>

Basically I want a co2 value that comes from an mqtt message and converted into a number and then set a pin true depending on the value of the co2 value. But this should only happen if a dropdown menu is set to true. I tried this with a logical and node, but never got it right. Unfortunately, the function nodes cannot process 2 inputs. Does anyone perhaps have an idea how I could implement this?

---

<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:** [11 March 2024 07:34 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326/2 "2024-03-11T07:34:01Z")

</div>

> [@htlvale](#):
>
> the function nodes cannot process 2 inputs

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

Once you have both values in one msg, you can do logic checks.

  

Alternatively, store both values in [context](https://nodered.org/docs/user-guide/context), then you can retrieve both values from context and do your logic tests.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [11 March 2024 08:11 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326/3 "2024-03-11T08:11:54Z")

</div>

Hello and welcome to the Forum.

Various ways to implement this. To get you started, here's a simple example using flow-context.

 ![forward_monday_v4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/39832adccdea61d7dd55d7f88dfb8cb0c9357145.png)  
The 'logic' this flow implements is... you need an input greater than 10 AND dropdown must be 'true'.

```auto
[{"id":"87a6eab4f305fa45","type":"tab","label":"Forward_message","disabled":false,"info":"","env":[]},{"id":"4647dc7fd8b4052a","type":"change","z":"87a6eab4f305fa45","name":"","rules":[{"t":"set","p":"dropdown","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":120,"wires":[[]]},{"id":"b0742a532562b986","type":"inject","z":"87a6eab4f305fa45","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"21","payloadType":"num","x":170,"y":260,"wires":[["29adf4552a70cfde"]]},{"id":"62a5f0d60d72a2e5","type":"debug","z":"87a6eab4f305fa45","name":"Check output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":600,"y":300,"wires":[]},{"id":"285f6c971c616361","type":"inject","z":"87a6eab4f305fa45","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":170,"y":140,"wires":[["4647dc7fd8b4052a"]]},{"id":"638a252deb52d314","type":"inject","z":"87a6eab4f305fa45","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":170,"y":100,"wires":[["4647dc7fd8b4052a"]]},{"id":"cceab04efcd4c834","type":"comment","z":"87a6eab4f305fa45","name":"This simulates an input from your MQTT-In node","info":"","x":280,"y":220,"wires":[]},{"id":"e583ca42228eb519","type":"comment","z":"87a6eab4f305fa45","name":"Simulate your dropdown ","info":"","x":210,"y":60,"wires":[]},{"id":"29adf4552a70cfde","type":"function","z":"87a6eab4f305fa45","name":"check values and states","func":"let dropdown = flow.get(\"dropdown\") || false;\nlet threshold = 10;\n\nif (msg.payload > threshold && dropdown === true) {\n msg.payload = true;\n node.status({fill:\"red\",shape:\"dot\",text:\"Turn Pin ON\"});\n return msg;\n}\nelse {\n msg.payload = false;\n node.status({fill:\"green\",shape:\"dot\",text:\"Turn Pin OFF\"});\n return msg;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":370,"y":300,"wires":[["62a5f0d60d72a2e5","3a626d0bafc76940"]]},{"id":"ccb70d851742d6c7","type":"inject","z":"87a6eab4f305fa45","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":170,"y":340,"wires":[["29adf4552a70cfde"]]},{"id":"b9f006b3634576ea","type":"comment","z":"87a6eab4f305fa45","name":"Threshold is set to 10 inside function node","info":"","x":420,"y":360,"wires":[]},{"id":"3a626d0bafc76940","type":"rpi-gpio out","z":"87a6eab4f305fa45","name":"","pin":"24","set":"","level":"0","freq":"","out":"out","bcm":true,"x":580,"y":240,"wires":[]},{"id":"3346a85ea7b60b37","type":"comment","z":"87a6eab4f305fa45","name":"Change PIN number to suit","info":"","x":630,"y":200,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![htlvale](https://avatars.discourse-cdn.com/v4/letter/h/e480ec/32.png) [@htlvale](https://discourse.nodered.org/u/htlvale)\
**Post date:** [12 March 2024 08:54 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326/4 "2024-03-12T08:54:53Z")

</div>

thank you, that works. Is there a possibility that when the dropdown menu is set to false, that the function node does not give an output, currently it always gives false but I would like to continue to control the pin via a button when the dropdown menu is set to false.

---

<div class="post-metadata">

**Author:** ![dynamicdave](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dynamicdave/32/96_2.png) [@dynamicdave](https://discourse.nodered.org/u/dynamicdave)\
**Post date:** [12 March 2024 09:08 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326/5 "2024-03-12T09:08:31Z")

</div>

I'm not sure exactly what you are after.  
You could change the last line of the function node to **return null;** and see if that works for you.

```auto
let dropdown = flow.get("dropdown") || false;
let threshold = 10;

if (msg.payload > threshold && dropdown === true) {
    msg.payload = true;
    node.status({fill:"red",shape:"dot",text:"Turn Pin ON"});
    return msg;
}
else {
    msg.payload = false;
    node.status({fill:"green",shape:"dot",text:"Turn Pin OFF"});
    return null; // <<<< change this line
}

```

---

<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:** [26 March 2024 09:46 UTC](https://discourse.nodered.org/t/forward-message-based-on-a-dropdown-menu-status/86326/7 "2024-03-26T09:46:39Z")

</div>

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