# Problems with mqtt node (msg.payload interrupt)

**URL:** <https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167>\
**Category:** General\
**Created:** [16 July 2020 04:54 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167 "2020-07-16T04:54:38Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [16 July 2020 04:54 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/1 "2020-07-16T04:54:38Z")

</div>

Hi, I'm trying to use some conditions with some readings from Arduino Mega, my issue is when I try to use the switch to send open, my condition don't allow me to send the msg, there is any solution to this?  
I was thinking about a switch case function, but it will be better to see another options.

```auto
[{"id":"edb33bf1.6e7ef8","type":"ui_switch","z":"75f85cad.09ef84","name":"","label":"OPEN/CLOSE","tooltip":"","group":"361cda81.f95386","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"OPEN","onvalueType":"str","onicon":"","oncolor":"","offvalue":"CLOSE","offvalueType":"str","officon":"","offcolor":"","x":540,"y":140,"wires":[["d87e7247.67ab5"]]},{"id":"d87e7247.67ab5","type":"mqtt out","z":"75f85cad.09ef84","name":"","topic":"lab/device1","qos":"","retain":"","broker":"61996a40.9e6e44","x":710,"y":140,"wires":[]},{"id":"1034c79c.c09d78","type":"delay","z":"75f85cad.09ef84","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":330,"y":400,"wires":[["638a82bd.a4cc7c"]]},{"id":"638a82bd.a4cc7c","type":"range","z":"75f85cad.09ef84","minin":"0","maxin":"550","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":480,"y":400,"wires":[["6b3c6b03.8dd224"]]},{"id":"6b3c6b03.8dd224","type":"function","z":"75f85cad.09ef84","name":"","func":"var humidityporcent=msg.payload;\n\nglobal.set('humidity',humidityporcent);\n\nvar humiditycondition = global.get(\"humidity\");\n\n if (humiditycondition < 20) \n\t {\n\t\tmsg.payload = \"OPEN\";\n\t\treturn msg;\n\t}\n\telse if (humiditycondition > 60) \n\t {\n\t\tmsg.payload = \"CLOSE\";\n\t\treturn msg;\n\t}","outputs":1,"noerr":0,"x":610,"y":400,"wires":[["487c49c5.c35488"]]},{"id":"a29be998.b916e8","type":"arduino in","z":"75f85cad.09ef84","name":"Mega","pin":"2","state":"ANALOG","arduino":"87b7cbc8.e9ff98","x":190,"y":400,"wires":[["1034c79c.c09d78"]]},{"id":"487c49c5.c35488","type":"mqtt out","z":"75f85cad.09ef84","name":"","topic":"lab/device1","qos":"","retain":"","broker":"61996a40.9e6e44","x":770,"y":400,"wires":[]},{"id":"361cda81.f95386","type":"ui_group","z":"","name":"control valvula","tab":"fdf8ba2e.2694f8","order":1,"disp":true,"width":"6","collapse":false},{"id":"61996a40.9e6e44","type":"mqtt-broker","z":"","name":"","broker":"192.168.43.47","port":"1883","clientid":"Hidro","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"87b7cbc8.e9ff98","type":"arduino-board","z":"","device":"/dev/ttyACM0"},{"id":"fdf8ba2e.2694f8","type":"ui_tab","z":"","name":"Home 1","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 July 2020 08:41 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/2 "2020-07-16T08:41:03Z")

</div>

Could you expand the explaination of your issue? You say:

> when I try to use the switch to send open, my condition don't allow me to send the msg

However there is no `switch` node in your flow. If you are talking about your `function` node's code, your logic dictates that only input messages that ar between 21 and 59 will cause any output.

The best way to see what is happening in a flow s to add`debug` nodes on the output of nodes along the flow. Then you can see what is happening. To debug a `function` node, add in `node.warn()` statments like  
`node.warn("debug1 - humiditycondition="+humiditycondition);`  
which will display the value of humiditycondition at that point in the flow.

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [16 July 2020 15:46 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/3 "2020-07-16T15:46:07Z")

</div>

![Sin título](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/7/b75527d039f23e384c2e506ac552baf3146010f2.png)  
For switch I was meaning about that node, and did you mean something like this...

```auto
[{"id":"f55f90bc.039bc","type":"ui_switch","z":"d65f5b12.ac1c08","name":"","label":"OPEN/CLOSE","tooltip":"","group":"4e3ad1c4.e639e","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"OPEN","onvalueType":"str","onicon":"","oncolor":"","offvalue":"CLOSE","offvalueType":"str","officon":"","offcolor":"","x":500,"y":220,"wires":[["f45d0de4.b6ddc","b11c448a.9dd468"]]},{"id":"f45d0de4.b6ddc","type":"mqtt out","z":"d65f5b12.ac1c08","name":"","topic":"lab/device1","qos":"","retain":"","broker":"2e5472af.7f3cfe","x":870,"y":80,"wires":[]},{"id":"2c52a45b.7420cc","type":"delay","z":"d65f5b12.ac1c08","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":290,"y":480,"wires":[["72789955.7c4128"]]},{"id":"72789955.7c4128","type":"range","z":"d65f5b12.ac1c08","minin":"0","maxin":"550","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":440,"y":480,"wires":[["9c692584.ea05d8"]]},{"id":"9c692584.ea05d8","type":"function","z":"d65f5b12.ac1c08","name":"","func":"var humidityporcent=msg.payload;\n\nglobal.set('humidity',humidityporcent);\n\nvar humiditycondition = global.get(\"humidity\");\n\n if (humiditycondition < 20) \n\t {\n\t\tmsg.payload = \"OPEN\";\n\t\treturn msg;\n\t}\n\telse if (humiditycondition > 60) \n\t {\n\t\tmsg.payload = \"CLOSE\";\n\t\treturn msg;\n\t}","outputs":1,"noerr":0,"x":570,"y":480,"wires":[["81383029.91914","327e1361.0b865c"]]},{"id":"9d83bd0.8a0824","type":"arduino in","z":"d65f5b12.ac1c08","name":"Mega","pin":"2","state":"ANALOG","arduino":"5bf4ba77.d85d84","x":150,"y":480,"wires":[["2c52a45b.7420cc"]]},{"id":"81383029.91914","type":"mqtt out","z":"d65f5b12.ac1c08","name":"","topic":"lab/device1","qos":"","retain":"","broker":"2e5472af.7f3cfe","x":750,"y":580,"wires":[]},{"id":"37487aac.81c626","type":"debug","z":"d65f5b12.ac1c08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":970,"y":480,"wires":[]},{"id":"6b399a9c.b89154","type":"debug","z":"d65f5b12.ac1c08","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1040,"y":240,"wires":[]},{"id":"b11c448a.9dd468","type":"function","z":"d65f5b12.ac1c08","name":"","func":"node.warn(\"debug1 - humiditycondition=\"+humiditycondition);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":880,"y":280,"wires":[["6b399a9c.b89154"]]},{"id":"327e1361.0b865c","type":"function","z":"d65f5b12.ac1c08","name":"","func":"node.warn(\"debug1 - humiditycondition=\"+humiditycondition);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":880,"y":400,"wires":[["37487aac.81c626"]]},{"id":"4e3ad1c4.e639e","type":"ui_group","z":"","name":"control valvula","tab":"f357030d.fc8b2","order":1,"disp":true,"width":"6","collapse":false},{"id":"2e5472af.7f3cfe","type":"mqtt-broker","z":"","name":"","broker":"192.168.43.47","port":"1883","clientid":"Hidro","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"5bf4ba77.d85d84","type":"arduino-board","z":"","device":"/dev/ttyACM0"},{"id":"f357030d.fc8b2","type":"ui_tab","z":"","name":"Home 1","icon":"dashboard","disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [16 July 2020 18:30 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/4 "2020-07-16T18:30:01Z")

</div>

Try this, add an MQTT-in node and subscribe to the same topic you are publishing to, connect the `mqtt-in` node to a `debug` node and see if the result comes back .

If that doesn't work, replace the switch with anotehr version and see what happens.

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [17 July 2020 03:40 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/5 "2020-07-17T03:40:59Z")

</div>

I tried but it didn't work, I'm going to explain it again,I need a function that when I use my switch node in the dashboard, it invalidates my function, so that they do not interrupt each other

This is my function

```auto
var humidityporcent=msg.payload;

global.set('humidity',humidityporcent);

var humiditycondition = global.get("humidity");

    if (humiditycondition < 20) 
	    {
		msg.payload = "OPEN";
		return msg;
	}
	else if (humiditycondition > 60) 
	 {
		msg.payload = "CLOSE";
		return msg;
	}

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [17 July 2020 08:14 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/6 "2020-07-17T08:14:01Z")

</div>

so you want a switch to turn on and off the data going through MQTT ?  
maybe something like this ? [https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65](https://flows.nodered.org/flow/a985944e789d90e0cd2008d85b7aaa65)  
or this ? [https://cookbook.nodered.org/basic/route-on-context](https://cookbook.nodered.org/basic/route-on-context)

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [20 July 2020 18:13 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/7 "2020-07-20T18:13:35Z")

</div>

The first one is kind what I want but I'm still with problems could you help me?

This is my flow

```auto
[{"id":"c96ece6e.83056","type":"ui_switch","z":"4ce899f9.a739a8","name":"","label":"switch","tooltip":"","group":"a433ab48.55c318","order":0,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"gate","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":450,"y":620,"wires":[["5611098a.b34ba8"]]},{"id":"5611098a.b34ba8","type":"function","z":"4ce899f9.a739a8","name":"control","func":"if (msg.topic === \"statusoc\") {\n context.pass = (msg.payload === true) ? true : false;\n return null; // exit out early as it's just the control\n}\nif (context.pass) {\n return msg; // if enabled pass msg\n}\nreturn null; // or drop it\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":700,"wires":[["197fd51a.8ff1bb"]]},{"id":"c3ba2eb9.c793b","type":"inject","z":"4ce899f9.a739a8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1","crontab":"","once":false,"onceDelay":"","topic":"","payload":"","payloadType":"date","x":524.5,"y":742,"wires":[["5611098a.b34ba8"]]},{"id":"197fd51a.8ff1bb","type":"debug","z":"4ce899f9.a739a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900.5,"y":701,"wires":[]},{"id":"48e83d25.745ce4","type":"ui_switch","z":"4ce899f9.a739a8","name":"","label":"OPEN/CLOSE","tooltip":"","group":"9bfcc815.c4fb78","order":1,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"OPEN","onvalueType":"str","onicon":"","oncolor":"","offvalue":"CLOSE","offvalueType":"str","officon":"","offcolor":"","x":120,"y":400,"wires":[["3cbd4160.3ec38e"]]},{"id":"7123b79.550c748","type":"mqtt out","z":"4ce899f9.a739a8","name":"","topic":"lab/device1","qos":"","retain":"","broker":"9d320b7f.df7158","x":530,"y":360,"wires":[]},{"id":"c88ae30f.18fa7","type":"delay","z":"4ce899f9.a739a8","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":true,"x":310,"y":980,"wires":[["db844c28.5e62f"]]},{"id":"db844c28.5e62f","type":"range","z":"4ce899f9.a739a8","minin":"0","maxin":"550","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload","name":"","x":460,"y":980,"wires":[["f069bbc6.ddd0e8"]]},{"id":"f069bbc6.ddd0e8","type":"function","z":"4ce899f9.a739a8","name":"","func":"var humidityporcent=msg.payload;\n\nglobal.set('humidity',humidityporcent);\n\nvar humiditycondition = global.get(\"humidity\");\n\n if (humiditycondition < 20) \n\t {\n\t\tmsg.payload = \"OPEN\";\n\t\treturn msg;\n\t}\n\telse if (humiditycondition > 60) \n\t {\n\t\tmsg.payload = \"CLOSE\";\n\t\treturn msg;\n\t}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":980,"wires":[["ff947ae2.915578"]]},{"id":"7eb5f2ab.316b1c","type":"arduino in","z":"4ce899f9.a739a8","name":"Mega","pin":"2","state":"ANALOG","arduino":"2962a660.2f6a3a","x":170,"y":980,"wires":[["c88ae30f.18fa7"]]},{"id":"ff947ae2.915578","type":"mqtt out","z":"4ce899f9.a739a8","name":"","topic":"lab/device1","qos":"","retain":"","broker":"9d320b7f.df7158","x":870,"y":980,"wires":[]},{"id":"3cbd4160.3ec38e","type":"function","z":"4ce899f9.a739a8","name":"","func":"var status = msg.payload;\n\nglobal.set('statusoc',status);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":300,"y":400,"wires":[["9f39c5d.38c8a38","7123b79.550c748","92c14aa0.02a698"]]},{"id":"9f39c5d.38c8a38","type":"debug","z":"4ce899f9.a739a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":510,"y":420,"wires":[]},{"id":"92c14aa0.02a698","type":"function","z":"4ce899f9.a739a8","name":"","func":"var statuscondition = global.get(\"statusoc\");\n\n if (statuscondition == \"OPEN\") \n\t {\n\t\tmsg.payload = true;\n\t\treturn msg;\n\t}\n\telse if (statuscondition == \"CLOSE\") \n\t {\n\t\tmsg.payload = false;\n\t\treturn msg;\n\t}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":520,"y":480,"wires":[["5611098a.b34ba8","c74ab78a.dd93e8"]]},{"id":"c74ab78a.dd93e8","type":"debug","z":"4ce899f9.a739a8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":480,"wires":[]},{"id":"a433ab48.55c318","type":"ui_group","z":"","name":"Default","tab":"5a7b2006.42f79","order":1,"disp":true,"width":"6"},{"id":"9bfcc815.c4fb78","type":"ui_group","z":"","name":"control valvula","tab":"f3d4548f.1572b8","order":1,"disp":true,"width":"6","collapse":false},{"id":"9d320b7f.df7158","type":"mqtt-broker","z":"","name":"","broker":"192.168.43.47","port":"1883","clientid":"Hidro","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"2962a660.2f6a3a","type":"arduino-board","z":"","device":"/dev/ttyACM0"},{"id":"5a7b2006.42f79","type":"ui_tab","z":"","name":"Home","icon":"dashboard"},{"id":"f3d4548f.1572b8","type":"ui_tab","z":"","name":"Home 1","icon":"dashboard","disabled":false,"hidden":false}]

```

My problem is with this function

```auto
var statuscondition = global.get("statusoc");

    if (statuscondition == "OPEN") 
	    {
		msg.payload = true;
		return msg;
	}
	else if (statuscondition == "CLOSE") 
	 {
		msg.payload = false;
		return msg;
	}

```

related with this another function

```auto
if (msg.topic === "gate") {
    context.pass = (msg.payload === true) ? true : false;
    return null; // exit out early as it's just the control
}
if (context.pass) {
    return msg; // if enabled pass msg
}
return null; // or drop it

```

so I know that my problem is the mg.topic == "gate" how can I do to make my first funciton to msg.topic == "gate"

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 July 2020 19:05 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/8 "2020-07-20T19:05:44Z")

</div>

Where do you set msg.topic to 'gate'?

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [20 July 2020 19:29 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/9 "2020-07-20T19:29:35Z")

</div>

![Sin título](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/c/4ca26dec1a6b6d9a5b540f0d0d0fdefdddb6d1bb.png)  
from a switch dashboard node but I want to replace for a function

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 July 2020 20:09 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/10 "2020-07-20T20:09:05Z")

</div>

So let me see if I understand, you say

> [@lalo](#):
>
> from a switch dashboard node but I want to replace for a function

so are you saying you want to replace the `ui-switch` bode with a `function` node? If so, then what will feed the `function` node?

If not then what do you mean?

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [20 July 2020 20:16 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/11 "2020-07-20T20:16:22Z")

</div>

> [@zenofmud](#):
>
> so are you saying you want to replace the `ui-switch` bode with a `function` node? If so, then what will feed the `function` node?

yeah that's right I will feed it with this function ...

```auto
var statuscondition = global.get("statusoc");

    if (statuscondition == "OPEN") 
	    {
		msg.payload = true;
		return msg;
	}
	else if (statuscondition == "CLOSE") 
	 {
		msg.payload = false;
		return msg;
	}

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [20 July 2020 20:48 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/12 "2020-07-20T20:48:51Z")

</div>

Well then you have teo set the msg.topic in that function.

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [20 July 2020 21:14 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/13 "2020-07-20T21:14:41Z")

</div>

I tried with this but it did't work

```auto
var statuscondition = global.get("statusoc");

    if (statuscondition == "OPEN") 
	    {
		msg.topic = true;
		return msg;
	}
	else if (statuscondition == "CLOSE") 
	 {
		msg.topic = false;
		return msg;
	}

```

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [20 July 2020 21:51 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/14 "2020-07-20T21:51:06Z")

</div>

So now you set `msg.topic` true or false. But up above you test ` ==="gate"` so you need to sort out one or other idea.

---

<div class="post-metadata">

**Author:** ![lalo](https://avatars.discourse-cdn.com/v4/letter/l/f4b2a3/32.png) [@lalo](https://discourse.nodered.org/u/lalo)\
**Post date:** [20 July 2020 21:54 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/15 "2020-07-20T21:54:28Z")

</div>

Like this?

```auto
if (msg.topic) {
    context.pass = (msg.payload === true) ? true : false;
    return null; // exit out early as it's just the control
}
if (context.pass) {
    return msg; // if enabled pass msg
}
return null; // or drop it

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [3 August 2020 21:54 UTC](https://discourse.nodered.org/t/problems-with-mqtt-node-msg-payload-interrupt/30167/16 "2020-08-03T21:54:29Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
