Comparing a string

Hi

I want to compare the variable I with an other number in string form. But it doesn't work
Where is my fault?

What is the problem you are seeing? If it is always 1 at the end then that is because you set I to 1, test it for 1 and set it to 2. Then you test it for 2 (which it now is) and set it to 3. Then you test it for 3 (which it now is) and set it back to 1 again.

Perhaps you meant to use else on the later tests

Yes, I have it already

But I want that the part I == 2 start on a second pulse of the timestamp. So on the first pulse, the first if loop en on the second pulse the second if loop.
Now if I try it he does all the loops in one time

image

So you essentially want a payload of "1" then "2" then "3" and then back to "1" every time it runs - is that correct?

If YES, then what you must realise is that every time a function runs, it does exactly what you tell it to. You tell I to be "1" at the start of the function. You need to store the value of I somewhere at the end of the function then retrieve I at the beginning. To achieve this, you can use context.set and context.get See the docs for context: Working with context : Node-RED

Is it possible to say: if I == 2 and Array[0][1] contains a value?

So I will try to say what I am trying.
I read every 5 minutes a value, but after 10 minutes (or 2 values) I need to calculate how much power I can use in the last 5 minutes.
How can I do that?

Do you know the formula you are trying to evaluate?

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