Setting environment variable to time in trigger node

Hello, I want to set environment variable to the time in the trigger node and also to set interval at a inject node Is this possible to set env variable to both the nodes?

trigger nodes can have their delay value set with msg.delay.

But I don't get what you want to do.

You could control the time in the trigger node from an environment variable.
But I think it is called context not environment. (Shrug)

I think environment is fixed.

But what do I know. (Shrug)

Thanks..for reply
But What I want is I have a simple flow which is inserting timestamp into database. I want to make this flow to be run at specific interval like for every 10 sec or 20 sec. So, to make the flow dynamic I will set environment variable to 20 sec in the settings.js file and I want to use that variable in my flow as I am using trigger node for repeated cycle.

I have set the option in trigger node as 'resend it every '

Ok, so you get a heap of inject nodes which inject different values (times) for the delays.

They then go into the trigger node setting the delay time. (msg.delay)

This is a BASIC idea of what I think you want.

[{"id":"873bb9c1.818218","type":"inject","z":"fc6fbf47.86d3e8","name":"","props":[{"p":"delay","v":"2000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":1450,"wires":[["57b4b1df.2f1e08"]]},{"id":"593115ec.167d9c","type":"inject","z":"fc6fbf47.86d3e8","name":"","props":[{"p":"delay","v":"6000","vt":"num"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":1510,"wires":[["57b4b1df.2f1e08"]]},{"id":"c05aef67.cdc82","type":"debug","z":"fc6fbf47.86d3e8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":1480,"wires":[]},{"id":"57b4b1df.2f1e08","type":"trigger","z":"fc6fbf47.86d3e8","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":440,"y":1480,"wires":[["c05aef67.cdc82"]]},{"id":"15ea4e57.00f012","type":"inject","z":"fc6fbf47.86d3e8","name":"STOP","props":[{"p":"reset","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":210,"y":1400,"wires":[["57b4b1df.2f1e08"]]}]

Change the values in the inject nodes to the values you want. One sets 2 second delay the other sets 6 second delay.

I included the STOP button only to stop the flow when you are thinking.

Thanks for the help.. I have set environment variable to msg.delay in inject node and its working..

For reference, an "environment variable" is something that the operating system controls. When Node-RED starts, its environment is set and therefore changing environment variables while Node-RED is running is unlikely to be effective.

A context variable is something that Node-RED controls. Sometimes you will see global and flow variables mentioned and these are context variables with a wider context!

As Andrew has said, you can use the inject node to kick things off at set times or intervals. If the inject node does not provide sufficient control. There are lots of other scheduling nodes available as well such as BigTimer and CRON+

@Trying_to_learn and @TotallyInformation thanks for the help..

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