Inject only on the hour (Node Red)

I have a flow for my underfloor heating that I only want to inject on the hour…

This is in theory easy (see screenshot below) however there is a problem - after reboot etc it doesn’t seem to trigger because I’ve turned off the inject once tickbox…
Assume this is because it is states as then do xyz

The problem is I cannot have this card inject at random intervals when i’ve updated or whatever… so is there a better way to have something trigger every hour?
image

Time pattern triggers are not optimal.
Why do you need this to trigger ever hour?
Is there really no event or state that can trigger?

Nope, the only trigger is time as it takes a long time for my UFH to warm up so I’ve worked out the optimal pattern to minimise energy use while keeping it at an acceptable temperature

I think the only solution is to have the trigger as you do, then use a function node and calculate the number of seconds to the next full hour and send that to a delay node.

Even if you do restart it will trigger as Node red starts then delay until the next full hour.

1 Like

Trigger, on start (and repeat every hour).
Change node with some fancy JSONata to calculate the delay in milliseconds to the next hour
Delay node, set to accept msg.delay

Seems to work fine for me. Been firing every hour on the hour just as requested.

[{"id":"9a6b636812953f70","type":"inject","z":"987b2e9d10a9bd13","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"3600","crontab":"","once":true,"onceDelay":0.1,"topic":"","payloadType":"date","x":730,"y":3740,"wires":[["a72a41bd8f7ce6c3"]]},{"id":"83f913da7e4ec2f5","type":"delay","z":"987b2e9d10a9bd13","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"outputs":1,"x":1060,"y":3740,"wires":[["38acfdb525541374"]]},{"id":"38acfdb525541374","type":"debug","z":"987b2e9d10a9bd13","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1210,"y":3740,"wires":[]},{"id":"a72a41bd8f7ce6c3","type":"change","z":"987b2e9d10a9bd13","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"(\t    $time := ($now('[H]:[m]:[s]')~>$split(':')).$number();\t    1000*(60*(60-$time[1]) - $time[2])\t)\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":3740,"wires":[["83f913da7e4ec2f5"]]}]
2 Likes

Have a look at the node-red-contrib-cron-plus add-on - it can be used to schedule every hour, on the hour (using “0 * * * *”). This website helps with the peculiarities of cron.

3 Likes

Sorry for the delay in response, busy weekend!
A little further investigation and I think my trigger is firing as I expected, I just had a condition afterwards that was throwing things and a cache issue or something which meant status changes weren’t showing)

I’m not sure it’s doing this actually - the “Inject Once” is unticked and I’ve tried rebooting with notification etc to see if it does fire when it’s not supposed to and I’ve not seeing anything

I’m definitely going to save this in my example flows for future tweaking if needed

Also going to save for when I have more nuanced requirements :slight_smile: