# Comparison of msg.payloads from the dashboard

**URL:** <https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854>\
**Category:** General\
**Created:** [18 May 2020 14:41 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854 "2020-05-18T14:41:01Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Joaovitor](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joaovitor](https://discourse.nodered.org/u/Joaovitor)\
**Post date:** [18 May 2020 14:41 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/1 "2020-05-18T14:41:01Z")

</div>

I am developing an app for Iot from node red.  
In this app I need to compare a sensor value with maximum and minimum limits defined from the dashboard.

It would have to work as follows: on the dashboard I would define the maximum and minimum values ​​of a sensor with a numerical node or something like that.

Example: maximum temperature: 30 ° C

minimum temperature: 10 ° C

The idea is to compare the input value of the sensor with the maximum and minimum values ​​defined in the dashboard.  
If, using the previous example, the temperature is above 30 ° C and below 10 ° C a notification is sent.

I tried to use function-type nodes but he is unable to "store" the values ​​that are on the dashboard.

Would there be any way to do what I want? Is there a node that performs the operation in a simple way?

Thanks for the help.

---

<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:** [18 May 2020 14:57 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/2 "2020-05-18T14:57:28Z")

</div>

You can use a ui\_form or ui\_text+ui\_button to enter values.

Either way, use a change function to set flow.min and flow.max

example...  
flow1 ui\_text --\> change node (set flow.max to msg.payload)  
flow2 ui\_text --\> change node (set flow.min to msg.payload)  
flow3 sensor input --\> function node --\> notification

the function would be something like...

```auto
const absMax = 99; //hard coded safe guard
const absMin = 10; //hard coded safe guard
msg.max = flow.get("min") || absMax;
msg.min = flow.get("max") || absMin;
msg.inputValue = msg.payload; //keep a record of original payload - good for debugging!

if(msg.inputValue >= msg.max){
  msg.payload = "Too high";
else if(msg.inputValue < msg.min){
  msg.payload = "Too low";
} else {
  return null; //dont fire function node output!
}
return msg;

```

---

<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:** [18 May 2020 15:01 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/3 "2020-05-18T15:01:27Z")

</div>

Alternatively you can use a Join node to combine the values into one message (that is my preferred solution, but others prefer using the context). See [this example from the cookbook](https://cookbook.nodered.org/basic/join-streams) for how that can be done.

---

<div class="post-metadata">

**Author:** ![Joaovitor](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joaovitor](https://discourse.nodered.org/u/Joaovitor)\
**Post date:** [18 May 2020 17:17 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/4 "2020-05-18T17:17:27Z")

</div>

I still have problems.

It seems that when it sends the values ​​to the node it does not store in the constants. it is as if the reference value were the values ​​set in the function (10 and 99). They don't update. Only something above 99 and below 10 is returned, it does not take into account what I mentioned in the dashboard.

The nodes are not configured correctly.

I am a beginner, if possible I would not have a more detailed example of the step by step, such as the ui\_text configuration?

---

<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:** [18 May 2020 17:50 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/5 "2020-05-18T17:50:15Z")

</div>

Export you flow Select nodes, press CTRL+E, copy then ...

`````  
` paste between backticks like this`  
`````

and I'll see whats wrong.

A screenshot would be good too (you can copy + paste an image straight into the reply on this forum)

---

<div class="post-metadata">

**Author:** ![Joaovitor](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joaovitor](https://discourse.nodered.org/u/Joaovitor)\
**Post date:** [18 May 2020 18:11 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/6 "2020-05-18T18:11:44Z")

</div>

here is the flow:

`[{"id":"6df7d1a7.4cd9c","type":"function","z":"cfbb6e4f.6526a","name":"","func":"const absMax = 99; //hard coded safe guard\nconst absMin = 10; //hard coded safe guard\nmsg.max = flow.get(\"min\") || absMax;\nmsg.min = flow.get(\"max\") || absMin;\nmsg.inputValue = msg.payload; //keep a record of original payload - good for debugging!\n\nif(msg.inputValue >= msg.max){\n msg.payload = \"Too high\";}\nelse if(msg.inputValue < msg.min){\n msg.payload = \"Too low\";\n} else {\n return null; //dont fire function node output!\n}\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":500,"wires":[["6dabc296.3525bc"]]},{"id":"6dabc296.3525bc","type":"debug","z":"cfbb6e4f.6526a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":670,"y":500,"wires":[]},{"id":"e93936eb.80cb48","type":"inject","z":"cfbb6e4f.6526a","name":"","topic":"inputValue","payload":"5","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":440,"wires":[["6df7d1a7.4cd9c"]]},{"id":"5b1d03a.6b0fafc","type":"inject","z":"cfbb6e4f.6526a","name":"","topic":"inputValue","payload":"50","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":270,"y":560,"wires":[["6df7d1a7.4cd9c"]]},{"id":"1e758b47.efc845","type":"ui_form","z":"cfbb6e4f.6526a","name":"","label":"","group":"91cc4ff3.10673","order":2,"width":0,"height":0,"options":[{"label":"Maximum","value":"flow.max","type":"text","required":true,"rows":null},{"label":"Minimum","value":"flow.min","type":"text","required":false,"rows":null}],"formValue":{"flow.max":"","flow.min":""},"payload":"","submit":"submit","cancel":"cancel","topic":"","x":250,"y":500,"wires":[["6df7d1a7.4cd9c"]]},{"id":"91cc4ff3.10673","type":"ui_group","z":"","name":"Botão Relé 1","tab":"8f89f7a7.c74cf8","disp":true,"width":"6","collapse":false},{"id":"8f89f7a7.c74cf8","type":"ui_tab","z":"","name":"Relés","icon":"dashboard","disabled":false,"hidden":false}]`

---

<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:** [18 May 2020 20:02 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/7 "2020-05-18T20:02:04Z")

</div>

The structure you have shown is what you would do if you were using a Join node to join all the messages before testing in a function node. Using the flow context you should not feed the form into the function node but instead into a Change node that sets the flow variables.

---

<div class="post-metadata">

**Author:** ![Joaovitor](https://avatars.discourse-cdn.com/v4/letter/j/3ab097/32.png) [@Joaovitor](https://discourse.nodered.org/u/Joaovitor)\
**Post date:** [18 May 2020 22:44 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/8 "2020-05-18T22:44:28Z")

</div>

I managed to use the join node with an entry corresponding to the maximum (msg.max), one corresponding to the minimum (msg.min) and one corresponding to the sensor value. Right after a function node comparing the variables. If the temperatures are higher or lower than those defined, a notification is returned. Otherwise, the return is null.

Everything is working as desired. I thank everyone who helped.

the flow is attached. I intend to replace the inject with a mqtt\_in node and debug for the notification.  
`[{"id":"97c9094b.030858","type":"debug","z":"cfbb6e4f.6526a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":690,"y":640,"wires":[]},{"id":"35d180ea.771eb","type":"function","z":"cfbb6e4f.6526a","name":"","func":"const a = msg.payload.max;\nconst b = msg.payload.min;\n\nif(msg.payload.inputValue > a){\n msg.payload = \"Too high\";}\nelse if(msg.payload.inputValue < b){\n msg.payload = \"Too low\";\n} else {\n return null; //dont fire function node output!\n}\nreturn msg;","outputs":1,"noerr":0,"x":510,"y":640,"wires":[["97c9094b.030858"]]},{"id":"531e311f.2b648","type":"join","z":"cfbb6e4f.6526a","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":true,"timeout":"","count":"1","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":350,"y":640,"wires":[["35d180ea.771eb"]]},{"id":"4e185f5e.96629","type":"inject","z":"cfbb6e4f.6526a","name":"temperature","topic":"inputValue","payload":"8","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":700,"wires":[["531e311f.2b648"]]},{"id":"940181a8.f2327","type":"ui_numeric","z":"cfbb6e4f.6526a","name":"","label":"maximum","tooltip":"","group":"91cc4ff3.10673","order":2,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"max","format":"{{value}}","min":0,"max":10,"step":1,"x":140,"y":580,"wires":[["531e311f.2b648"]]},{"id":"2fff4a91.ac2376","type":"ui_numeric","z":"cfbb6e4f.6526a","name":"","label":"minimum","tooltip":"","group":"91cc4ff3.10673","order":3,"width":0,"height":0,"wrap":false,"passthru":true,"topic":"min","format":"{{value}}","min":0,"max":10,"step":1,"x":140,"y":640,"wires":[["531e311f.2b648"]]},{"id":"91cc4ff3.10673","type":"ui_group","z":"","name":"Botão Relé 1","tab":"8f89f7a7.c74cf8","disp":true,"width":"6","collapse":false},{"id":"8f89f7a7.c74cf8","type":"ui_tab","z":"","name":"Relés","icon":"dashboard","disabled":false,"hidden":false}]`

---

<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:** [1 June 2020 22:44 UTC](https://discourse.nodered.org/t/comparison-of-msg-payloads-from-the-dashboard/26854/9 "2020-06-01T22:44:31Z")

</div>

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