Changing the inject node repeat option from UI

Morning all,

I'm new to Node Red so sorry if this is a dumb question.

I am controlling a solenoid to come on for 500 milliseconds and go off for 20 mins. This all works fine. I would however like to allow a variable time to be entered from the UI to set the 20 min wait time.

I've tried to upload my json file but the forum won't let me as i'm a new user?

So to describe my setup I have an inject with the repeat interval set to 20 mins going into a trigger set to 500ms going to a Pi output pin for the solenoid.

I would really appreciate your help.

Thanks

Grigsy

The inject node cannot be programmatically set, but you can do what you want in another way - check out Colin's neat solution or the sophisticated node-red-contrib-msg-resend node.

One way would be to replace the repeating inject with a function node containing a JavaScript setTimeout function.

Grigsy,

Have you had a look at the BigTimer contrib node?

Morning all,

Thanks for your feedback.

I have had a look at the suggestions above but not really go anywhere however I have had a play with the change node and I am very nearly there.

For context I am trying to allow for a time to be selected in the UI that will set a timer for the drum on my pond. This will trigger the drum to wash every X minutes. So you set the time for the drum to wait before a 500ms trigger is sent then repeat the "wait time".

The attached now works for the input timer and works the drum, however if I change the time, it runs two different timing intervals.

It appears that I need to clear the Global.delay and the the msg.delay before injecting a new time.

Your help as always is greatly appreciated!

Thanks

Julian

I've pasted below as I am still not allowed to upload attachements.

[{"id":"6fdfb8a.b02d748","type":"tab","label":"Drum Timer","disabled":false,"info":""},{"id":"cb9e3ab0.4048f8","type":"rpi-gpio out","z":"6fdfb8a.b02d748","name":"","pin":"11","set":"","level":"0","freq":"","out":"out","x":560,"y":440,"wires":},{"id":"c2b3185b.efcb18","type":"change","z":"6fdfb8a.b02d748","name":"","rules":[{"t":"set","p":"delay","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":280,"wires":[["f41b5591.e6e738"]]},{"id":"fe45d2c3.71a03","type":"delay","z":"6fdfb8a.b02d748","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":620,"y":280,"wires":[["7b8e3ee9.8a41d","50fc16d9.235f58","c2b3185b.efcb18"]],"outputLabels":["0"]},{"id":"f41b5591.e6e738","type":"change","z":"6fdfb8a.b02d748","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":280,"wires":[["fe45d2c3.71a03"]]},{"id":"47481bf6.e86d94","type":"ui_dropdown","z":"6fdfb8a.b02d748","name":"","label":"Set Drum Timer","tooltip":"","place":"Select option","group":"38b8797e.5fd136","order":4,"width":0,"height":0,"passthru":true,"options":[{"label":"1 Minutes","value":60000,"type":"num"},{"label":"2 Minutes","value":120000,"type":"num"},{"label":"15 Minutes","value":900000,"type":"num"},{"label":"25 Minutes","value":1500000,"type":"num"},{"label":"30 Minutes","value":1800000,"type":"num"},{"label":"45 Minutes","value":2700000,"type":"num"},{"label":"10 seconds","value":10000,"type":"num"},{"label":"20 seconds","value":20000,"type":"num"}],"payload":"","topic":"delay","x":80,"y":280,"wires":[["c2b3185b.efcb18"]]},{"id":"7b8e3ee9.8a41d","type":"change","z":"6fdfb8a.b02d748","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":360,"wires":[["4d6c34e5.9839dc","895e26f5.c66b88"]]},{"id":"50fc16d9.235f58","type":"debug","z":"6fdfb8a.b02d748","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":280,"wires":},{"id":"4d6c34e5.9839dc","type":"simpletime","z":"6fdfb8a.b02d748","name":"","x":470,"y":360,"wires":[["151d975d.abf959"]]},{"id":"151d975d.abf959","type":"ui_text","z":"6fdfb8a.b02d748","group":"38b8797e.5fd136","order":3,"width":0,"height":0,"name":"","label":"Time of Last Wash","format":"{{mydate}} {{mytime}}","layout":"col-center","x":650,"y":360,"wires":},{"id":"895e26f5.c66b88","type":"trigger","z":"6fdfb8a.b02d748","op1":"0","op2":"1","op1type":"num","op2type":"num","duration":"500","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":400,"y":440,"wires":[["cb9e3ab0.4048f8"]]},{"id":"38b8797e.5fd136","type":"ui_group","z":"","name":"Pond Filter","tab":"e438b126.3fec6","order":2,"disp":true,"width":"6","collapse":false},{"id":"e438b126.3fec6","type":"ui_tab","z":"","name":"Julian's Pond","icon":"dashboard","disabled":false,"hidden":false}]

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.

[{"id":"6fdfb8a.b02d748","type":"tab","label":"Drum Timer","disabled":false,"info":""},{"id":"cb9e3ab0.4048f8","type":"rpi-gpio out","z":"6fdfb8a.b02d748","name":"","pin":"11","set":"","level":"0","freq":"","out":"out","x":560,"y":440,"wires":[]},{"id":"c2b3185b.efcb18","type":"change","z":"6fdfb8a.b02d748","name":"","rules":[{"t":"set","p":"delay","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":280,"wires":[["f41b5591.e6e738"]]},{"id":"fe45d2c3.71a03","type":"delay","z":"6fdfb8a.b02d748","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":620,"y":280,"wires":[["7b8e3ee9.8a41d","50fc16d9.235f58","c2b3185b.efcb18"]],"outputLabels":["0"]},{"id":"f41b5591.e6e738","type":"change","z":"6fdfb8a.b02d748","name":"","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"global"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":280,"wires":[["fe45d2c3.71a03"]]},{"id":"47481bf6.e86d94","type":"ui_dropdown","z":"6fdfb8a.b02d748","name":"","label":"Set Drum Timer","tooltip":"","place":"Select option","group":"38b8797e.5fd136","order":4,"width":0,"height":0,"passthru":true,"options":[{"label":"1 Minutes","value":60000,"type":"num"},{"label":"2 Minutes","value":120000,"type":"num"},{"label":"15 Minutes","value":900000,"type":"num"},{"label":"25 Minutes","value":1500000,"type":"num"},{"label":"30 Minutes","value":1800000,"type":"num"},{"label":"45 Minutes","value":2700000,"type":"num"},{"label":"10 seconds","value":10000,"type":"num"},{"label":"20 seconds","value":20000,"type":"num"}],"payload":"","topic":"delay","x":80,"y":280,"wires":[["c2b3185b.efcb18"]]},{"id":"7b8e3ee9.8a41d","type":"change","z":"6fdfb8a.b02d748","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":280,"y":360,"wires":[["4d6c34e5.9839dc","895e26f5.c66b88"]]},{"id":"50fc16d9.235f58","type":"debug","z":"6fdfb8a.b02d748","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":790,"y":280,"wires":[]},{"id":"4d6c34e5.9839dc","type":"simpletime","z":"6fdfb8a.b02d748","name":"","x":470,"y":360,"wires":[["151d975d.abf959"]]},{"id":"151d975d.abf959","type":"ui_text","z":"6fdfb8a.b02d748","group":"38b8797e.5fd136","order":3,"width":0,"height":0,"name":"","label":"Time of Last Wash","format":"{{mydate}} {{mytime}}","layout":"col-center","x":650,"y":360,"wires":[]},{"id":"895e26f5.c66b88","type":"trigger","z":"6fdfb8a.b02d748","op1":"0","op2":"1","op1type":"num","op2type":"num","duration":"500","extend":false,"units":"ms","reset":"","bytopic":"all","name":"","x":400,"y":440,"wires":[["cb9e3ab0.4048f8"]]},{"id":"38b8797e.5fd136","type":"ui_group","z":"","name":"Pond Filter","tab":"e438b126.3fec6","order":2,"disp":true,"width":"6","collapse":false},{"id":"e438b126.3fec6","type":"ui_tab","z":"","name":"Julian's Pond","icon":"dashboard","disabled":false,"hidden":false}]

You will understand the issue if you debug the property msg._msgid in the output of your delay node.

What happens is that each time you change the time you are introducing a new message in your flow. These messages will loop forever in your flow.

This is a modification of your flow to ease the understanding.

r-02

Hi Andrei and thank you for your response.

I understand that I am sending multiple messages that never run out my issue is I am unsure how to resolve the problem.

I have tried addiing a change node and setting the global.delay and msg.delay to 0 then passing the msg.payload through but his doesn't work.

Any further help would be appreciated.

Julian

Not ideal but I have added a button that injects a Msg.reset = true to the delay mode so I can reset it and the set the new wait time.

Thanks for your help everyone

1 Like