# Special hysteresis

**URL:** <https://discourse.nodered.org/t/special-hysteresis/50448>\
**Category:** General\
**Created:** [31 August 2021 14:24 UTC](https://discourse.nodered.org/t/special-hysteresis/50448 "2021-08-31T14:24:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [31 August 2021 14:24 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/1 "2021-08-31T14:24:39Z")

</div>

I need help with the following problem. I am using a hysteresis node to determine the switching of an output by using an incoming variable. Furthermore I am using a variable to determine the high band and the low band limit. All the messages in-between get blocked until the higher or lower limits are reached. How could I for example pre determine two values, high and low and then just add the status High, when the variable exceeds the high limit. When the variable is between the two limits, gets the status, neutral and when the variable goes under the lower limits, gets the status low. Sound complicated? I think there isn’t a standard node for this. Any suggestions?

---

<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:** [31 August 2021 19:34 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/2 "2021-08-31T19:34:24Z")

</div>

You can use a Switch node to send the message down three different wires dependant on the value, then in those wires set the status and join the wires back together again.

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [31 August 2021 20:52 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/3 "2021-08-31T20:52:34Z")

</div>

Hi Colin, I have had a look at the switch node for the task, only I can't send a variable for the switch point. or can you?

---

<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:** [31 August 2021 20:57 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/4 "2021-08-31T20:57:37Z")

</div>

> [@Duncan](#):
>
> I can't send a variable for the switch point

Set a flow (or global) context variable and test against that in the Switch

---

<div class="post-metadata">

**Author:** ![drmibell](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/drmibell/32/8424_2.png) [@drmibell](https://discourse.nodered.org/u/drmibell)\
**Post date:** [31 August 2021 21:13 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/5 "2021-08-31T21:13:59Z")

</div>

When you said

> [@Duncan](#):
>
> I am using a hysteresis node

I assumed that you were using a contributed node, something like `node-red-contrib-hysteresis` or its close relation `node-red-smithtek-hysteresis`. Is there a reason why one of these won't do what you need?

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [1 September 2021 06:51 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/6 "2021-09-01T06:51:23Z")

</div>

I am using the _node-red-smithtek-hysteresis_ node because I can use a variable to set the "high" and "Low" limits dynamically. When the incomming messages have hit one of these limits it will trigger. What I actually need are the massages in the "dead band" aswell.  
for example: When a measured value has passed the “high” setpoint it only sends one message”high”. The status of the node has “high band rising”, “high band falling”, “high deadband falling”, “low band”, “low band falling”, basically I need to know the other statuses so I can take other actions when I know which direction the value is going.

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [1 September 2021 07:34 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/7 "2021-09-01T07:34:53Z")

</div>

Here is an example of outputting high, neutral or low, hope it helps

```auto
[{"id":"15705321.9a3e5d","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":170,"y":2900,"wires":[["15054293.cdc9ed"]]},{"id":"15054293.cdc9ed","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"$$.payload < 15 ? \"low\" : $$.payload > 25 ? \"high\" : \"neutral\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":2980,"wires":[["fc9f5d97.4fe9d8"]]},{"id":"6781fa74.d62d14","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":170,"y":2960,"wires":[["15054293.cdc9ed"]]},{"id":"bea6911a.561d3","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":170,"y":3020,"wires":[["15054293.cdc9ed"]]},{"id":"fc9f5d97.4fe9d8","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":590,"y":2960,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [1 September 2021 08:02 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/8 "2021-09-01T08:02:50Z")

</div>

This could work if I could get the variable msg.high / msg.low to set the upper and lowe limits.

```auto
[{"id":"15705321.9a3e5d","type":"inject","z":"0bb5bb0be91e8e3a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":590,"y":980,"wires":[["15054293.cdc9ed"]]},{"id":"15054293.cdc9ed","type":"change","z":"0bb5bb0be91e8e3a","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"$$.payload < msg.low ? \"low\" : $$.payload > msg.high ? \"high\" : \"neutral\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":860,"wires":[["fc9f5d97.4fe9d8"]]},{"id":"6781fa74.d62d14","type":"inject","z":"0bb5bb0be91e8e3a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":590,"y":840,"wires":[["15054293.cdc9ed"]]},{"id":"bea6911a.561d3","type":"inject","z":"0bb5bb0be91e8e3a","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":590,"y":700,"wires":[["15054293.cdc9ed"]]},{"id":"fc9f5d97.4fe9d8","type":"debug","z":"0bb5bb0be91e8e3a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1010,"y":860,"wires":[]},{"id":"e8449762da70d1c4","type":"inject","z":"0bb5bb0be91e8e3a","name":"high - 25","props":[{"p":"high","v":"25","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"high","x":580,"y":760,"wires":[["15054293.cdc9ed"]]},{"id":"213a2c8bf2facce5","type":"inject","z":"0bb5bb0be91e8e3a","name":"low - 15","props":[{"p":"low","v":"15","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"low","x":590,"y":920,"wires":[["15054293.cdc9ed"]]}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [1 September 2021 08:10 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/9 "2021-09-01T08:10:23Z")

</div>

that's possible

Feeding in hgh and low with payload.

```auto
[{"id":"15054293.cdc9ed","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"$$.payload < $$.low ? \"low\" : $$.payload > $$.high ? \"high\" : \"neutral\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":2960,"wires":[["fc9f5d97.4fe9d8"]]},{"id":"15705321.9a3e5d","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"high","v":"25","vt":"num"},{"p":"low","v":"15","vt":"num"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":210,"y":2960,"wires":[["15054293.cdc9ed"]]},{"id":"fc9f5d97.4fe9d8","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":2940,"wires":[]}]

```

[edit] Or using context storage

```auto
[{"id":"bea6911a.561d3","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"30","payloadType":"num","x":150,"y":2860,"wires":[["15054293.cdc9ed"]]},{"id":"15054293.cdc9ed","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"$$.payload < $flowContext(\"presets.low\") ? \"low\" : $$.payload > $flowContext(\"presets.high\") ? \"high\" : \"neutral\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":3020,"wires":[["fc9f5d97.4fe9d8"]]},{"id":"15705321.9a3e5d","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"10","payloadType":"num","x":150,"y":3140,"wires":[["15054293.cdc9ed"]]},{"id":"fc9f5d97.4fe9d8","type":"debug","z":"c74669a0.6a34f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":570,"y":3020,"wires":[]},{"id":"6781fa74.d62d14","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":150,"y":3000,"wires":[["15054293.cdc9ed"]]},{"id":"e8449762da70d1c4","type":"inject","z":"c74669a0.6a34f8","name":"high - 25","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"high","payload":"25","payloadType":"num","x":400,"y":2880,"wires":[["4ee59ba3.9d9974"]]},{"id":"213a2c8bf2facce5","type":"inject","z":"c74669a0.6a34f8","name":"low - 15","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"low","payload":"15","payloadType":"num","x":400,"y":2920,"wires":[["4ee59ba3.9d9974"]]},{"id":"4ee59ba3.9d9974","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"presets","pt":"flow","to":"$merge([$flowContext(\"presets\"),{$$.topic:$$.payload}])","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":2880,"wires":[[]]}]

```

Or using a join node.

```auto
[{"id":"bea6911a.561d3","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reading","payload":"30","payloadType":"num","x":170,"y":2940,"wires":[["f12c3e40.366bf8"]]},{"id":"f12c3e40.366bf8","type":"join","z":"c74669a0.6a34f8","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":390,"y":2960,"wires":[["15054293.cdc9ed"]]},{"id":"15705321.9a3e5d","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reading","payload":"10","payloadType":"num","x":170,"y":3040,"wires":[["f12c3e40.366bf8"]]},{"id":"6781fa74.d62d14","type":"inject","z":"c74669a0.6a34f8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"reading","payload":"20","payloadType":"num","x":170,"y":3000,"wires":[["f12c3e40.366bf8"]]},{"id":"15054293.cdc9ed","type":"change","z":"c74669a0.6a34f8","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"$$.payload.reading < $$.payload.low ? \"low\" : \t$$.payload.reading > $$.payload.high ? \"high\" : \t\"neutral\"","tot":"jsonata"},{"t":"move","p":"payload.reading","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":570,"y":2960,"wires":[["8855a4b8.d2663"]]},{"id":"213a2c8bf2facce5","type":"inject","z":"c74669a0.6a34f8","name":"low - 15","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"low","payload":"15","payloadType":"num","x":400,"y":2920,"wires":[["f12c3e40.366bf8"]]},{"id":"e8449762da70d1c4","type":"inject","z":"c74669a0.6a34f8","name":"high - 25","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"high","payload":"25","payloadType":"num","x":400,"y":2880,"wires":[["f12c3e40.366bf8"]]},{"id":"8855a4b8.d2663","type":"switch","z":"c74669a0.6a34f8","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"reading","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":740,"y":2960,"wires":[["fc9f5d97.4fe9d8"]]},{"id":"fc9f5d97.4fe9d8","type":"debug","z":"c74669a0.6a34f8","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":2960,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![Duncan](https://avatars.discourse-cdn.com/v4/letter/d/ecc23a/32.png) [@Duncan](https://discourse.nodered.org/u/Duncan)\
**Post date:** [1 September 2021 08:17 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/10 "2021-09-01T08:17:32Z")

</div>

Thanks, I am going to play arround with this idea. It will work!

---

<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:** [31 October 2021 08:17 UTC](https://discourse.nodered.org/t/special-hysteresis/50448/11 "2021-10-31T08:17:49Z")

</div>

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