Do a flow at the top of every hour


#1

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 hour.
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 flows.nodered.org 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”:“960e832b.b7fe5”,“type”:“inject”,“z”:“1da9d23f.b57efe”,“name”:“Second Tick”,“topic”:"",“payload”:"",“payloadType”:“date”,“repeat”:“1”,“crontab”:"",“once”:false,“x”:160,“y”:320,“wires”:[[“8433d8f7.e9bb78”]]},{“id”:“8433d8f7.e9bb78”,“type”:“function”,“z”:“1da9d23f.b57efe”,“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\nmsg = {payload:hour};\nreturn msg;\n”,“outputs”:1,“noerr”:0,“x”:330,“y”:320,“wires”:[[“50cca2b9.59de5c”]]},{“id”:“50cca2b9.59de5c”,“type”:“rbe”,“z”:“1da9d23f.b57efe”,“name”:"",“func”:“rbe”,“gap”:"",“start”:"",“inout”:“out”,“x”:467,“y”:320,“wires”:[[“d330822d.86d12”]]},{“id”:“afe311c2.714c78”,“type”:“comment”,“z”:“1da9d23f.b57efe”,“name”:“Automaticly do the do at the top of every hour”,“info”:"",“x”:230,“y”:260,“wires”:[]}]