Do a flow at the top of every hour


Need to do something at the top of every hour?
Node-RED is a little odd with its inject nodes… You can do something at an interval, or at a specific time once a day, but repeating at a specific time all day and all night is not in its bag of tricks.
Use this flow to inject a timestamp at the top of every hour… So in other words, just replace a single inject Node with these three nodes and your flow will run at the top of every hour.

Here is what it looks like.

What we are doing is using the Inject node to fire its time-stamp into the function Node every second.
The function Node has a little code to grab the time and pull out the hours which it then packages into the msg.payload.
The last node is the ‘Report By Exception’ Node. It is setup to only send out a time stamp when the input to this Node changes, which in our case is once an hour.

Note, whenever I get asked how to do anything, I always head over to first.
There are so many different flows and nodes there that usually you can find something close to what you need and tweak it to work for your application.

Here is the flow.

[{"id":"7e4cd656.31676","type":"inject","z":"57484d51.98fedc","name":"Every Second","topic":"","payload":"","payloadType":"date","repeat":"1","crontab":"","once":false,"onceDelay":0.1,"x":140,"y":540,"wires":[["d9dc9f17.84ef68"]]},{"id":"8183d8ac.01c1e","type":"rbe","z":"57484d51.98fedc","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":490,"y":540,"wires":[[]]},{"id":"d9dc9f17.84ef68","type":"function","z":"57484d51.98fedc","name":"Get Hour","func":"function gethour() {\n var date = new Date();\n var hour = (\"0\"+date.getHours()).substr(-2);\n return hour;\n}\n\nvar hour = gethour();\n\nreturn { payload : hour };","outputs":1,"noerr":0,"x":340,"y":540,"wires":[["8183d8ac.01c1e"]]}]


Exactly what I am looking for, but I am not able import the code via clipboard. Its not getting validated for me to hit the import button in nodered.


Yeah, sorry about that, we found that pasting code from Node-RED MUST be put in ‘formatted text’ mode in this Forum or it gets mangled.

I have fixed the text formatting.