Trigger at specific date-time

I feel like this is really easy and I am just missing it.

I want to provide a datetime as an input and wait in a flow until that time occurs.

Everything I look at appears to only want a brief interval or a time of day and it fires the next time. I want to provide an actual datetime, with a date portion. Inject is like cron, repeats on day of week, I want date.

Have I just not found the right node? Or not calling one correctly?

Basically "Wait until 2019-07-15 23:12" or whatever format it wants for time.


Thanks, Linwood

PS. I can simulate this with a complicated loop that waits, say, 12 hours at a time until the remaining time is under 12 hours, then waits that long. But that's ugly.

Inject that outputs a timestamp as seconds since epoch, and a function node that checks if the timestamp is greater than/equals to the specified data and if not drops the message, then drops all messages after passing through the message at the correct time? Doesn't sound like a very clean solution to me, but I guess it should work.

You could use the node-red-contrib--cron-pkjq node to trigger at specific dates.

@afelix, yes, I can loop and check and loop and check. Hoping for elegant.

@bakman2 I need to feed the date-time as an input to the node, and this node does not appear to permit anything but hard-coded info.

Thanks both.

I cannot find any node that handles actual date scheduling.

What you could try is the node-red-contrib-moment (for date/time formatting) and use an inject node with interval (eg. every 30 secs) into that node. And add another node inject node for your date/time schedule (possibly best to set flow variables) and compare if the date/time matches, if yes, trigger whatever you like.

If you don't mind needing Internet connectivity, you could always use Google Calendar.


A relatively easy way is to do some simple maths

Lets say i want to set something to go off tomorrow at 7AM

I would get the time and date as at now, then using one of the other nodes (such as moment) perform maths to see how far away that time is when i want the alarm (in minutes) - i would then feed that to the mytimeout node by Neil Chery - essentially you can feed this timeout node the amount of time you want it to wait (not sure of the maximum) and it will at the end of the time send out something for you - you could just take this output through the switch node - and essentially invert it - i.e.mytimeout is counting down - when it finishes counting down it will send an off/finish - you take this into the switch node and test what it is getting as input and then act on that


Here's what I ended up doing.

I have the "until" time stored in a flow context variable.

In a function node I grab it and check if it is expired, and if so exit to output 1 (expired).

If not, I compare the date portion (only) with today, and if not the same (i.e. until is later) I emit from output 2 a "00:00" for midnight, and fall into the schedex node (which I'm using elsewhere also).

If on the other hand the until is the same date, I emit the time portion in output 2 the same way.

Then I loop back to the same node from the schedex output.

The result is that the timer fires once a day at midnight, until the last day, it fires on the until time.

Finally on the output 1 path I feed back to schedex a blank on/off time, which cancels any timer still running.

It is a bit messy but it seems easiest, most of the code is just pulling apart javascript date/times and formatting them.

It occurs to me I might be able to just do all this in a function node with settimeout, but was not at all sure how such a timeout would work with node-red's structure.

Sounds like a pretty clean solution to me, from a logic point of view that is. Nice job!