Using Inject node to trigger a flow as a cron job (specific time interval)

2,646 views
Skip to first unread message

Greg EVA

unread,
May 29, 2015, 11:28:53 AM5/29/15
to node...@googlegroups.com
Hello Internet,

I am looking to do some stuff with some values that I've stuffed into the global context... and I'd like this all to happen on a very fixed and strict schedule (like every 5 minutes, or once a day as the clock strikes midnight, as the bell tolls, etc.)

I am using the Inject node to do this, and it references that this will be done using cron.  Super.. I like cron.  However for my needs, 1) there seem to be some missing cron configuration options, and 2) I'm not sure that I can properly select "all the time".

1) In cron speak, you have the "at" part, and the "on" part.  So for example you'd say '0/5' for minutes, would mean that the thing would happen at 0 minutes, and then every 5 minutes after that.  In the Inject node, I only see the "Interval between times", but no "when to initially trigger".

2) Using the 0/5, at :00, :05, :10, :15, ... example... I want this to happen all day, every day.  Normally in cron, you just put a star for the hours, but here I need to select a start and end time.  So I choose 00:00 to 00:00, however it doesn't like this, so it changes it to 00:00 to 01:00... obviously only being for one hour.  If I put 00:00 to 23:00, I'm afraid that it will not trigger between 23:00 and 24:00.

Here is a screenshot with a fabulously drawn yellow rectangle around the section in question.
https://dl.dropboxusercontent.com/u/79298132/NodeRED_Inject_IntervalBetweenTimes1.png

I tried using the "at a specific time" mode for the node, however then I don't have the option for the repetition.

Any thoughts on how I might accomplish what I'm trying to do here, or just write the cron expression out entirely myself?

Happy cocktail hour ( I say that out of envy as I rush off to look after a couple of 2 year olds)

Greg

Nicholas O'Leary

unread,
May 29, 2015, 11:40:45 AM5/29/15
to Node-RED Mailing LIst
HI Greg,

trying to provide a human-usable interface to everything that cron can do is hard. What we have satisfies most scenarios at the sacrifice of some cron capability. So it is always useful to hear of specific cron capabilities that people want to use that we don't currently expose.

If you want something to happen all day, every day, you can select the "interval" option and not worry about specifying a time/day range. That doesn't use cron under the covers - just a simple timer.

It does look like there's a small bug with when you select between 0:00 and 0:00. If you look at the info side bar (after closing the edit dialog), you can see the node properties show the generate cron string is */5 0-23 * * * - which I think is what you want. If you reopen the dialog, it is incorrectly parsing the cron string and setting it to 0 - 1. Will fix that shortly.

As for specifying the 'on' part... that you cannot do currently. Will see if there's a way of doing so that doesn't overload the UI too much.

Nick

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dave C-J

unread,
May 29, 2015, 12:13:08 PM5/29/15
to node...@googlegroups.com
What is wrong with the (non-cron) interval option set to every 5 minutes ? Will do it all day every day...  ?
The at a specific time option will do the once a day at midnight...
(yes acknowledge there is a parsing bug). - must admit I thought 0-23 does mean all the hours including 23, not up to... maybe it means including 23.00 but not 23.05 ?

One of our users, Peter Scargill, also created a scheduler node - https://github.com/scargill/scheduler which was more about turning things on and off - but had things like sunrise/sunset built in

And then another, Dean-o, did a "later" node - https://www.npmjs.com/package/node-red-contrib-later which parses english like sentences to  make a cron job....

Julian Knight

unread,
May 29, 2015, 3:49:49 PM5/29/15
to node...@googlegroups.com
In addition to Nick and Dave's suggestions, there are some "contrib" nodes that might give you additional control if you decide you need it.


On Friday, 29 May 2015 16:28:53 UTC+1, Greg EVA wrote:
Hello Internet,

I am looking to do some stuff with some values that I've stuffed into the global context... and I'd like this all to happen on a very fixed and strict schedule (like every 5 minutes, or once a day as the clock strikes midnight, as the bell tolls, etc.)
...

Nicholas O'Leary

unread,
May 29, 2015, 4:14:45 PM5/29/15
to Node-RED Mailing LIst
Dave,

in cron, 0-23 does mean all the hours including 23. But, that's cron.

Our node's UI is trying to hide the complexity of cron and present a usable interface. Saying 'repeat between 0:00 and 23:00 means between those hours, so translates to 0-22 in cron syntax.

N

--

Dave C-J

unread,
May 29, 2015, 4:34:46 PM5/29/15
to node...@googlegroups.com
Nick,

yes .... and if you enter 00:00  to 00:00 from the select box we initially do the right thing... the property gets set to 
*/5 0-23 * * *
It's just the re-parse when we re-open that's borked.

Nicholas O'Leary

unread,
May 29, 2015, 4:35:56 PM5/29/15
to Node-RED Mailing LIst
yes - I ack'd that in my original reply ;)

--

Dave C-J

unread,
May 29, 2015, 4:42:13 PM5/29/15
to node...@googlegroups.com
not sure what line 340 is trying to achieve...
   end = (Number(hours[1])+1)%24;

Nicholas O'Leary

unread,
May 29, 2015, 5:35:13 PM5/29/15
to Node-RED Mailing LIst
FYI - fix for 0-0 selection just pushed to git.

On 29 May 2015 at 21:42, Dave C-J <dce...@gmail.com> wrote:
not sure what line 340 is trying to achieve...
   end = (Number(hours[1])+1)%24;

--

Greg EVA

unread,
Jun 1, 2015, 4:24:58 AM6/1/15
to node...@googlegroups.com
Hi guys, first, thanks for you quick replies.

@Nick - I understand that its tough to render this stuff human readable and concise and that limits need to be established.  That being said, cron is a good example of something that is extremely powerful, flexible, and simple ; despite the learning curve to figure out the appropriate scheduling syntax.  For this reason, what about adding an "Advanced" section for the node which allows you to simply write your own cron entry?  I didn't see that the cron entry was rendered in the Info panel... thanks for that little goody!

@Dave - Thanks for those additional options.  I had a look, and seems to be some relevant stuff there.

@Julian - Thanks... I had a quick scan of the contrib nodes, but think that I will just start with the "every 5 minutes" option as a matter of time and focus.

In case the requirement here isn't clear, it is really important to reliably record a meters reading at a specific time, and regularly.  Ever hour needs to be say at 13:00:00 and then 14:00:00.  Every hour without a start time would not be able to provide say hourly consumptions.  Any drift by a second or so would also accumulate over time and certain windows could then be say 59 mintues, or 61 minutes.  Specifying the trigger time helps keep the interval window in check, as well as ensuring that the data will fall on appropriate boundaries.  Imagine a SQL statement selecting data between a time range.... say WHERE timestamp >= "2015-30-05 00:00:00" AND timestamp < "2015-01-06 00:00:00".  Being one second off would mean that data from one day would fall into the other day, or not be taken into account in the selection (< 00:00:00 does not catch 00:00:01).

For the time being... I'm going to just deal with this... :-P

Cheers,

Dave C-J

unread,
Jun 1, 2015, 6:23:35 AM6/1/15
to node...@googlegroups.com
Hopefully the 00:00 - 00:00 fix should now allow what you want anyway, without exposing the complexities of cron - fingers crossed...



Greg EVA

unread,
Jun 1, 2015, 6:28:33 AM6/1/15
to node...@googlegroups.com
Unless I misunderstood something, there is no way to currently employ the "at" part of the cron implementation; so no it will not work.

Dave C-J

unread,
Jun 1, 2015, 6:45:53 AM6/1/15
to node...@googlegroups.com
The interval between times option (which uses cron) now lets you set "every 5 minutes between 00:00 and 00:00"
which I thought was your use case... (rather than just the "interval - every 5 mins" option.)

Inline images 1

Greg EVA

unread,
Jun 2, 2015, 5:20:11 AM6/2/15
to node...@googlegroups.com
Hi Dave,

I'm sorry but I don't think I can be much clearer in what I am trying to do.  I have tried to express it already in many various ways throughout the thread.

What you are describing does not specify when something will happen... it specifies the interval between the events and the window... not the execution time.

Regards,

Greg

Dean Sellers

unread,
Jun 2, 2015, 6:20:41 AM6/2/15
to node...@googlegroups.com
Thanks for the mention of my later node :)

I think that both the interval/cron or the later node would solve your problem, unless I don't understand it properly.

What is your use case, maybe an example flow.

Nicholas O'Leary

unread,
Jun 2, 2015, 6:32:34 AM6/2/15
to Node-RED Mailing LIst
Dean,

Greg's use case are outline in earlier posts in this thread, specifically:



@Greg - I spoke with Dave yesterday, he had missed your mention of the 'at' part of the cron task and had focussed on your original bullet points. No problem - be reassured we understand what's missing from your perspective.

Nick


--

Dean Sellers

unread,
Jun 2, 2015, 6:58:12 AM6/2/15
to node...@googlegroups.com
Thanks Nick,

Ok, I had read that and I didn't get where later or even cron doesn't solve the problem?

Greg, the example flow for later https://www.npmjs.com/package/node-red-contrib-later triggers every 5 minutes, clock time. So at 00.05, 00.10.... The linked doc to the actual code that runs is really helpful. But if you want to send something every hour, in later you use "every hour". It will then repeat the input at the next clock hour and every hour afterward.

 If you want some to trigger 'exactly' an hour after something else a function node using javascript's setTimeout() in a loop would work, wouldn't it?

Dave C-J

unread,
Jun 2, 2015, 12:02:20 PM6/2/15
to node...@googlegroups.com
In my defence the first example given.... " So for example you'd say '0/5' for minutes, would mean that the thing would happen at 0 minutes, and then every 5 minutes after that"  - is actually one that we can support... as the 0 is the option we offer ....  so we are both right  :-)     

But yes we can't currently do ..    every 20 minutes starting at 7 minutes past the hour. (though starting at 0 with a delay node of 7 mins could maybe do it ;-)

(but Dean's node can ;-)

Dean Sellers

unread,
Jun 2, 2015, 11:21:49 PM6/2/15
to node...@googlegroups.com
I would be interested to know if my node 'later' doesn't solve the problem. It might be easy to add whatever support needed.

Greg EVA

unread,
Jun 3, 2015, 5:06:05 AM6/3/15
to node...@googlegroups.com
G'day Cats,

@Nick - thank you for clearly stating the understanding of the issue/need!

@Dave - that's OK... we're all human (or perhaps not...) I could have misunderstood something as well.... as I saw */5 in the info window, which is obviously quite different than 0/5.

@Dean - sounds like your node, and example will be perfect for what I am trying to do.  That is really the thing... I want to use the clock and have the events triggered for example on the hour, or on the day.  I will give it a try.  Thanks!

Peace ;-)

Julian Knight

unread,
Jun 3, 2015, 4:45:45 PM6/3/15
to node...@googlegroups.com
By the way, was this for the Pi? because I've found that my pi works on GMT only when in NR and I have to remember that when I am doing time related things.

Greg EVA

unread,
Jun 4, 2015, 4:36:49 AM6/4/15
to node...@googlegroups.com
Nope.  I started with it running on the Pi with plans of integrating a serial USB device.... but quickly upgraded to a VM to give it a better home.

I have seen a bunch of locale config problems with Raspbian as well... would be nice if they'd sort that out
Reply all
Reply to author
Forward
0 new messages