# Help needed with comparing inputs using msg.topic

**URL:** <https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258>\
**Category:** General\
**Created:** [15 October 2021 10:42 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258 "2021-10-15T10:42:32Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![KrishnanRavichandran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnanravichandran/32/44858_2.png) [@KrishnanRavichandran](https://discourse.nodered.org/u/KrishnanRavichandran)\
**Post date:** [15 October 2021 10:42 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/1 "2021-10-15T10:42:32Z")

</div>

I have a system where there are 8 inlet pressure measurements from 8 different channels. In my system, I am trying to maintain the pressure in a range using hysteresis.

Here, I want the compressor to switch on even if one of 8 pressure measurement drop below a certain value (say 0.2 bar). But, I tried to connect the one output to the compressor from each input. Then realized that multiple inputs from my 8 channels are to be in a OR function to run the compressor even if one of the pressure channels are below pressure.

How can I separate the hysteresis output from each of the 8 channels to get an output turn on even if one of the pressure falls below?

I tried using msg.topic but I am making some mistake as I couldn't compare the topics.

**8 channels read pressure - 8 hysteresis loops for each channel - write the output (switch on) the compressor even when one value is below set point.**

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [15 October 2021 10:59 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/2 "2021-10-15T10:59:42Z")

</div>

I assume you receive 8 different messages, node-red handles a single message at a time, you can combine the messages using a join node. Or [use context](https://nodered.org/docs/user-guide/writing-functions#getset-multiple-values) to keep track of all values and compare.

---

<div class="post-metadata">

**Author:** ![KrishnanRavichandran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnanravichandran/32/44858_2.png) [@KrishnanRavichandran](https://discourse.nodered.org/u/KrishnanRavichandran)\
**Post date:** [15 October 2021 11:42 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/3 "2021-10-15T11:42:27Z")

</div>

I used global context to assign the output to a varuiable and used it for control. Thank you.

But when I use join node to form an array of the 8 inputs, how can I check if at least one of the input is 1 or ON??

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [15 October 2021 12:11 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/4 "2021-10-15T12:11:06Z")

</div>

Don't use array mode on the join node, use key/value mode. Then it's a simple case of logic in a function node.

There’s a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

![BX00Cy7yHi](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [15 October 2021 19:31 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/5 "2021-10-15T19:31:52Z")

</div>

If you already have the 8 channels and 8 hysteresis nodes set to provide a 1 if they need to be switched on then you don't need anything fancy, as any node outputting a 1 should be aa signal to act - not matter where it comes from... so just wire all of them into a node that just looks for a 1... or am I missing something ?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 October 2021 10:38 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/6 "2021-10-16T10:38:03Z")

</div>

> [@dceejay](#):
>
> am I missing something ?

Possibly there needs to be a way of getting back to zero again when none of the inputs is on.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [16 October 2021 11:02 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/7 "2021-10-16T11:02:25Z")

</div>

Presumably you would run for a timeout. You wouldn’t want to oscillate a compressor on/off around a set point

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 October 2021 12:39 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/8 "2021-10-16T12:39:19Z")

</div>

> [@dceejay](#):
>
> You wouldn’t want to oscillate a compressor on/off around a set point

Hence the hysteresis nodes.

---

<div class="post-metadata">

**Author:** ![KrishnanRavichandran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnanravichandran/32/44858_2.png) [@KrishnanRavichandran](https://discourse.nodered.org/u/KrishnanRavichandran)\
**Post date:** [16 October 2021 13:55 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/9 "2021-10-16T13:55:06Z")

</div>

Ithank you very much for the replies. Though I found a method, I happen to have better understand on how to improve it.

I thought having multiple inputs to one node to switch on the compressor might have contradicting signal. When I instead of having one particular output node, had 8 separate nodes that pointed to my compressor, it got on for one second or so and switched off later.

This is something that can be avoided if I have one compressor node and 8 inputs going to it (instead of 8 comp, and 8 nodes)?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [16 October 2021 14:30 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/10 "2021-10-16T14:30:26Z")

</div>

I don't understand what you mean. Can you post the flow for what you have so far please so that I can better understand? So from the pressure inputs through to the compressor output. See this post for how to post your flow - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![KrishnanRavichandran](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krishnanravichandran/32/44858_2.png) [@KrishnanRavichandran](https://discourse.nodered.org/u/KrishnanRavichandran)\
**Post date:** [10 November 2021 09:50 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/11 "2021-11-10T09:50:30Z")

</div>

I could not reply to you as I had met with an accident and was not able to work!

Thank you for answering anyways and I found that my flow had an issue may be due to the node red version of it (v0.17.5).

Multiple inputs with opposite values for eg: 0 and 1 are the inputs to the particular node with operates the blower in my system. But, when varying inputs are given, the blower shuts off after starting for a second or so. So, I used a function with OR statement to give me an output of either 0 or 1.

```auto
[{"id":"79df6e65.866f","type":"function","z":"eda27e78.828a9","name":"OR from Inputs","func":"var A71 = global.get('A71');\n\nvar A72 = global.get('A72');\n\nvar A73 = global.get('A73');\n\nvar A50 = global.get('A50');\n\nvar A51 = global.get('A51');\n\nvar A30 = global.get('A30');\n\nvar A31 = global.get('A31');\n\nvar A32 = global.get('A32');\n\nif (A71 == 1 || A72 == 1 || A73 == 1 || A51 == 1 || A50 == 1 || A30 == 1 || A31 == 1 || A32 == 1 ){\n msg.payload=1;\n}\nreturn msg;","outputs":1,"noerr":0,"x":470.00006103515625,"y":2744.5002641677856,"wires":[["6af1ce00.8678e4"]]}]

```

---

<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:** [9 January 2022 09:50 UTC](https://discourse.nodered.org/t/help-needed-with-comparing-inputs-using-msg-topic/52258/12 "2022-01-09T09:50:50Z")

</div>

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