# Creating flows based on node-red events?

**URL:** <https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979>\
**Category:** General\
**Created:** [14 February 2021 15:46 UTC](https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979 "2021-02-14T15:46:09Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [14 February 2021 22:32 UTC](https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979/21 "2021-02-14T22:32:59Z")

</div>

Though this has no real code in it, this is (maybe) a better example of what I am trying to say:

 ![Screenshot from 2021-02-15 09-32-24](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/8/18d16a87540438417c86b0acc1359c9a49cb5ddb.png)

```auto
[{"id":"e6e5edba.0a4358","type":"function","z":"8bb4de19.f72c88","name":"startup stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2690,"y":3130,"wires":[["2ea75733.23cd38"]]},{"id":"2ea75733.23cd38","type":"function","z":"8bb4de19.f72c88","name":"main stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2840,"y":3130,"wires":[["4decf0aa.7c4248"]]},{"id":"4decf0aa.7c4248","type":"function","z":"8bb4de19.f72c88","name":"end stuff","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2980,"y":3130,"wires":[["904f2553.f7283"]]},{"id":"a5221b63.7698e","type":"comment","z":"8bb4de19.f72c88","name":"This is your existing flow.","info":"","x":2840,"y":3090,"wires":[]},{"id":"7cc29f0d.525948","type":"function","z":"8bb4de19.f72c88","name":"This determins that the flow should be done","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2700,"y":3050,"wires":[["e6e5edba.0a4358"]]},{"id":"14e27688.181e59","type":"function","z":"8bb4de19.f72c88","name":"This wipes all the stored variables (etc)","func":"\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":3020,"y":3230,"wires":[["7cc29f0d.525948"]]},{"id":"904f2553.f7283","type":"delay","z":"8bb4de19.f72c88","name":"","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":3140,"y":3130,"wires":[["14e27688.181e59"]]},{"id":"b738c446.d813a8","type":"comment","z":"8bb4de19.f72c88","name":"All done and get ready for next time.","info":"","x":3210,"y":3090,"wires":[]}]

```

Just to show you what I am meaning.

Hope it helps.

And really the _wire_ from the `wipe` node back to the `start` node isn't needed.  
The start node detects things externally anyway and doesn't need an input (from a node as shown).

Can you understand what I am trying to show you?

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [14 February 2021 22:36 UTC](https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979/22 "2021-02-14T22:36:12Z")

</div>

Zoom out and take a screen shot of the flow (don't post the code) and maybe show what is the _input_ and which is the _output_.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [14 February 2021 22:56 UTC](https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979/23 "2021-02-14T22:56:33Z")

</div>

The built in persistent storage plugin does flush to disk when a close event happens. All nodes get a close event, so they can tidy themselves up, but you can't run a flow based on it. As Nick said there is work in progress to allow more graceful stopping (eg allow a flow to complete before stop etc)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 April 2021 22:57 UTC](https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979/24 "2021-04-15T22:57:19Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/creating-flows-based-on-node-red-events/40979.md?page=1)
