# Custom node to run on hour or half hour

**URL:** <https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104>\
**Category:** General\
**Created:** [14 March 2020 16:23 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104 "2020-03-14T16:23:27Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [14 March 2020 16:23 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/1 "2020-03-14T16:23:27Z")

</div>

I've written a custom node to make an API call every 30 minutes. I have some code to make it only run once within the half hour period but I cannot find a way of triggering it on the hour/half hour.

What is the best way to get a node to run on each hour/half hour?

I could trigger regularly, but that seems rather a waste of resources.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [14 March 2020 16:26 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/2 "2020-03-14T16:26:09Z")

</div>

> [@borpin](#):
>
> I could trigger regularly, but that seems rather a waste of resources

Why? Are you low on resources? Just a trigger node needed...

---

<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:** [14 March 2020 16:39 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/3 "2020-03-14T16:39:29Z")

</div>

If you use an Inject node (I think that may be what @krambriw meant) set to Repeat at Interval Between Times and set it to 30 minutes then it will inject on the hour/half hour, as explained in the Info tab for the node.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [14 March 2020 19:20 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/4 "2020-03-14T19:20:36Z")

</div>

Oh yes, inject node was what I meant, thank you!

---

<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:** [14 March 2020 20:35 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/5 "2020-03-14T20:35:14Z")

</div>

I have made that mistake too, because the Inject node is used to trigger things I think.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [14 March 2020 22:44 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/6 "2020-03-14T22:44:03Z")

</div>

Hi Brian. Octopus?  
If you want to trigger the flow every 30 minutes, it may be better to avoid hardcoding the update time, because everyone using your node would be making the api request at exactly the same time, which could cause problems upstream.  
If you don't want to use an inject node, you could always look at [something like this node](https://github.com/node-red/node-red-web-nodes/blob/master/darksky/darksky.js#L135), which calls an api every 15 minutes as a template.

---

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [15 March 2020 10:27 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/7 "2020-03-15T10:27:41Z")

</div>

> [@Paul-Reed](#):
>
> Octopus?

Ha, caught 😁

Yes. The problem being you'll want the current price as soon as it becomes current. It is probably possible to get more clever and return it on the basis of the times in the data previously found and only call the API when looking for the next set of data.

I'll look at that but for now, I just need a reliable way of pulling the data and the Home Assistant RESTful Integration and a template isn't reliable I'm finding.

> [@Colin](#):
>
> set to Repeat at Interval Between Times and set it to 30 minutes then it will inject on the hour/half hour

Thanks - re-reading that it made sense now. What would it do with an interval of say 13 minutes? Would it do multiples of 13 per hour then reset to 13 minutes past each hour? What if you wanted to pull once per hour at 20 minutes past? I'm guessing it can't 😁

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [15 March 2020 10:36 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/8 "2020-03-15T10:36:35Z")

</div>

Have a look at the `node-red-contrib-cron-plus` node Brian, it is far more powerful than the inject node.

---

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [15 March 2020 10:58 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/9 "2020-03-15T10:58:53Z")

</div>

> [@Paul-Reed](#):
>
> Have a look at the `node-red-contrib-cron-plus`

Thanks Paul, I will. Looking at that DarkSky node, that looks a good approach. I'll investigate further.

---

<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:** [15 March 2020 11:10 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/10 "2020-03-15T11:10:58Z")

</div>

I am just looking at octopus too, if you get something going would you be able to share it?

---

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [15 March 2020 11:37 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/11 "2020-03-15T11:37:01Z")

</div>

Always happy to share (as well as my referral code 😉).

Have you looked at emonCMS - Part of the OpenEnergyMonitor project ([forum](https://community.openenergymonitor.org/latest)). They have a 'DemandShaper` module within that plus a module that will compare energy use measured against what it would have cost under Agile. Also, there have been some discussions on the Home Assistant forum on extracting the Octopus data. The final resource I'll offer is [this website](https://www.energy-stats.uk).

Next task is to calculate and return the lowest n hour period in the next 24 (or at the limit of the data available - the next 23:00 - 23:00 period is released around 16:00). I've sort of got it working.

My extremely rough module is here. I'm likely to be fiddling with it so is not stable in any sense right now. My Javascript is a little ropey - I know what I want to do, just not how to do it without a whole load of research 😁.

> **[borpin/node-red-contrib-octopus](https://github.com/borpin/node-red-contrib-octopus)**
>
> Octopus Node-Red node. Contribute to borpin/node-red-contrib-octopus development by creating an account on GitHub.

---

<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:** [15 March 2020 12:00 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/12 "2020-03-15T12:00:03Z")

</div>

The principle thing I want to do initially is get the recent usage data so I can put it into influx so I can chart it.  
I say 'I' but actually it is for my son.

---

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [15 March 2020 14:41 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/13 "2020-03-15T14:41:27Z")

</div>

> [@Colin](#):
>
> The principle thing I want to do initially is get the recent usage data

From Octopus? Their API will allow that I think. Just need to create an API Key.

---

<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:** [15 March 2020 14:52 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/14 "2020-03-15T14:52:30Z")

</div>

Yes, I know, create the key, and design a bit of flow to fetch it every half hour and extract any data I haven't got already so I can add it to the db. But if @borpin is building a node that will do that for me then hopefully I can use that.

---

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [16 March 2020 22:27 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/15 "2020-03-16T22:27:39Z")

</div>

@Colin, the node pulls in the pricing data now quite happily. Documentation needs a bit of work and it is still rough around the edges.

Once I have switched I'll work on the consumption data.

---

<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:** [17 March 2020 09:34 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/16 "2020-03-17T09:34:22Z")

</div>

Great, that is working for me. If I had some time I would look at helping with the usage stuff, but concentrating on trying to sort out elderly parents and making sure they can get food delivered at the moment so little time for recreation ☹  
Are you in the process of switching?

---

<div class="post-metadata">

**Author:** ![borpin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/borpin/32/1765_2.png) [@borpin](https://discourse.nodered.org/u/borpin)\
**Post date:** [18 March 2020 17:01 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/17 "2020-03-18T17:01:10Z")

</div>

> [@Colin](#):
>
> Are you in the process of switching?

Yes but they are failing miserably.

---

<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:** [17 May 2020 17:01 UTC](https://discourse.nodered.org/t/custom-node-to-run-on-hour-or-half-hour/23104/18 "2020-05-17T17:01:14Z")

</div>

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