Delay command until the top of the minute

Hi, I need to sync a command on multiple raspberry pis running node red. Currently all the pis are connected to the internet and sync with a NTP clock (I am using the node which shows the time on the dashboard top right corner).

I am after a node that once a button is clicked, the node does not start until the top of the minute. So as an example if a button is pressed at 10:40:15, the command is delayed until 10:41:00.

I cannot figure it out myself (I don't know how to program nodes). Some help would be really appreciated.

Why does this need to happen at the top of the minute?

Here is a flow which does that.

External node required: node-red-contrib-cron-plus
This node allows better control of when things happen.

[{"id":"7fa25746.3c6ab8","type":"cronplus","z":"68e3655f.b606b4","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"schedule1","topic":"schedule1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":250,"y":1770,"wires":[["2192c12a.c94d4e"]]},{"id":"2192c12a.c94d4e","type":"function","z":"68e3655f.b606b4","name":"Top of the minute","func":"if (msg.topic == \"GATE\")\n{\n    context.set(\"ALLOW\",1);\n    node.status({fill: \"green\",text:\"ONE\"});\n    return;\n}\nif (context.get(\"ALLOW\") == 1)\n{\n    //\n    context.set(\"ALLOW\",0);\n    node.status({});\n    return msg;\n}","outputs":1,"noerr":0,"x":440,"y":1740,"wires":[["3d931b76.dd0084"]]},{"id":"3d931b76.dd0084","type":"debug","z":"68e3655f.b606b4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":660,"y":1740,"wires":[]},{"id":"59d03342.87f37c","type":"inject","z":"68e3655f.b606b4","name":"Activate","topic":"GATE","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":240,"y":1710,"wires":[["2192c12a.c94d4e"]]}]

That's quite nice.
You can simplify it a bit by using an Inject node configured like this rather than the cron node.

oh well.... There are a lot of ways to skin a cat. :wink:

Hi, Thank you.

The reason is that I need to interrupt relays which are running on different raspberry pis (different electrical cabinets). I need the relays to switch at the same time.

Really appreciate your help.

I think @Colin has a better way.

I just am not that much of an expert.

Just checking that you realise that using this method you can't guarantee exactly the same time. Whether they are near enough depends on your requirement. Depending on what else is going on in the pi they could be fractions of a second or even seconds apart. If this is a safety issue or if damage to equipment could occur if they are out or sync then this is not the way to do it.

Hi Colin,

For my purpose its not vital to be exact, no safety issue.

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