# After change node not comparing on function node

**URL:** <https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070>\
**Category:** General\
**Created:** [12 December 2021 08:45 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070 "2021-12-12T08:45:42Z")\
**Posts on this page:** 15\
**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:** [12 December 2021 08:45 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/1 "2021-12-12T08:45:42Z")

</div>

Hi,  
using change node to convert PLC address to some readable format so that i can use it on function node, i doing this because i dont know how to use ALLEB BRADLY PLC address to function node after that i am comparing the values , is there way to use PLC address directly to function without change node kindly let me know, kindly see pic for reference

 ![AB Temp coperision change node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/5/556fdaab3c6c97409a0f5c166b6fd1a4f9be77fe.png)  
 ![AB Temp coperision function code](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/0/505460601ef7eed19bd42dd42afbf80d98022117.png)  
 ![AB Temp coperision join node](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/d/0dce122a7b80c5ab35a9d0b4c7a30df6c92a10ac.png)  
 ![AB Temp coperision](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/1/414a03c298652d13891558dee2b87d5b996b7278.png)  
 ![WhatsApp Image 2021-12-12 at 11.13.40 AM](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/5/2512d3d803f04fab94d8c287ecfbdb3924cf5912.jpeg)

---

<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:** [12 December 2021 08:54 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/2 "2021-12-12T08:54:44Z")

</div>

In your change node you are using flow , which is context storage. You should be using msg. You also need to set a topic for data 2 and 1, i.e. `Set, msg.topic To, T1`

---

<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:** [12 December 2021 09:01 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/3 "2021-12-12T09:01:36Z")

</div>

is it ok, what else and where i nee to make changes

 ![change node 1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/9/d9da3d278780e82ed44afb8e3df8130b7cac455b.png)

---

<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:** [12 December 2021 09:09 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/4 "2021-12-12T09:09:04Z")

</div>

I don't think you need the change node there. You probably need to set topic's for each incoming data  
e.g.

```auto
[{"id":"d226cbf4.abb8d8","type":"inject","z":"c791cbc0.84f648","name":"data 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":820,"wires":[["bce83b3d.beb44"]]},{"id":"bce83b3d.beb44","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"T1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":820,"wires":[["f2c701ba.5f7278"]]},{"id":"f2c701ba.5f7278","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":480,"y":840,"wires":[["c6d7484b.ad177"]]},{"id":"95cceaee.7c2fd","type":"change","z":"c791cbc0.84f648","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"T2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":900,"wires":[["f2c701ba.5f7278"]]},{"id":"c6d7484b.ad177","type":"debug","z":"c791cbc0.84f648","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":840,"wires":[]},{"id":"13fa7762.ab25a9","type":"inject","z":"c791cbc0.84f648","name":"data 2","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":110,"y":900,"wires":[["95cceaee.7c2fd"]]}]

```

---

<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:** [12 December 2021 09:12 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/5 "2021-12-12T09:12:24Z")

</div>

sorry, i am new in node red and json cant understand what you have sent

---

<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:** [12 December 2021 09:13 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/6 "2021-12-12T09:13:53Z")

</div>

i can see output of function if add return msg at end but why it is not comparing  
can i use address of plc directly to function node without using change node

---

<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:** [12 December 2021 09:15 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/7 "2021-12-12T09:15:23Z")

</div>

That is a flow json i exported from my node-red.  
To use copy it, then press ctrl i in the editor, paste the flow json in the import pop up and press import. You will see an example flow.  
some good reading [Working with messages : Node-RED](https://nodered.org/docs/user-guide/messages)

[https://cookbook.nodered.org/basic/join-streams](https://cookbook.nodered.org/basic/join-streams)

Export your flow by highlighting all nodes and press ctrl e, add two inject nodes with examples of data coming out of the data(plc) nodes. you can copy values using a debug node, in the side panel next to the object names, when you hover mouse you will see two icons pop up one is copy value the other copy path, these are very usefull.

---

<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:** [12 December 2021 09:23 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/8 "2021-12-12T09:23:04Z")

</div>

Actually code is working with inject node but not workig when i use pchange node with plc address

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [12 December 2021 10:00 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/9 "2021-12-12T10:00:48Z")

</div>

I will never understand why function nodes - are used. This makes the flow completely intransparent. I tried to simulate your output with inject nodes and realized your logic without writing code:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/a/5a87db024868272713f85426f56b281dd9e15598.png)

```auto
[{"id":"5340cfd658f6f6f6","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ch0","payload":"142","payloadType":"num","x":330,"y":380,"wires":[["2f12098b5d79577b"]]},{"id":"a60c55afc6b15c70","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"ch1","payload":"396","payloadType":"num","x":330,"y":440,"wires":[["2f12098b5d79577b"]]},{"id":"2f12098b5d79577b","type":"join","z":"cb05e14b.326a9","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":500,"y":400,"wires":[["675f9b230d46ed95"]]},{"id":"5d30c0bd802ccec2","type":"debug","z":"cb05e14b.326a9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":990,"y":400,"wires":[]},{"id":"675f9b230d46ed95","type":"switch","z":"cb05e14b.326a9","name":"Difference < > 5","property":"payload.ch1 - payload.ch0","propertyType":"jsonata","rules":[{"t":"gt","v":"5","vt":"num"},{"t":"lt","v":"5","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":400,"wires":[["a00e3f8dc5d6738a"],["0e1560893c977356"]]},{"id":"a00e3f8dc5d6738a","type":"change","z":"cb05e14b.326a9","name":"= 1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":380,"wires":[["5d30c0bd802ccec2"]]},{"id":"0e1560893c977356","type":"change","z":"cb05e14b.326a9","name":"= 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":420,"wires":[["5d30c0bd802ccec2"]]}]

```

The code above (JSON) can be copied in the clipboard and imported in your NodeRed using the import function. 😉

---

<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:** [12 December 2021 10:05 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/10 "2021-12-12T10:05:19Z")

</div>

my code or node red flow is working with inject node too but when i replace inject node with plc address then it is not giving me output according to conditional, if i use return msg at end of all bracket then i am also getting value coming from my plc address but it is not getting in to conditional if i use plc address instead of inject node

---

<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:** [12 December 2021 10:06 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/11 "2021-12-12T10:06:34Z")

</div>

As stated you need to set topic's for the join

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [12 December 2021 10:07 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/12 "2021-12-12T10:07:12Z")

</div>

The you have to transform the output of the plc nodes - that it matches the format of the inject nodes. So best is to show your inject nodes and the output of the plc nodes using debug nodes.

Ok if the topics are missing then put a change Node after each plc node - setting a topic (different topics for each plc node)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/f/6f740482b01b545d163a7be434a169d9f59a1798.png)

---

<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:** [12 December 2021 10:11 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/13 "2021-12-12T10:11:16Z")

</div>

if i use set instead of move and msg instead of flow then debug shows me unidentified value

---

<div class="post-metadata">

**Author:** ![mickym2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mickym2/32/36128_2.png) [@mickym2](https://discourse.nodered.org/u/mickym2)\
**Post date:** [12 December 2021 10:19 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/14 "2021-12-12T10:19:23Z")

</div>

I will modify my flow above - so you can add your plc Nodes directly instead - if the problem was only the missing topic.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b9709339c52d073573cebf7828d4c8e58702806d.png)

So you can see the whole object and then the result which comes out when you subtract t0-t1

```auto
[{"id":"2f12098b5d79577b","type":"join","z":"cb05e14b.326a9","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":530,"y":500,"wires":[["675f9b230d46ed95","4955a3635ee96cdd"]]},{"id":"5d30c0bd802ccec2","type":"debug","z":"cb05e14b.326a9","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":500,"wires":[]},{"id":"675f9b230d46ed95","type":"switch","z":"cb05e14b.326a9","name":"Difference < > 5","property":"payload.t1 - payload.t0","propertyType":"jsonata","rules":[{"t":"gt","v":"5","vt":"num"},{"t":"lt","v":"5","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":500,"wires":[["a00e3f8dc5d6738a"],["0e1560893c977356"]]},{"id":"a00e3f8dc5d6738a","type":"change","z":"cb05e14b.326a9","name":"= 1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":480,"wires":[["5d30c0bd802ccec2"]]},{"id":"0e1560893c977356","type":"change","z":"cb05e14b.326a9","name":"= 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":520,"wires":[["5d30c0bd802ccec2"]]},{"id":"f2386f5cae401760","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"142","payloadType":"num","x":190,"y":460,"wires":[["2a8b0803c56f0b58"]]},{"id":"57a19d7cabaee9a5","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"396","payloadType":"num","x":190,"y":520,"wires":[["9e7dd48c8a33fbff"]]},{"id":"2a8b0803c56f0b58","type":"change","z":"cb05e14b.326a9","name":"topic = t0","rules":[{"t":"set","p":"topic","pt":"msg","to":"t0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":460,"wires":[["2f12098b5d79577b"]]},{"id":"9e7dd48c8a33fbff","type":"change","z":"cb05e14b.326a9","name":"topic = t1","rules":[{"t":"set","p":"topic","pt":"msg","to":"t1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":520,"wires":[["2f12098b5d79577b"]]},{"id":"4955a3635ee96cdd","type":"debug","z":"cb05e14b.326a9","name":"object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":420,"wires":[]}]

```

If the output of the PLC Nodes are strings instead of numbers the use the change node to convert the payload in a number:

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/1/c15a1f3702b5646226197ef7af0bc2369f9ad74a.png)

add the conversion to both change nodes if necessary.

---

<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:** [13 December 2021 10:24 UTC](https://discourse.nodered.org/t/after-change-node-not-comparing-on-function-node/55070/15 "2021-12-13T10:24:48Z")

</div>

> [@mickym2](#):
>
> ```auto
> [{"id":"2f12098b5d79577b","type":"join","z":"cb05e14b.326a9","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":530,"y":500,"wires":[["675f9b230d46ed95","4955a3635ee96cdd"]]},{"id":"5d30c0bd802ccec2","type":"debug","z":"cb05e14b.326a9","name":"result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1000,"y":500,"wires":[]},{"id":"675f9b230d46ed95","type":"switch","z":"cb05e14b.326a9","name":"Difference < > 5","property":"payload.t1 - payload.t0","propertyType":"jsonata","rules":[{"t":"gt","v":"5","vt":"num"},{"t":"lt","v":"5","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":690,"y":500,"wires":[["a00e3f8dc5d6738a"],["0e1560893c977356"]]},{"id":"a00e3f8dc5d6738a","type":"change","z":"cb05e14b.326a9","name":"= 1","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":480,"wires":[["5d30c0bd802ccec2"]]},{"id":"0e1560893c977356","type":"change","z":"cb05e14b.326a9","name":"= 0","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":520,"wires":[["5d30c0bd802ccec2"]]},{"id":"f2386f5cae401760","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"142","payloadType":"num","x":190,"y":460,"wires":[["2a8b0803c56f0b58"]]},{"id":"57a19d7cabaee9a5","type":"inject","z":"cb05e14b.326a9","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"396","payloadType":"num","x":190,"y":520,"wires":[["9e7dd48c8a33fbff"]]},{"id":"2a8b0803c56f0b58","type":"change","z":"cb05e14b.326a9","name":"topic = t0","rules":[{"t":"set","p":"topic","pt":"msg","to":"t0","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":460,"wires":[["2f12098b5d79577b"]]},{"id":"9e7dd48c8a33fbff","type":"change","z":"cb05e14b.326a9","name":"topic = t1","rules":[{"t":"set","p":"topic","pt":"msg","to":"t1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":520,"wires":[["2f12098b5d79577b"]]},{"id":"4955a3635ee96cdd","type":"debug","z":"cb05e14b.326a9","name":"object","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":420,"wires":[]}]
> 
> ```

Thanks a lot, problem was on i have not selected the topic
