# Comparision of two numeric values and make conditional accordingly

**URL:** <https://discourse.nodered.org/t/comparision-of-two-numeric-values-and-make-conditional-accordingly/54974>\
**Category:** General\
**Created:** [10 December 2021 02:51 UTC](https://discourse.nodered.org/t/comparision-of-two-numeric-values-and-make-conditional-accordingly/54974 "2021-12-10T02:51:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aminulhaq](https://avatars.discourse-cdn.com/v4/letter/a/f17d59/32.png) [@aminulhaq](https://discourse.nodered.org/u/aminulhaq)\
**Post date:** [10 December 2021 02:51 UTC](https://discourse.nodered.org/t/comparision-of-two-numeric-values-and-make-conditional-accordingly/54974/1 "2021-12-10T02:51:04Z")

</div>

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

---

<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:** [10 December 2021 09:03 UTC](https://discourse.nodered.org/t/comparision-of-two-numeric-values-and-make-conditional-accordingly/54974/2 "2021-12-10T09:03:50Z")

</div>

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

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [10 December 2021 09:07 UTC](https://discourse.nodered.org/t/comparision-of-two-numeric-values-and-make-conditional-accordingly/54974/3 "2021-12-10T09:07:59Z")

</div>

First off, being a new user of NR, I recommend watching this playlist: [Node-RED Essentials](https://www.youtube.com/playlist?list=PLyNBB9VCLmo1hyO-4fIZ08gqFcXBkHy-6). 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](https://cookbook.nodered.org/basic/join-streams)) 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.

---

<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:** [8 February 2022 09:08 UTC](https://discourse.nodered.org/t/comparision-of-two-numeric-values-and-make-conditional-accordingly/54974/4 "2022-02-08T09:08:37Z")

</div>

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