Comparision of two numeric values and make conditional accordingly

Hi,
I am new in node red and dont k now programing language of node red,
i have taken two temperature values from my PLC and now i want to compare these two values and put conditional on it like if differencer of two values is greater then two then generate output or to send massage to whattsapp, i have done whattsapp messaging part but need help how can i make condition and difference by function programing or by any node
Thanks

This depends on how the messages are coming in. If in same message then no need to join, but if in seperate messages you would need to join

here are 2 examples

[{"id":"3700ccb2.13e61c","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"temp1\":30,\"temp2\":20}","payloadType":"json","x":200,"y":420,"wires":[["f292fe8b.6236e"]]},{"id":"f292fe8b.6236e","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"payload.diff","pt":"msg","to":"payload.temp1 - payload.temp2","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":480,"y":420,"wires":[["8ea65a2a.82955"]]},{"id":"8ea65a2a.82955","type":"switch","z":"c791cbc0.84f648","name":"","property":"payload.diff","propertyType":"msg","rules":[{"t":"gt","v":"5","vt":"num"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":710,"y":420,"wires":[["eb09cf04.0c501"],["53f22e73.4abe1"]]},{"id":"2eb62b45.77169c","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"temp1\":30,\"temp2\":26}","payloadType":"json","x":190,"y":460,"wires":[["f292fe8b.6236e"]]},{"id":"9e9e5902.988908","type":"join","z":"c791cbc0.84f648","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":310,"y":580,"wires":[["f292fe8b.6236e"]]},{"id":"eb09cf04.0c501","type":"debug","z":"c791cbc0.84f648","name":"> 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":920,"y":400,"wires":[]},{"id":"53f22e73.4abe1","type":"debug","z":"c791cbc0.84f648","name":"<= 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":910,"y":480,"wires":[]},{"id":"dffe3bf9.b5288","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temp1","payload":"28","payloadType":"num","x":150,"y":560,"wires":[["9e9e5902.988908"]]},{"id":"bf8ab5e8.03a9b","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temp1","payload":"30","payloadType":"num","x":150,"y":520,"wires":[["9e9e5902.988908"]]},{"id":"a302bd0a.5059b8","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temp2","payload":"20","payloadType":"num","x":150,"y":640,"wires":[["9e9e5902.988908"]]},{"id":"8d2b2ebe.7e7338","type":"inject","z":"c791cbc0.84f648","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"temp2","payload":"26","payloadType":"num","x":150,"y":680,"wires":[["9e9e5902.988908"]]}]

First off, being a new user of NR, I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

Next are the two values coming into your flow in the same msg or are you getting two seperate msgs?

You need to understand that each msg goes thru the flow seperately. If the vaues are in the same msg then it is easy, if they are in different msgs the you need to join them (see: Create a single message from separate streams of messages : Node-RED) so you can test the two against each other. You can easily test them against each other by using a switch node and having two outputs from the switch node doing what ever else you need to do.

1 Like

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