Compare Numbers

Hi there,

i am new to Node Red and most of programming.
Searching Google and the forum didn't help me at all, almost because english is not my native language and i dont understand most of the subjects.

My very little understanding of programming is more like boolean algebra used in PLC controllers some time ago.

i dont understand how nodes interact with other nodes. On every "wiring point" i can combine as many nodes as i wish, but how do they interact?

i have two nodes that have numbers in form of "19.5" or "23".
if Number A is higher than B, i want to get a boolean TRUE.
if this TRUE is valid more than time X, then use GPIO Pin on the Raspberry.

hope you can give me some tipps.

Nodered is flow based. This basically means that you have a message that comes from an inject or some other input like an mqtt subscription or where ever your sensordata comes from. (It can also be time based as there is nodes which send messages at certain intervals or certain times).
This message gets passed through the flow along the wires from left to right and each node it passes can access the information in the message and react to it or change it. So get familiar on how to work with them
https://nodered.org/docs/user-guide/messages
So lets break it down.
You want to work with to messages from two sources. Each message contains a value you’re interested in comparing to the other. Fortunately the documentation of nodered is quite good.
So i would recommend you start by looking at how to work with messages and their properties:
https://cookbook.nodered.org/basic/set-message-property-fixed
than take this new knowledge and apply it to
https://cookbook.nodered.org/basic/join-streams
Once you succeed in having both temperatures in one message object you can look further on how to compare them
https://cookbook.nodered.org/basic/route-on-property
I hope this gives you some pointers on how to start and basic concepts. Once you have mastered those come back here and Im happy to help you with the rest.

Johannes

1 Like

i was just reading this user guide.
i think, i figured it out.

one timer, triggers both temperatures,
both temperatures "join" as an array in payload[0] and [1]
"switch" compares payload[0] higher than [1]. if true gives the array
to "change", which turns the array to an boolean true
"trigger" keeps the true alive, till the timer runs it again.

two things left:
what node can i use, to add an "offset" to the temperature?
i want to keep the true message, false until true is active for a time/cycles

Usually it is better to use key/value join (as suggested in the cookbook link posted earlier) rather than array. Then you use names to identify rather than having to rely on the position in the array, which is very difficult to guarantee.

Adding an offset can be done in a function node very easily. If it is in the payload then this will offset it by 1.5

msg.payload = msg.payload + 1.5
return msg

Or I imagine a Change node can be used but I would have to experiment to determine exactly how to do that. Or a Range node could do it.

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