The first one is kind what I want but I'm still with problems could you help me?
This is my flow
[{"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
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
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"