# Only one input on function nodes?

**URL:** <https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744>\
**Category:** General\
**Created:** [24 October 2020 11:13 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744 "2020-10-24T11:13:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![pawihd](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@pawihd](https://discourse.nodered.org/u/pawihd)\
**Post date:** [24 October 2020 11:13 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744/1 "2020-10-24T11:13:01Z")

</div>

Hi,

i would like to react on temperature values from a sensor by comparing them to threshold values from a dashboard like this:

> temperature = msg.payload;  
> if (temperature \> threshold){  
> return {payload: "over threshold"  
> }

I expected to be able to do that with a function node, but for that i would need a second input for the dynamic threshold value from my dashboard.  
And i guess, as node-red is flow driven, this is not possible by definition.

But how can i implement this?

Thanks

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [24 October 2020 11:19 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744/2 "2020-10-24T11:19:05Z")

</div>

Hi @pawihd

one approach would be to store the threshold value in [context](https://nodered.org/docs/user-guide/context).

So you would have one flow where the dashboard input is connected to Change node configured to set `flow.threshold` to the provided value.

In your function node you can add:

```auto
let threshold = flow.get("threshold");

```

to get its current value.

You'd probably also need to add a line to check if `threshold` has been set to _anything_ yet and if not, set a default...

```auto
let threshold = flow.get("threshold");
if (threshold === undefined) {
   threshold = 1234;
}

```

---

<div class="post-metadata">

**Author:** ![pawihd](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@pawihd](https://discourse.nodered.org/u/pawihd)\
**Post date:** [24 October 2020 12:08 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744/3 "2020-10-24T12:08:08Z")

</div>

Thanks for the prompt answer!  
I tried it out, but i obviously missed (or misunderstood) something!?

I have one function node which receives the threshold value from the dashboard:

> flow.threshold = msg.payload

then another function node which receives the values and should do the comparision:

> let threshold = flow.get("threshold")  
> if (msg.payload \> threshold) {return {payload:"over threshold"}}

What is wrong?

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [24 October 2020 12:25 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744/4 "2020-10-24T12:25:43Z")

</div>

Either use a change node to set the flow.threshold as suggested. Or in the function you need flow.set(“threshold “) = msg.payload;

---

<div class="post-metadata">

**Author:** ![pawihd](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@pawihd](https://discourse.nodered.org/u/pawihd)\
**Post date:** [24 October 2020 12:35 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744/5 "2020-10-24T12:35:01Z")

</div>

Thats it, i understand and it works!  
Thanks again!

---

<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:** [23 December 2020 12:35 UTC](https://discourse.nodered.org/t/only-one-input-on-function-nodes/34744/6 "2020-12-23T12:35:02Z")

</div>

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