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?
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.
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?
Set a flow (or global) context variable and test against that in the Switch
When you said
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?
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.
Here is an example of outputting high, neutral or low, hope it helps
[{"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":[]}]
This could work if I could get the variable msg.high / msg.low to set the upper and lowe limits.
[{"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"]]}]
that's possible
Feeding in hgh and low with payload.
[{"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
[{"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.
[{"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":[]}]
Thanks, I am going to play arround with this idea. It will work!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.