# Node for multiple outputs based on single input

**URL:** <https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645>\
**Category:** General\
**Created:** [28 September 2024 11:55 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645 "2024-09-28T11:55:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [28 September 2024 11:55 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/1 "2024-09-28T11:55:14Z")

</div>

Could anyone recommend a node for controlling a fan based on a numeric range please?

The incoming number is from an air quality sensor, the output is a hepa filter fan.

I'd like to ensure there's not a "bouncing" effect, i.e.:  
Sensor detects \>500, turns fan to LOW, sensor drops to \<500, fan goes OFF, sensor detects \>500.......and so on...

So I think a switch might be problematic.

I'll also make it so if the LWT is offline, the fan runs at LOW speed, in case the sensor fails.

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/0361842d6455518ff27a5c6c34419dc7972df158.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:** [28 September 2024 15:54 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/2 "2024-09-28T15:54:15Z")

</div>

[node-red-contrib-hysteresis](https://github.com/Sineos/node-red-contrib-hysteresis) should do what you want.  
Or you can easily achieve the same thing in a function node.

---

<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:** [28 September 2024 15:57 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/3 "2024-09-28T15:57:21Z")

</div>

> [@877](#):
>
> I'll also make it so if the LWT is offline

For this insert a Switch node that only passes the message if Offline, then a Change node that sets the fan speed to low and then feed that to the fan.

---

<div class="post-metadata">

**Author:** ![877](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/877/32/8207_2.png) [@877](https://discourse.nodered.org/u/877)\
**Post date:** [28 September 2024 21:41 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/4 "2024-09-28T21:41:29Z")

</div>

I did think of the word hysteresis but wasn’t sure it was the correct term, thanks for the link to the node.

I’m very interested in the function node code,  
I can understand filtering for the range but not sure how it could handle the hysteresis type issue.

---

<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:** [29 September 2024 09:42 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/5 "2024-09-29T09:42:11Z")

</div>

Looking more carefully I see you want three threshold values, so you would have to use three hysteresis nodes.  
Here is a flow using a function node for one threshold. You could use three of those, or extend the code to include all three thresholds.

```auto
[{"id":"7ca3a3f733af8bae","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"500","payloadType":"num","x":250,"y":3060,"wires":[["f43ec61481b0dd4c"]]},{"id":"550f755c18868c32","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"501","payloadType":"num","x":250,"y":3020,"wires":[["f43ec61481b0dd4c"]]},{"id":"7719a3e86fce4df3","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"499","payloadType":"num","x":250,"y":3100,"wires":[["f43ec61481b0dd4c"]]},{"id":"d0c8377bc31bb4df","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"498","payloadType":"num","x":250,"y":3140,"wires":[["f43ec61481b0dd4c"]]},{"id":"f43ec61481b0dd4c","type":"function","z":"bdd7be38.d3b55","name":"Hysteresis 499:501","func":"// switch value\nconst setpoint = 500\n// hysteresis to apply around that value \nconst hyst = 2 // output will switch at 499 and 501\n// values to output when msg.payload is above/below setpoint\nconst highOutput = \"LOW\"\nconst lowOutput = \"OFF\"\n// get lastoutput value\nlet lastOutput = context.get(\"lastOutput\") ?? highOutput // default to highOutput the first time through\nlet newOutput\nif (msg.payload >= setpoint + hyst/2) {\n // above threshhold\n newOutput = highOutput\n} else if (msg.payload <= setpoint - hyst/2) {\n newOutput = lowOutput\n} else {\n // within hysteresis band, keep output at the last value\n newOutput = lastOutput\n}\n// save the new output value\ncontext.set(\"lastOutput\", newOutput)\nmsg.payload = newOutput\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":3080,"wires":[["932a6dfdcfcd6ebf"]]},{"id":"932a6dfdcfcd6ebf","type":"debug","z":"bdd7be38.d3b55","name":"debug 100","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":3080,"wires":[]},{"id":"d70a158ce238f366","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"502","payloadType":"num","x":250,"y":2980,"wires":[["f43ec61481b0dd4c"]]},{"id":"264da1332312f2fb","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"497","payloadType":"num","x":250,"y":3180,"wires":[["f43ec61481b0dd4c"]]}]

```

---

<div class="post-metadata">

**Author:** ![Tany](https://avatars.discourse-cdn.com/v4/letter/t/dfb087/32.png) [@Tany](https://discourse.nodered.org/u/Tany)\
**Post date:** [30 September 2024 10:00 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/6 "2024-09-30T10:00:52Z")

</div>

Working on PWM controlled TRV-valves and -ventilationFans. Temp & hum are collected via MQTT or Zigbee, and handled with function node to convert into 0-10 or 0-255. This goes to a filter node that only outputs RBE on changes, and payload to MQTT/Zigbee out.  
For non-Zigbee, the (remote) fan is controlled by a ESP32 + PLC-LM358-PWM2V PWM to Voltage (0-10V).  
For Zigbee, the PWM is messaged to a Zigbee-bridge, that controls the TRV/Fan  
For this config i expect no hystereris-node or ranges needed.  
As the sensor-reading is approaching the target, fans will slow down and TRVs gradually will close. For TRV... the CV/pump need to go OFF before reaching end point.  
Cheers,  
T

---

<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:** [29 December 2024 10:01 UTC](https://discourse.nodered.org/t/node-for-multiple-outputs-based-on-single-input/91645/7 "2024-12-29T10:01:42Z")

</div>

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