I seem to be recently bombarded with things which are variable.
The trigger
node (default) doesn't have the option to control the time to which it is set for the trigger to happen.
This has caught me a few times and it has come to a head. So I sat down and designed my own.
Yes, it is very very specific thing. But if/when you need it, it is painful not having it.
I've written many flows which are time based/triggered.
They expect things to happen at certain times, and if things happen: all is good.
If they don't then there is a problem.
In a prefect world, all these times are fixed, and I grant you that even when you write the flow: you have the option to adjust the time by editing the node.
But - and there's always a but...... - sometimes things don't quite fit.
You need to adjust the time and so you then have to run around and edit all those nodes and reset their times.
If you are a good programmer - and I am not - then it may not be a big thing.
But it only takes one node to be missed and the Gremlins escape, and it's all over.
So this sub-flow is a variable watchdog node.
It allows you to edit the time it waits - dynamically.
It allows you to set the "Start" message, so it sends you a "I am not doing my job" message.
Optionally, you can not send one by setting it to SKIP
.
You can set the message it sends when it detects a lack of message for a certain time.
All these have defaults in case you forget to set them.
(Or you can edit the node in the flow)
But this gives you the option to DYNAMICALLY change the time!
Yes, that means you have to add extra code to send this to the node anyway.
But that is then part of the code, and if you change the time you don't have to go and edit all the nodes to the new time.
Yes, I had to use a foreign node. See below.
I hope someone can use it.
I'm not saying you have to. But in the spirit of sharing, I thought I would post it.
Any nodes with a *
in their name are to be read. (That is my system to indicate there is more to read for some nodes.)
Node required:
node-red-contrib-countdown
[{"id":"cce7f624.e4e92","type":"subflow","name":"Watchdog","info":"","category":"","in":[{"x":170,"y":200,"wires":[{"id":"e5b65a5c.5721b"}]}],"out":[{"x":720,"y":160,"wires":[{"id":"ce959944.e6142","port":0}]}],"env":[],"color":"#DD0303","icon":"node-red/timer.svg"},{"id":"654ee6f5.f2ce2","type":"comment","z":"cce7f624.e4e92","name":"Watchdog *","info":"Node required:\n`node-red-contrib-countdown`\nSet time (in seconds) with `msg.topic` set to `control`\nSet the message to be sent when started with `topic` set to `startMessage`\nIf you set the message to `SKIP` then no message will be sent at start.\nSet the message to be sent when it times out with `topic` set to `failMessage`","x":400,"y":100,"wires":[]},{"id":"cd75d26e.edc","type":"countdown","z":"cce7f624.e4e92","name":"","topic":"","payloadTimerStart":"true","payloadTimerStartType":"bool","payloadTimerStop":"false","payloadTimerStopType":"bool","timer":"4711","resetWhileRunning":true,"setTimeToNewWhileRunning":true,"startCountdownOnControlMessage":false,"x":530,"y":200,"wires":[["ce959944.e6142"],[]]},{"id":"e5b65a5c.5721b","type":"switch","z":"cce7f624.e4e92","name":"control?","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"control","vt":"str"},{"t":"eq","v":"failMessage","vt":"str"},{"t":"eq","v":"startMessage","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":330,"y":200,"wires":[["cd75d26e.edc"],["5f64b009.d517f"],["6ccd39c7.efabc8"],["cd75d26e.edc"]]},{"id":"5f64b009.d517f","type":"change","z":"cce7f624.e4e92","name":"Fail Message","rules":[{"t":"set","p":"FailMessage","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":240,"wires":[[]]},{"id":"ce959944.e6142","type":"function","z":"cce7f624.e4e92","name":"Get Messages *","func":"if (msg.payload === false)\n{\n msg.payload = flow.get(\"FailMessage\") || \"DummyStop\";\n}\nif (msg.payload === true)\n{\n msg.payload = flow.get(\"StartMessage\") || \"DummyStart\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":540,"y":160,"wires":[[]],"info":"Edit the *default* values here."},{"id":"6ccd39c7.efabc8","type":"change","z":"cce7f624.e4e92","name":"Start Message","rules":[{"t":"set","p":"StartMessage","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":280,"wires":[[]]},{"id":"834e7a31.36f738","type":"subflow:cce7f624.e4e92","z":"ced2b72a.6e8688","name":"","x":910,"y":1750,"wires":[[]]}]