# Ping a target every 20 seconds except 03:00 to 03:03

**URL:** <https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370>\
**Category:** General\
**Created:** [9 July 2024 11:18 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370 "2024-07-09T11:18:42Z")\
**Posts on this page:** 19\
**Page:** 1

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 July 2024 11:18 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/1 "2024-07-09T11:18:42Z")

</div>

I'm monitoring the availability of a remote machine by pinging it every 20 sec.  
Since my mobile broadband router reboots every day at 3am I'm getting false outage reports.

So what's the best way to not send the ping between 02:59:59 and 03:03:00?

I am using node-red-configurable-ping and have three cronplus nodes and two triggers:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58a1324939e3c6949c8ed2543da2da41d85ad2c0.png)

Is there a more elegant approach?  
A switch node that filters out any payload if the time is 02:59:59 to 03:03:00 maybe?

I could ping my router but it might reboot milliseconds after I do, thus still scope for false alerts.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [9 July 2024 11:41 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/2 "2024-07-09T11:41:37Z")

</div>

would this not work ?

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/feece80871137b36b521b306112b2d446f08284f.png)

```auto
[{"id":"cc139d1392f41af7","type":"cronplus","z":"f65bb41a740d2610","name":"","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"output1","defaultLocation":"","defaultLocationType":"default","outputs":1,"options":[{"name":"schedule1","topic":"topic1","payloadType":"date","payload":"","expressionType":"cron","expression":"0/20 * * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":290,"y":250,"wires":[["e1c485f77dc5ea6e"]]},{"id":"e1c485f77dc5ea6e","type":"time-range-switch","z":"f65bb41a740d2610","name":"","lat":"","lon":"","startTime":"02:59:59","endTime":"03:03:00","startOffset":0,"endOffset":0,"x":590,"y":250,"wires":[[],[]]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 July 2024 11:46 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/3 "2024-07-09T11:46:40Z")

</div>

Thanks @smanjunath211. I'll take a look at node-red-contrib-time-range-switch.

I didn't know cron-plus can do intervals shorter than a minute!

---

<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:** [9 July 2024 15:49 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/4 "2024-07-09T15:49:33Z")

</div>

Could not an Inject node be used instead of cron plus in this case?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 July 2024 16:32 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/5 "2024-07-09T16:32:04Z")

</div>

I have slimmed it down to a standard inject node and a function node provided by Leo AI built in to Brave Browser:

```auto
let now = new Date();
let start = new Date();
let end = new Date();
now.setMinutes(now.getMinutes() + now.getTimezoneOffset());
start.setHours(2, 59, 59);
end.setHours(3, 4, 59);

if (now >= start && now <= end) {
    msg.payload = start + " <= " + now + " <= " + end + " Reject"
    return [msg, null]
} else {
    msg.payload = now + " not between " + start + " and " + end + " OK"
    return [null, msg]
}

```

The AI ran out of breath before it could come up with a non-function version.  
I'm not convinced about  
`now.setMinutes(now.getMinutes() + now.getTimezoneOffset())`, will have to wait till tonight to see which HH:MM actually get rejected.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [9 July 2024 22:41 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/6 "2024-07-09T22:41:04Z")

</div>

Yeah i do something similar - i use the enhanced Inject node and the within time node and set the fail of the within time to just dump the requests so they never get to the router

Craig

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [9 July 2024 22:42 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/7 "2024-07-09T22:42:49Z")

</div>

Chat GPT thinks "your" code is a bit sloppy 😉

```auto
let now = new Date();
let start = new Date(now);
let end = new Date(now);

now.setMinutes(now.getMinutes() + now.getTimezoneOffset());

start.setHours(2, 59, 59, 0);
end.setHours(3, 4, 59, 999);

if (now >= start && now <= end) {
    msg.payload = start.toISOString() + " <= " + now.toISOString() + " <= " + end.toISOString() + " Reject";
    return [msg, null];
} else {
    msg.payload = now.toISOString() + " not between " + start.toISOString() + " and " + end.toISOString() + " OK";
    return [null, msg];
}

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 July 2024 23:00 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/8 "2024-07-09T23:00:43Z")

</div>

I can't believe you told ChatGPT I wrote that code! 😄

Jeez what's a millisecond or two?

As for the toISOString() thing, sensible though it is, I'm not planning on using that but instead seeing which timestamps are missing from a database.

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [9 July 2024 23:25 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/9 "2024-07-09T23:25:18Z")

</div>

I sometimes like to see what different AI think of each others work 😉

I hadn't come across Leo AI

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [9 July 2024 23:51 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/10 "2024-07-09T23:51:17Z")

</div>

It pops up every time I try and type B but mistakenly hit CTRL. Like the Sodding Paperclip of old only brighter.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [10 July 2024 02:36 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/11 "2024-07-10T02:36:20Z")

</div>

I was just going along with the OP. indeed an inject node would do the job.  
I was always curious to ask, I have several cron-plus nodes in my flow, where easily i can switch to inject node, but i cannot get it to trigger at '00' of the clock. is it possible to trigger at every minute but at '00' of the clock ?  
also, on memory pov, how much impact does a cron-plus node have compared to an inject node ?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 July 2024 02:56 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/12 "2024-07-10T02:56:42Z")

</div>

> [@smanjunath211](#):
>
> is it possible to trigger at every minute but at '00' of the clock ?

Repeat at "interval between times" 00:00 and 00:00 should do that.

---

<div class="post-metadata">

**Author:** ![smanjunath211](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/smanjunath211/32/95742_2.png) [@smanjunath211](https://discourse.nodered.org/u/smanjunath211)\
**Post date:** [10 July 2024 07:02 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/13 "2024-07-10T07:02:47Z")

</div>

Yes, It is working! new things to learn everyday.

I believe there should be a separate section of **DID YOU KNOW** in this forum!  
tips and tricks shared by experts on a regular basis, since by now they know where new users usually get stuck at or take a longer route to achieve their goal.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [10 July 2024 09:26 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/14 "2024-07-10T09:26:56Z")

</div>

As you already have cron-plus, here is an alternative no-code way (without triggers or delays)

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/5/85cb366eb2efd54fe95317731656ef8e42871157.png)

```auto
[{"id":"d42434189dccf003","type":"cronplus","z":"153004dfa27f7bcc","name":"","outputField":"payload","timeZone":"","storeName":"","commandResponseMsgOutput":"fanOut","defaultLocation":"","defaultLocationType":"default","outputs":5,"options":[{"name":"20s","topic":"Every 20 sec","payloadType":"default","payload":"","expressionType":"cron","expression":"0/20 * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"disable","topic":"disable","payloadType":"bool","payload":"true","expressionType":"cron","expression":"0 0 3 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"enable","topic":"disable","payloadType":"bool","payload":"false","expressionType":"cron","expression":"0 3 3 * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":790,"y":140,"wires":[["aae7da4a0e98475b"],["a69f36e039feaa4b"],["a69f36e039feaa4b"],[],[]]},{"id":"aae7da4a0e98475b","type":"switch","z":"153004dfa27f7bcc","name":"disabled?","property":"disabled","propertyType":"flow","rules":[{"t":"true"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1000,"y":100,"wires":[["fc01af8012d44521"],["11cbf02243ffc0d1"]]},{"id":"a69f36e039feaa4b","type":"change","z":"153004dfa27f7bcc","name":"update flow.disabled","rules":[{"t":"set","p":"disabled","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1040,"y":160,"wires":[[]]},{"id":"11cbf02243ffc0d1","type":"debug","z":"153004dfa27f7bcc","name":"do ping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1220,"y":120,"wires":[]},{"id":"fc01af8012d44521","type":"debug","z":"153004dfa27f7bcc","name":"do nothing","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1230,"y":80,"wires":[]}]

```

---

<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:** [10 July 2024 09:49 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/15 "2024-07-10T09:49:42Z")

</div>

Can this not be done using just two inject nodes? One configured to repeat, using Interval between times, every 20 seconds between 00:00 and 02:59, and another the same, but between 03:03 and 24:00?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [10 July 2024 09:54 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/16 "2024-07-10T09:54:46Z")

</div>

How do you get a repeat interval shorter than a minute with repeat between times?

I can't get it to accept start and end times other than hh:00 either ☹

These seem to be non-positive features of the inject node.

---

<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:** [10 July 2024 09:57 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/17 "2024-07-10T09:57:57Z")

</div>

Ah, good point, I had never noticed that. I withdraw my suggestion.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [10 July 2024 23:47 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/18 "2024-07-10T23:47:54Z")

</div>

Yeah need the inject enhanced node for that which is what i use for most of them that do not need the total flexibility of Cronplus. I find it is easier to understand than Cronplus (as it is very close to the standard inject node - just a bit more flexible)

Craig

---

<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:** [8 October 2024 23:48 UTC](https://discourse.nodered.org/t/ping-a-target-every-20-seconds-except-03-00-to-03-03/89370/19 "2024-10-08T23:48:05Z")

</div>

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