Pick the last value

Created the Unique ID with the define range, i want to select the output of the last Unique value it showing (refer to upload://7NYXPYznBSQJUdje4hk0Sql6SN.png)


if (msg.payload.Pos1_op > 21.00 & msg.payload.Pos1_op < 21.50)
d = new Date,
dformat = [d.getMonth()+1,

dtstmp = new Date().toString();
pld1 = "L16POS1"+ dformat +""

msg.payload = pld1
return msg;

Flow Image:

Say the entire range is 0 to 5. You need to keep a history of values in some way to know which is unique. For example, array, the logic is...Each line is a new value and how it is processed or handled.

A = [ 0] first value, last unique is 0
A = [ 0,1 ] next, last unique 1
A = [ 0,1,2 ] next, last unique is 2
A = [ 0,1,2,3 ] next, last unique is 3

At this point they are all unique values right? So 0, then 1, then 2, then 3 are the result you want? As the last unique value, right?

With more values...

A = [ 0,1,2,3 ] next
A = [ 0,1,2,3,4 ] next
A = [ 0,1,2,3,4,5 ] next
A = [ 0,1,2,3,4,5,0 ] next

Now you start to narrow the unique value list? So the last unique value is 5?

So I would say the last unique value is always the last value added to the array, unless, there is already a match in the array? Also if you find a match, you need to remove that value from the array so it can become unique again...

A = [ 0,1,2,3,4,5,0 ] remove 0, A = [ 1,2,3,4,5 ] next, last unique is 5
A = [ 1,2,3,4,5,0 ] next, now unique last unique is 0

Have I stated the logic correctly? There are other ways to keep the history, but the above is one easy way to do it. You could also keep an array of counters and increment the count for each match in the stream of values, and the lowest count is always the last unique unique value. But I think the above example is easier to understand and validate.

i'm newbee.
So i need to write another function that state this?
can you please give me more clue or example of function ?

If you want the value L16POS119262020173530 ?

It is in msg.payload

See this https://nodered.org/docs/user-guide/messages to help you understand how to get values from a msg.

And as a newbee - i cannot recommend strongly enough - watch this playlist: Node-RED Essentials. It is by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in less than an hour. A small investment for a lot of gain.

The first step of learning is try. The second step is to struggle with it. Most learning comes from effort. I don't say this to be flippant but to illustrate how I have learned. Of course we will help, nudge you in the right direction, but will not just give you the solution. I am sure you can understand how we encourage effort first.

Once you learn how to deal with messages and the data in them, then I suggest you read about arrays in javascript. Say https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
for example.