Function for Hysteresi on analog signal

Hi,
I would like to implement a function for the control of an analog signal, with the operation indicated below:

hyst01

I don't know how to memorize the fact that the input signal has exceeded the setpoint inside the function attached, any help is welcome.

[{"id":"483a7328.79364c","type":"function","z":"7aab5d55.3ddbd4","name":"Input","func":"msg.payload=Number(msg.payload);\nmsg.topic = \"Input\";\nreturn msg;","outputs":1,"noerr":0,"x":270,"y":180,"wires":[["a3c54186.81ec"]]},{"id":"e8490a51.f32b38","type":"function","z":"7aab5d55.3ddbd4","name":"SetPoint","func":"msg.payload=Number(msg.payload);\nmsg.topic = \"SetPoint\";\nreturn msg;","outputs":1,"noerr":0,"x":260,"y":280,"wires":[["a3c54186.81ec"]]},{"id":"a3c54186.81ec","type":"function","z":"7aab5d55.3ddbd4","name":"Comparatore","func":"context.set(msg.topic,msg.payload);\n\nvar SetPoint = context.get(\"SetPoint\") ||100;\nvar In = context.get(\"Input\") || 0;\nvar Hyst = context.get(\"Hyst\") || 10;\n\nif (In > (SetPoint)) \n{\n    msg.payload = 1;               // HL  >100\n} \nelse if (In <= (SetPoint-Hyst))\n{\n     msg.payload = 0;          // LL  <=90\n       \n} else \n{\n    msg.payload = 2;            // \n}\n\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":240,"wires":[["b66c62b0.04fd1"]]},{"id":"26479dfa.2ab9f2","type":"inject","z":"7aab5d55.3ddbd4","name":"","topic":"","payload":"91","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":200,"wires":[["483a7328.79364c"]]},{"id":"8809f3e3.e344f","type":"inject","z":"7aab5d55.3ddbd4","name":"","topic":"","payload":"100","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":280,"wires":[["e8490a51.f32b38"]]},{"id":"25e1a718.395a68","type":"inject","z":"7aab5d55.3ddbd4","name":"","topic":"","payload":"105","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["483a7328.79364c"]]},{"id":"8aadddc7.7259f","type":"inject","z":"7aab5d55.3ddbd4","name":"","topic":"","payload":"89","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":240,"wires":[["483a7328.79364c"]]},{"id":"b66c62b0.04fd1","type":"switch","z":"7aab5d55.3ddbd4","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"2","vt":"num"}],"checkall":"true","repair":false,"outputs":3,"x":590,"y":240,"wires":[[],[],[]],"outputLabels":["Reset","SendMsg","Targhet"]}]

There is a hysteresis node available, would that help you out ?

Hi bakman2,

thanks for your help, the Hysteresi node works as I wanted, how can I parameterize the input thresholds through an input function?

Can you give me a little idea to work on?

Thanks

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