# If Function ((with two Inputs))?

**URL:** https://discourse.nodered.org/t/if-function-with-two-inputs/13305
**Category:** General
**Created:** [15 July 2019 13:44 UTC](https://discourse.nodered.org/t/if-function-with-two-inputs/13305 "2019-07-15T13:44:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Kiwi\_gamer01](https://avatars.discourse-cdn.com/v4/letter/k/a587f6/32.png) [@Kiwi\_gamer01](https://discourse.nodered.org/u/Kiwi_gamer01)
#### Post date: [15 July 2019 13:44 UTC](https://discourse.nodered.org/t/if-function-with-two-inputs/13305/1 "2019-07-15T13:44:58Z")

</div>

Is there an if function that takes and compares a value of a slider and a lux sensor.

This means that if the lux value is greater than the value of the slider, a value of 1 should be sent

---

<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: [15 July 2019 14:12 UTC](https://discourse.nodered.org/t/if-function-with-two-inputs/13305/2 "2019-07-15T14:12:21Z")

</div>

There are no nodes in Node-RED with two separate inputs, but you can do compare two values where they are in separate messages; take a look at this example in the cookbook  
[https://cookbook.nodered.org/basic/route-on-context](https://cookbook.nodered.org/basic/route-on-context)

Context values can also be used in a function node, see: [https://nodered.org/docs/user-guide/writing-functions](https://nodered.org/docs/user-guide/writing-functions)  
which would allow you to do it in an if statement within a function node

---

<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: [15 July 2019 16:15 UTC](https://discourse.nodered.org/t/if-function-with-two-inputs/13305/3 "2019-07-15T16:15:11Z")

</div>

You then sent me a private message (copied here so that others can also learn if they find this post)

> Hello, I do not understand the two inputs, could you rewrite your example that fits my program. I get a lux value (0-65000) and a value of a slider, and if the lux value is higher than the slider value, a signal should be sent to a GPIO pin.

Have one flow that saves the slider value to a context value (eg `global.sliderLux`)  
In your lux flow have a switch node configured (eg `msg.payload` is` > global.sliderLux` )  
This will only pass the message on if your lux value ( msg.payload) is greater than your slider value
