How to reset Trigger Node inside a Subflows? msg.reset don't work

I just firgured out that setting msg.reset to True inside a subflow does not reset the trigger. I think it is because each subflow will be run as a separate instance. So is there anyway to use a trigger node inside the subflow that I can manually reset it?

Test flows :


[{"id":"4ea28f90a2bbbaae","type":"subflow","name":"Test","info":"","category":"","in":[{"x":220,"y":420,"wires":[{"id":"be98edd1e6558ce6"}]}],"out":[{"x":1500,"y":660,"wires":[{"id":"58d75d607537f3b6","port":0}]}],"env":[{"name":"state","type":"bool","value":"true"},{"name":"force_control","type":"bool","value":"true"}],"meta":{},"color":"#DDAA99"},{"id":"be98edd1e6558ce6","type":"switch","z":"4ea28f90a2bbbaae","name":"State Command","property":"state","propertyType":"env","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":400,"y":420,"wires":[["c480c1c2754ee00c"],["b99c496d5eac742f","b0e822bc612129f7"]]},{"id":"b0e822bc612129f7","type":"trigger","z":"4ea28f90a2bbbaae","name":"","op1":"","op2":"true","op1type":"nul","op2type":"bool","duration":"5","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":780,"y":580,"wires":[["5e3940dc705eca5b"]]},{"id":"c480c1c2754ee00c","type":"change","z":"4ea28f90a2bbbaae","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":440,"wires":[["b0e822bc612129f7","762647792899d211"]]},{"id":"58d75d607537f3b6","type":"link in","z":"4ea28f90a2bbbaae","name":"link in 2","links":["c67a0ef15a60d4c3","792476e6e10ee98f","2d0748d40a685a13","c3b79478b0768725"],"x":1185,"y":660,"wires":[[]]},{"id":"2d0748d40a685a13","type":"link out","z":"4ea28f90a2bbbaae","name":"link out 5","mode":"link","links":["58d75d607537f3b6"],"x":1175,"y":440,"wires":[]},{"id":"5e3940dc705eca5b","type":"change","z":"4ea28f90a2bbbaae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Turn offfffff","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1000,"y":520,"wires":[["2d0748d40a685a13"]]},{"id":"b99c496d5eac742f","type":"change","z":"4ea28f90a2bbbaae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"Start counting","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":640,"wires":[["c3b79478b0768725"]]},{"id":"c3b79478b0768725","type":"link out","z":"4ea28f90a2bbbaae","name":"link out 3","mode":"link","links":["58d75d607537f3b6"],"x":1035,"y":640,"wires":[]},{"id":"762647792899d211","type":"change","z":"4ea28f90a2bbbaae","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"reset counting","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":940,"y":440,"wires":[["2d0748d40a685a13"]]}]

You need to format your code in blocks other wise the editor changes it. Click the little code button and paste where indicated between the 2 sets of backticks.

type or paste code here

Sub-flows work slightly differently, however the basic operation of the flow and nodes is the same, so yes you can indeed reset a trigger node, just as long as you work with the same sub-flow instance.

I suspect that Node-RED only keeps one copy of the flow definition, even for a sub-flow, however for sub-flows the flow is encapsulated, and can only be run (called) via a sub-flow node. Since you can have more than one sub-flow node, each such node is associated with a different flow-context. For each sub-flow node, an input message starts a new context space with a new message in the sub-flow, and the flow result returns to the calling sub-flow node.

Within the one sub-flow node however, the flow context remains for that node / sub-flow. This means that injecting a new message into the same sub-flow node will start a new message in the same flow-context. Therefore an input message with msg.reset property can be used to cause a reset of a trigger node that is already active in the flow context.

You appear to be using the UI environment variables to action the reset, but since environment variables are set when the sub-flow node is called and are therefore specific to the sub-flow node instance and context, this can only be set differently from a different sub-flow node and different flow context.

Just use a second input to the same sub-flow node, with msg.reset property set (you can use switch to route accordingly inside the flow if required) and this can be used to reset the trigger node. You can also set the msg.reset property inside the sub-flow, but the instantiation of this must originate from either a subsequent input message to the same sub-flow node, or from the internal logic within the sub-flow itself.

Starting the sub-flow with a basic message causes two outputs as expected from the Trigger node. Starting with a basic message, and then subsequently sending in msg.reset, causes the Trigger node to reset thereby cancelling the second output message.

Another alternative would be to use the Link-call nodes. This has much the same outcome as a sub-flow, in that a given flow can be called from one or more different points in the main flow, with the return coming back to the specific calling point. However, since the nodes are not part of a sub-flow (which can only accept one input point) additional link nodes can be used to accept inbound messages, routed directly to the trigger node and with msg.reset property set.