Extension: trigger node

Hello,
I use the example below quite a lot when monitoring that my external services are a live and running. Without going into details of this special service, I wonder if it would be a good option for the trigger to being able to resend the out message to it's input?

The example below works as follow:

  • the external (Weather) service is expected to deliver required data at some defined interval to a mqtt topic
  • if this fails, the trigger node restarts the service and informs the user (me) that this has happened via Telegram

Now, if the restart would fail, a second service restart attempt would not happen so there's the reason for the function node passing the output message back to the input. Restarts would then continue (forever) until the service starts & runs properly again

The function node is just the default, returning the incoming msg

image

Interesting question. So the point is that you wanted to do the same without using the function node and possibly adding this as a optional feature in the node. I am not sure if such new capability would be feasible. How about using link nodes like below ?

PS: in your flow you already uses an input link. You just need one more for the loop :grin:

2 Likes

Given the simplicity of the link feedback vs the myriad of possible options that "opening up" the node config could offer I'm tempted to not touch it...

Yes, the linking is of course the most efficient way but using a "dummy" function node gives maybe a more clearer view of what is happening, a "tunnel" node just passing the same message is what is meant. Many ways doing the same, I just thought is was in the trigger node such a thing could eventually belong, and maybe also in the delay node but I respect of course the important concerns regarding unwanted myriads :wink:

@krambriw, I think the node-red-contrib-msg-resend node can be configured to do what you want. This flow might come close. (I've added some control so that it doesn't run forever while you experiment with it.)

[{"id":"edcb1fed.809708","type":"msg-resend","z":"258a44dd.aacd44","interval":"3","intervalUnit":"secs","maximum":"0","bytopic":false,"clone":false,"firstDelayed":true,"addCounters":false,"highRate":true,"outputCountField":"","outputMaxField":"","name":"","x":530,"y":300,"wires":[["cc1d4a8a.4ae298"]]},{"id":"34a52ba2.e667b4","type":"inject","z":"258a44dd.aacd44","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"0","x":330,"y":300,"wires":[["edcb1fed.809708"]]},{"id":"cc1d4a8a.4ae298","type":"debug","z":"258a44dd.aacd44","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":670,"y":300,"wires":[]},{"id":"41e2e842.7247d","type":"inject","z":"258a44dd.aacd44","name":"start","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":340,"wires":[["32396202.98ae66"]]},{"id":"af0fa9e5.08bdc8","type":"inject","z":"258a44dd.aacd44","name":"stop","topic":"","payload":"1","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":380,"wires":[["32396202.98ae66"]]},{"id":"32396202.98ae66","type":"change","z":"258a44dd.aacd44","name":"","rules":[{"t":"set","p":"resend_max_count","pt":"msg","to":"payload","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":320,"y":360,"wires":[["edcb1fed.809708"]]}]

How often do you use the trigger node this way?

If this is a single use case, than @Andrei proposal is the perfect solution.

Otherwise the node-red-contrib-dsm node can do it in a single node.
If you'd like to try it, I'll post the dsm solution.

Thank you all, very interesting discussion as always!

With NR, so many possible ways to solve tasks. Another one not (yet) possible would be if it was allowed to connect the output with the input directly (under the hood, NR could anyway use, in such case, hidden links).

I use this setup to monitor external services that are running "outside" of NR. In my little Home Automation system I have in total 7 RPi's and one Lenovo Laptop (for the purpose getting really fast DNN video analytics), all integrated via MQTT. Reason for this "massive" amount of distributed Pi's, why is something I sometimes question myself, is mainly "easier to connect wireless than installing a lot of cables"

In all of those computers I have one or more Python scripts that are fully monitored & restarted in this way if required. Thanks to NR!

Anyway, for now I think I just keep the configuration as is, using function nodes, but when I make a major revision, I will change into using links I think

Best regards, Walter

If you want to use the core nodes, I'd use a switch instead of a function node:

trigger-restart

[{"id":"a840a91e.6098c8","type":"debug","z":"7c6a9ec3.f1512","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":490,"y":80,"wires":[]},{"id":"8ae0b9fc.f3a5e8","type":"trigger","z":"7c6a9ec3.f1512","op1":"","op2":"restarting","op1type":"nul","op2type":"str","duration":"3","extend":true,"units":"s","reset":"","bytopic":"all","name":"","x":290,"y":80,"wires":[["a840a91e.6098c8","b42e96b8.346368"]]},{"id":"98131d75.ce26a","type":"inject","z":"7c6a9ec3.f1512","name":"","topic":"start","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":80,"wires":[["8ae0b9fc.f3a5e8"]]},{"id":"b42e96b8.346368","type":"switch","z":"7c6a9ec3.f1512","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":290,"y":160,"wires":[["8ae0b9fc.f3a5e8"]]},{"id":"53abd264.b926fc","type":"inject","z":"7c6a9ec3.f1512","name":"","topic":"stop","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["8ae0b9fc.f3a5e8"]]}]

He's already using link nodes on the output ... so already has half the solution :slight_smile:

Sure! One thing I'm missing is a logic to stop the infinity loop.

Yes, all great possibilities. To add-on a logic that breaks the loop after x nbr's of attempts (using a join node) and if that doesn't help, the next action would eventually be a reboot. Also added a one-time trigger at the initial startup just "to get things going" again

EDIT: in the example below I can of course not reset the counter inside the join node (such method is not available) but I think I can live with that. If the counter starts to count up, a reboot might not be too bad

This feature is built in in my dsm-node solution :wink:
I'll add this use case to the dsm Wiki soon.

Just added the watchdog flow to the dsm Wiki Watchdog

watchdog

I hope, it can help simplify the logic.

2 Likes