[Solved] How to realise auto-control and manual-control of the light?

Hi,

I have a question about the IoT system by using MQTT nodes. I want to realize that people can choose to manually and automatically control the lights in the dashboard, like the flow in the figure below, but the problem is that if I turn off the automatic control and use the manual control, the lights will only listen to the instructions for a short time then continue to control automatically, so I think the problem is that the flow of automatic control is not really turned off. Please help me how to really close the mqtt flow of this automatic control?


1

Thanks!
Meng

Instead of the gate, use change node to set a flow variable.
If the ui switch is set to manual, set variable auto off.

Then use a "normal" switch node you can pass or block based on the variable (which you can insert between the 2 mqtt nodes).

Thanks for your reply. Here is the flow that I modified, but still can not solve the problem, maybe its because I linked them in the wrong way. Could you please give me some more details. Thanks!

[{"id":"dc9576df.df7678","type":"mqtt in","z":"bf6ed410.bc2df8","name":"up","topic":"molly-pycom-device/devices/orangefipy/up","qos":"2","datatype":"auto","broker":"fb1bb5ab.f1c4c8","x":210,"y":800,"wires":[["980184f9.cab908"]]},{"id":"be59d29e.3e5a5","type":"function","z":"bf6ed410.bc2df8","name":"light downlink","func":"var payload = msg.payload.payload_fields.light;\n\nreturn {\n  topic: 'molly-pycom-device/devices/orangefipy/down',\n  payload: {\n    port: 2,\n    confirmed: true,\n    payload_raw: Buffer.from(\"\"+payload).toString('base64'),\n    schedule: 'last'\n  }\n};","outputs":1,"noerr":0,"x":560,"y":800,"wires":[["49d1f256.f0fcbc"]]},{"id":"49d1f256.f0fcbc","type":"mqtt out","z":"bf6ed410.bc2df8","name":"","topic":"molly-pycom-device/devices/orangefipy/down","qos":"0","retain":"false","broker":"fb1bb5ab.f1c4c8","x":970,"y":800,"wires":[]},{"id":"d0f7d187.5e49e","type":"mqtt out","z":"bf6ed410.bc2df8","name":"down","topic":"molly-pycom-device/devices/orangefipy/down","qos":"1","retain":"false","broker":"fb1bb5ab.f1c4c8","x":710,"y":960,"wires":[]},{"id":"38789e18.c58752","type":"function","z":"bf6ed410.bc2df8","name":"manual downlink","func":"var payload = msg.payload;\nreturn {\n  topic: 'molly-pycom-device/devices/orangefipy/down',\n  payload: {\n    port: 2,\n    confirmed: true,\n    payload_raw: Buffer.from(\"\"+payload).toString('base64'),\n    schedule: 'replace'\n  }\n};","outputs":1,"noerr":0,"x":510,"y":960,"wires":[["d0f7d187.5e49e"]]},{"id":"980184f9.cab908","type":"json","z":"bf6ed410.bc2df8","name":"","property":"payload","action":"","pretty":false,"x":350,"y":800,"wires":[["be59d29e.3e5a5"]]},{"id":"ab91476e.a80c68","type":"ui_switch","z":"bf6ed410.bc2df8","name":"","label":"switch","tooltip":"","group":"73325e5b.3dcd4","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"molly-pycom-device/devices/orangefipy/down","style":"","onvalue":"[48]","onvalueType":"bin","onicon":"","oncolor":"","offvalue":"[50,48,48]","offvalueType":"bin","officon":"","offcolor":"","x":310,"y":960,"wires":[["38789e18.c58752"]]},{"id":"c27f44a8.7cef08","type":"change","z":"bf6ed410.bc2df8","name":"change","rules":[{"t":"set","p":"auto","pt":"flow","to":"payload?true:false","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":880,"wires":[["d51d19c4.a200a8"]]},{"id":"d51d19c4.a200a8","type":"switch","z":"bf6ed410.bc2df8","name":"","property":"auto","propertyType":"flow","rules":[{"t":"false"}],"checkall":"true","repair":false,"outputs":1,"x":630,"y":880,"wires":[["49d1f256.f0fcbc"]]},{"id":"b96424e3.d4e328","type":"ui_switch","z":"bf6ed410.bc2df8","name":"","label":"auto switch","tooltip":"","group":"73325e5b.3dcd4","order":3,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"","oncolor":"","offvalue":"false","offvalueType":"bool","officon":"","offcolor":"","x":250,"y":880,"wires":[["c27f44a8.7cef08"]]},{"id":"fb1bb5ab.f1c4c8","type":"mqtt-broker","z":"","name":"","broker":"eu.thethings.network","port":"1883","tls":"","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"2","birthRetain":"false","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"73325e5b.3dcd4","type":"ui_group","z":"","name":"Light","tab":"ce75d44a.fb5a18","disp":true,"width":"6","collapse":false},{"id":"ce75d44a.fb5a18","type":"ui_tab","z":"","name":"Lora","icon":"dashboard","order":2}]

Not loaded your flow (a picture is worth a thousand lines of flow by the way in cases like this :grinning: ) but I imagine that you don't have a switch node between your light downlink function node and the mqtt-out node.

The switch node is what will block/allow the message based on your variable.

As I understand your question, you want to stop the automatic part of your flow when you manually change your on/off switch.

If this is the correct understanding, you can simply have your switch send a message to the automatic part of your flow (like set a boolean to false) which instructs the automatic process not to process. But this is not without complications (and more code), so....

Some people would simply have another switch for "automatic or manually mode" and add that to your flow and your UI to control which which process you want (manual or automatic)

Did I misunderstand your question?

I tried several times, and finally get your points! thanks!

No, your understanding is right. Actually I need a switch node between two mqtt nodes, and after I added it, it realised.

Thanks! it solved.

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