Hi, i've created a flow that send a msg evry 5 seconds and it's infinite now i have to create a switch that make me able to turn on and off the system without "cutting" the flow. Thx in advance
There are a ton of examples on the forum.
Here is one such way: Stop inject message - #3 by Steve-Mcl
You could also install a gate
node to do the same thing
can i do it without using code?
Yes. Use a change
node to Set/Reset a flow
or global
context variable and use a switch
node to allow/block the passing of messages.
Hello again!
Two options:
- Put a switch node after your inject which tests the value of a context variable
[{"id":"e43380a154ca2c9a","type":"inject","z":"8c4e3f534dc04c4f","name":"","props":[{"p":"payload"}],"repeat":"5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":290,"y":480,"wires":[["5016645086a493e7"]]},{"id":"5016645086a493e7","type":"switch","z":"8c4e3f534dc04c4f","name":"flow.messagesblocked == yes?","property":"messagesblocked","propertyType":"flow","rules":[{"t":"eq","v":"no","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":530,"y":480,"wires":[["f2af62755da68fea"]]},{"id":"f2af62755da68fea","type":"debug","z":"8c4e3f534dc04c4f","name":"debug 20","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":760,"y":480,"wires":[]},{"id":"b29fe054b9e09f23","type":"inject","z":"8c4e3f534dc04c4f","name":"block messages","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"yes","payloadType":"str","x":300,"y":380,"wires":[["5f9c03e9e8554e93"]]},{"id":"30fa8ae93edc94f8","type":"inject","z":"8c4e3f534dc04c4f","name":"allow messages","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"no","payloadType":"str","x":300,"y":420,"wires":[["5f9c03e9e8554e93"]]},{"id":"5f9c03e9e8554e93","type":"change","z":"8c4e3f534dc04c4f","name":"","rules":[{"t":"set","p":"messagesblocked","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":530,"y":400,"wires":[[]]}]
- There are various "gate" nodes available. Take a look at node-red-contrib-simple-gate for instance. It may have example flows you can import via Manage Palette.
PS, this is really beginner stuff so i assume you are new to node-red?
I recommend watching this playlist (it covers context and switches and change nodes): Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.
You can use node-red-contrib-simple-gate which is designed for exactly this.
and how can i connect?
Put it where you want to block it.
If you are using the gate node then look at the help text and the readme on the node-red flows page to see how to use it. Also, after installing it, you can import example flows for the node by selecting Import and then Examples.
If you don't understand how to use it then watch the videos linked to earlier and come back if you need further help after that.
Also please add a closing comment to your previous post indicating that that question has been answered, or you can mark one of the answers as the solution.
Hard to tell from just a picture of your flow, but perhaps you are republishing an MQTT message to the same topic?
I strongly advise against doing it like this.
If the incoming messages are from a mqtt node. You could use dynamic subscription to subscribe and unsubsrcibe at will.
examples here Dynamic MQTT LWT birth, Close & Will Property - #2 by Steve-Mcl