Cancel inputs for a period of time

Is there a way I can cancel inputs from other nods using a button until I press it again?

Welcome to the forum @luis.

That is a very vague question as you haven't said what you mean by 'inputs from other nodes`. However if what you want to do is to block messages based on the button press then you can use node-red-contrib-simple-gate to do that. It would be easiest to use a ui-switch rather than a button as then you can feed the switch straight into the gate node. If you must use a button then you will have to add a bit of extra logic generate the pass/block messages alternately.

Yes I want to block messages based on the button and I also must use a button, I'll try that simple gate. Thanks

I wanted to press the button once and block the messages and then when I click it again it lets the messages through

You can easily convert the single press button to two state using a function node and node context to remember the previous state. However, get it running using a ui_switch first (as that is simpler and you can check it works) then change to using a button if you really must.

You can block / unblock flow in the node-red editor with simple change and switch nodes...

image

[{"id":"cd7521f5.10b9c","type":"inject","z":"4656711a.6b16a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":780,"wires":[["f09b3da7.cc7b7"]]},{"id":"f09b3da7.cc7b7","type":"switch","z":"4656711a.6b16a","name":"blockFlow is false?","property":"blockFlow","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":430,"y":780,"wires":[["c7e7a1c1.45b11"]]},{"id":"c7e7a1c1.45b11","type":"debug","z":"4656711a.6b16a","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":450,"y":840,"wires":[]},{"id":"786630c0.b0ed4","type":"inject","z":"4656711a.6b16a","name":"block","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":230,"y":700,"wires":[["484bfc3f.a71ed4"]]},{"id":"f5819368.a7c6f","type":"inject","z":"4656711a.6b16a","name":"unblock","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"false","payloadType":"bool","x":230,"y":660,"wires":[["484bfc3f.a71ed4"]]},{"id":"484bfc3f.a71ed4","type":"change","z":"4656711a.6b16a","name":"","rules":[{"t":"set","p":"blockFlow","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":680,"wires":[[]]}]


Or for a more self contained version (with indicator), use a function node...

image

image

[{"id":"cd7521f5.10b9c","type":"inject","z":"4656711a.6b16a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":250,"y":780,"wires":[["c1e35392.abf13"]]},{"id":"c7e7a1c1.45b11","type":"debug","z":"4656711a.6b16a","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":450,"y":840,"wires":[]},{"id":"786630c0.b0ed4","type":"inject","z":"4656711a.6b16a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"_block","payload":"true","payloadType":"bool","x":240,"y":700,"wires":[["c1e35392.abf13"]]},{"id":"f5819368.a7c6f","type":"inject","z":"4656711a.6b16a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"_block","payload":"false","payloadType":"bool","x":250,"y":660,"wires":[["c1e35392.abf13"]]},{"id":"c1e35392.abf13","type":"function","z":"4656711a.6b16a","name":"gate","func":"var block = context.get(\"block\") || false;\nif (msg.topic == \"_block\") {\n    block = msg.payload;\n    context.set(\"block\", block);\n    var stat = {\n        fill: block ? \"red\" : \"green\",\n        shape: block ? \"dot\": \"ring\",\n        text: block ? \"Blocked\" : \"Unblocked\"\n    }\n    node.status(stat)\n}\n\nif(block) return null; //halt flow\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":410,"y":780,"wires":[["c7e7a1c1.45b11"]]}]
2 Likes

But can I use that with just one button?

Yes. Modify the function to invert the flag. you can do whatever you want. Pretty basic stuff TBH...

image

[{"id":"30fa103f.eaf63","type":"inject","z":"ca47339b.a88a1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"0.5","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":700,"wires":[["83cbfbf5.ac2558"]]},{"id":"9ffb7a65.d24838","type":"debug","z":"ca47339b.a88a1","name":"","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":510,"y":760,"wires":[]},{"id":"83cbfbf5.ac2558","type":"function","z":"ca47339b.a88a1","name":"gate","func":"var block = context.get(\"block\") || false;\n\nif (msg.topic == \"_block_toggle\") {\n    block = !block;\n    context.set(\"block\", block);\n    var stat = {\n        fill: block ? \"red\" : \"green\",\n        shape: block ? \"dot\": \"ring\",\n        text: block ? \"Blocked\" : \"Unblocked\"\n    }\n    node.status(stat)\n}\n\nif(block) return null; //halt flow\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":510,"y":700,"wires":[["9ffb7a65.d24838"]]},{"id":"69be54a4.ab448c","type":"inject","z":"ca47339b.a88a1","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"_block_toggle","payload":"true","payloadType":"bool","x":330,"y":640,"wires":[["83cbfbf5.ac2558"]]}]