Using JINA2 substitutions in Node-Red Nodes?

How does one use JINJA2 replacements in Node-Red nodes? (and can it be done?)
e.g. the looptimer node is expecting a number in the loop every field (see screenshot)

But instead of that number, I want to use a variable or an attribute of the message
How would one code it?
I have searched the documentation but I could not find an answer.
I tried single and double braces, global.get and $ etc, etc.
thanks so much,

You almost never need JINJA templates with node-red. if you use a trigger node or current state, whatever variable you need can be extracted from the message object, for example msg.payload or

That being said, unfortunately you can’t change the loop timer for that node programmatically. That’s a limitation of than node. Maybe you can find another looptimer node that is capable of doing it. or alternatively, a function node.

1 Like

thank you @serkank
I was hoping that Jinja2-replacement would happen before the data is processed by the node and the node would never see the “variable”. But I’m not a programmer.

Function node with a delay:
I also tried the other path that you suggest; using a function node to make a delay. There I get stuck on the way “sleep” is handled in JavaScript. It is my understanding that there is no such thing as “sleep” in JS. And the timeout is asynchronous.
I tried :

setTimeout(() => {  return msg;  }, 2000);

but that didn’t work. Anyone any tips on why ?

I want to achieve the following:
first hit= delay 2sec, second hit = delay 4 sec, then 8, then 16, then 32, then 1 minute,…

If I were only smarter, :innocent:


wait wait wait…
Replacing return msg; by node.send(msg); as indicated in the discourse link by @serkank seems to work :slight_smile:

setTimeout(() => { node.send(msg)  }, 20000);

The above waits 20 seconds before continuing
Note to self: READ before WRITE chrisV…
Exploring this further but looking very promising so far

glad to be help… I guess… :slight_smile:

here is another idea, after explained what you want to achieve. delay node can help here. it looks ugly but no need a function node.

1 Like

Hi @serkank
I was not aware there was a delay node
And…JSONata expressions… that is something I need to explore
awesome information
Learning exiting new things here :slight_smile:
thank you for sharing