Various flows connect to the OUT_RFX input link to send messages to RFXCom devices. Any incoming messages are also replicated to the OUT_RFX_RECEIVED output link to allow other flows to be notified. For example, I use this to update dashboard switches, or to send a Telegram message to my Telegram debugging channel.
Is it possible to convert this functionality to sub-flows like the following?
Basically the RFX Out sub-flow would process any incoming message in the same way as my current flow, but it would also need to forward the message to all instances of the RFX Out Received sub-flow.
It seems like link nodes cannot be used in sub-flows, otherwise I could simply convert my current flow to the RFX Out sub-flow, and connect the OUT_RFX_RECEIVED link to an input link defined in the the RFX Out Received sub-flow.
I guess I could add a function node that uses the Node-RED API to find all RFX Out Received nodes and send the incoming message to each of these nodes. Does anyone have any examples on the API functions to use, or are there any better ways of accomplishing this?
As an example, previously I had a similar RFX In flow, which receives messages from the RFXCom device, performs some operations on the message, and then forwards the message to an IN_RFX link. All functional flows that need to be triggered by RFXCom input messages then connected to this link.
I have now converted this re-usable flow into an RFX In sub-flow. All functional flows that previously connected to the IN_RFX link now connect directly to the RFX In sub-flow. This results in various advantages:
Hide internal nodes.
Reduction of the number of links. Especially when configuring a link in or link out node, it becomes difficult and error-prone to select the correct link(s) in a large list of links.
Re-usable sub-flows usually don't need a lot of maintenance, so the ability to close these tabs makes it easier to focus on functional flow tabs. (note that I currently have a separate flow tab for each reusable flow)
A sub-flow node provides a default name, description and icon, making it much easier to understand the flows that use these sub-flow nodes. In comparison, a link node by default only provides a generic link icon. You need to update name/icon/description/'show label' settings for every individual link to have it appear similar to a sub-flow node, and/or click on the link node to see where it connects to.
Taking this a bit further, given the flow simplification due to using a sub-flow like this, it would become viable to move all reusable flows to a single Reusable Links tab (instead of having a separate tab for every reusable flow). Comparing to the list of sub-flow advantages above:
Hides internal nodes (except for the link nodes).
Given that all re-usable links are on a single tab makes it a little easier to connect to the correct link when adding a new link, as the link settings page organizes links by tab.
The Reusable Links tab cannot be closed, but still better than having multiple tabs with reusable flows that cannot be closed.
This would still be an issue. I guess though I could add corresponding links on either the Reusable Links tab or in my library (haven't used the library before) with correct label/description/icon, and then copy/import such links from the library when I need to connect to these reusable flows. For example, for the OUT_RFX input link, I could define a corresponding OUT_RFX output link that can then be copied/imported to the flows that need to send messages to RFXCom devices.
Another minor issue with this approach is consistency; some flows like RFX In can be fully converted to a sub-flow, whereas other flows like RFX Out need to referenced through links.
I think I'll use this approach for now, but I would still be interested in potentially better approaches.