# Setting environment variable to time in trigger node

**URL:** <https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038>\
**Category:** General\
**Created:** [5 July 2021 08:44 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038 "2021-07-05T08:44:24Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![OmkarNodered](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@OmkarNodered](https://discourse.nodered.org/u/OmkarNodered)\
**Post date:** [5 July 2021 08:44 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/1 "2021-07-05T08:44:24Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 July 2021 08:48 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/2 "2021-07-05T08:48:28Z")

</div>

`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)

---

<div class="post-metadata">

**Author:** ![OmkarNodered](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@OmkarNodered](https://discourse.nodered.org/u/OmkarNodered)\
**Post date:** [5 July 2021 08:52 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/3 "2021-07-05T08:52:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![OmkarNodered](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@OmkarNodered](https://discourse.nodered.org/u/OmkarNodered)\
**Post date:** [5 July 2021 08:54 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/4 "2021-07-05T08:54:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 July 2021 08:54 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/5 "2021-07-05T08:54:41Z")

</div>

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`)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 July 2021 08:58 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/6 "2021-07-05T08:58:56Z")

</div>

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

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![OmkarNodered](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@OmkarNodered](https://discourse.nodered.org/u/OmkarNodered)\
**Post date:** [5 July 2021 09:40 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/7 "2021-07-05T09:40:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [5 July 2021 12:56 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/8 "2021-07-05T12:56:55Z")

</div>

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+

---

<div class="post-metadata">

**Author:** ![OmkarNodered](https://avatars.discourse-cdn.com/v4/letter/o/90ced4/32.png) [@OmkarNodered](https://discourse.nodered.org/u/OmkarNodered)\
**Post date:** [6 July 2021 06:54 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/9 "2021-07-06T06:54:21Z")

</div>

@Trying_to_learn and @TotallyInformation thanks for the help..

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [4 September 2021 06:54 UTC](https://discourse.nodered.org/t/setting-environment-variable-to-time-in-trigger-node/48038/10 "2021-09-04T06:54:39Z")

</div>

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