Flow Filter
This function filters all messages based on control message. The control message is Boolean in nature, with a basic (and changeable topic) of 'allowdata'. Default status is false. To change, send msg.topic:allowdata and msg.payload:true as boolean, to input.
If control message is true, all following messages will be sent to output 1. If control message is false (default), all following messages will be sent to output 3. When the control message is updated true > false, or false > true, a status message is sent to output 2.
Message input [ status checked ] if true, message to output 1. if false, message to output 3. if status change, change message to output 2.
Non control messages, which is everything except the control, will pass to output 1 or 3 without any changes, to me, this is better than the bool-gate, that changes the topic.
Enjoy.
[{"id":"8f83235b.ec185","type":"function","z":"17022f92.521fc","name":"Flow Filter","func":"var AP = context.get('AP')||false; \nvar msgAP = {payload: AP};\n\nif (msg.topic == \"allowdata\"){\n if (msg.payload === true){\n context.set('AP', true);\n msgAP.payload = \"Allowed\";\n node.status({fill:\"green\",shape:\"dot\", text:\"Allowed\"});\n return[null, msgAP, null];\n }\n else if(msg.payload === false){\n context.set('AP', false);\n msgAP.payload = \"Denied\";\n node.status({fill:\"red\",shape:\"dot\", text:\"Denied\"});\n return[null, msgAP, null];\n }\n}\n\nif (AP === true) {\n node.status({fill:\"green\",shape:\"dot\", text:\"Allowed\"});\n return [msg, null, null];\n} \nelse if (AP === false) {\n node.status({fill:\"red\",shape:\"dot\", text:\"Denied\"});\n return [null, null, msg];\n}","outputs":"3","noerr":0,"x":329,"y":137,"wires":[["5eb4fbd8.661804"],["fb356d40.1ab28"],["754ce688.7a6bc8"]]},{"id":"32550fe.e8d3df","type":"inject","z":"17022f92.521fc","name":"Allow","topic":"allowdata","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"x":117,"y":95,"wires":[["8f83235b.ec185"]]},{"id":"457ce83b.866168","type":"inject","z":"17022f92.521fc","name":"Deny","topic":"allowdata","payload":"false","payloadType":"bool","repeat":"","crontab":"","once":false,"x":116,"y":136,"wires":[["8f83235b.ec185"]]},{"id":"1a4d82e1.0bbf8d","type":"inject","z":"17022f92.521fc","name":"Sample Data","topic":"sampledata","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":132,"y":174,"wires":[["8f83235b.ec185"]]},{"id":"5eb4fbd8.661804","type":"debug","z":"17022f92.521fc","name":"Allowed","active":true,"console":"false","complete":"payload","x":522,"y":97,"wires":[]},{"id":"fb356d40.1ab28","type":"debug","z":"17022f92.521fc","name":"Status","active":true,"console":"false","complete":"payload","x":510,"y":136,"wires":[]},{"id":"754ce688.7a6bc8","type":"debug","z":"17022f92.521fc","name":"Denied","active":true,"console":"false","complete":"payload","x":521,"y":176,"wires":[]}]