Custom node to run on hour or half hour

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.

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

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.

1 Like

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

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

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, which calls an api every 15 minutes as a template.

Ha, caught :grin:

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.

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 :grin:

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

1 Like

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

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

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

Have you looked at emonCMS - Part of the OpenEnergyMonitor project (forum). 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.

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 :grin:.

1 Like

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.

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

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.

@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.

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 :frowning:
Are you in the process of switching?

Yes but they are failing miserably.

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