# Delay command until the top of the minute

**URL:** <https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487>\
**Category:** Developing Nodes\
**Created:** [6 September 2020 02:19 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487 "2020-09-06T02:19:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![martin8094](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@martin8094](https://discourse.nodered.org/u/martin8094)\
**Post date:** [6 September 2020 02:19 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/1 "2020-09-06T02:19:14Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [6 September 2020 03:39 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/2 "2020-09-06T03:39:07Z")

</div>

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.

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 September 2020 08:46 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/3 "2020-09-06T08:46:14Z")

</div>

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

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a463a5322eb7cb3fa421dec06e5eeb66e21b25f8.png)

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [6 September 2020 08:58 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/4 "2020-09-06T08:58:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![martin8094](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@martin8094](https://discourse.nodered.org/u/martin8094)\
**Post date:** [6 September 2020 09:06 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/5 "2020-09-06T09:06:45Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [6 September 2020 09:07 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/6 "2020-09-06T09:07:53Z")

</div>

I think @Colin has a better way.

I just am not that much of an expert.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 September 2020 09:10 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/7 "2020-09-06T09:10:51Z")

</div>

> [@martin8094](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![martin8094](https://avatars.discourse-cdn.com/v4/letter/m/bcef8e/32.png) [@martin8094](https://discourse.nodered.org/u/martin8094)\
**Post date:** [6 September 2020 09:24 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/8 "2020-09-06T09:24:08Z")

</div>

Hi Colin,

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 November 2020 09:24 UTC](https://discourse.nodered.org/t/delay-command-until-the-top-of-the-minute/32487/9 "2020-11-05T09:24:20Z")

</div>

Closed on 5 November 2020 09:24 UTC

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