Dynamic inject node options...?

Hi all,
I'm currently using a inject node on a set time of day. This works well, but I would like to be able to change the time it triggers. I can store a revised time in the global context, but cannot work out how to get the inject node (Or any other) to pick up the time from the context.
Perhaps the inject node is not the right method, but something has to trigger the flow...
Maybe there is a simple option, but I'm stumped.. Any ideas?
TIA
image

I use this node for flexible scheduling:

There are many different scheduling and timing and CRON nodes. CRON+ for example is one of the most comprehensive and supports both dynamic and static schedules.

Ahh, I'll take a look. Do you know if it can take a context value?

Not sure, sorry. Probably depends what you want to do with that. You can always add an upstream change node to put a context variable onto the flow. I don't think there is any way to make that more dynamic but there are other ways to trigger a flow from a changed variable.

ERR! request to https://registry.npmjs.org/node-red-contrib-cron-plus failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
Oops... Guess I'll need to find another way.

It's effectively a wake up timer. I'm currently using an inject node with a time hard coded in. But there are times when that's not appropriate. I could just use an inject node triggering every 30 seconds against a variable stored in context (I can set that using another series of nodes from a dashboard).
It's a shame the set time in the inject node cannot reference a context rather than a fixed hard coded time...?

I did look at that, but I wanted to set the trigger time based on a value that can change (Selected in Home Assistant via an input_number entity) I can get that selected value into NR and into a global context slot as a variable, but can't think of an efficient way to get that to trigger the flow within NR, save for a repeating trigger loop and a switch node for example..

The beautiful thing about NR is the many ways of implementing something, just seems a shame that the inject node does not allow to reference the context store for the value. Perhaps in order to do so would be too many round trips to the CRON...?

Then you need node-red-contrib-cron-plus as @TotallyInformation suggested above.

Hi, it refused to install; see above..

EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error.

Your node-red device cannot access the internet. All attempts to install ANY node will fail without internet.

Thanks Steve. Got it working now. It was a minor blip in my local DNS arrangements :grin:
Now, I've got the node, but can't see a way to set the time of the trigger based on a time value stored within a Global context variable. Have I missed something?
Thanks

There are built in demos that show you how to create schedules dynamically.
CTRL-I :arrow_right: EXAMPLES :arrow_right: CRON-PLUS

There is also a demo here: Dynamic cron schedules / timers via dashboard control (flow) - Node-RED

And many examples and explanations on the forum too.

1 Like

Instead of saving it to context, send the time value (in the correct format) direct into the Cron+ node to establish a dynamic schedule.
You only need to inject it once (unless the value changes) because you can Persist dynamic schedules from within Cron+, so it will survive a reboot.

Take a look at this small example flow.

[{"id":"aafa7164b643c55a","type":"cronplus","z":"8ec88bd9c36c3f6b","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":405,"y":1230,"wires":[["8290dc3dcb28bac9"]]},{"id":"97a868827958c7c1","type":"inject","z":"8ec88bd9c36c3f6b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"add","payload":"{\"command\":\"add\",\"name\":\"Test\",\"topic\":\"Inject time\",\"expression\":\"2022-05-14 12:23 GMT+1\",\"payload\":\"GO\",\"type\":\"default\",\"limit\":0}","payloadType":"json","x":220,"y":1210,"wires":[["aafa7164b643c55a"]]},{"id":"8290dc3dcb28bac9","type":"debug","z":"8ec88bd9c36c3f6b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":565,"y":1230,"wires":[]},{"id":"961fe60ec377b464","type":"inject","z":"8ec88bd9c36c3f6b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"add","payload":"{\"command\":\"add\",\"name\":\"Test\",\"topic\":\"Inject time\",\"expression\":\"2022-05-14 20:25 GMT+1\",\"payload\":\"GO\",\"type\":\"default\",\"limit\":0}","payloadType":"json","x":220,"y":1250,"wires":[["aafa7164b643c55a"]]}]
2 Likes

Hi Paul,
Having taken a look at your example flow, I'm afraid it's just a bit too complicated for my level at the min. Thanks for taking the time to create it and post. Much appreciated. P

1 Like

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