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

**URL:** https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352
**Category:** General
**Created:** [28 February 2020 04:38 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352 "2020-02-28T04:38:55Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![molly](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@molly](https://discourse.nodered.org/u/molly)
#### Post date: [28 February 2020 04:38 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/1 "2020-02-28T04:38:55Z")

</div>

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?

 ![捕获](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/0/3030c2c517ac1877cb18ee9d1fe4b7ef7be9a01b.jpeg)  
 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/a/0ae40a2ed571b8dea6d03336d3332a57d935347b.jpeg)

Thanks!  
Meng

---

<div class="post-metadata">

### Author: ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)
#### Post date: [28 February 2020 05:31 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/2 "2020-02-28T05:31:17Z")

</div>

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

 ![Screenshot 2020-02-28 at 06.31.57](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/e/3e7d089b14aa12c570d46e972ff8172a61bfc7e7.jpeg)

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

 ![Screenshot 2020-02-28 at 06.27.35](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/038daea416208bbc6fdd33640497019931c82843.jpeg)

---

<div class="post-metadata">

### Author: ![molly](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@molly](https://discourse.nodered.org/u/molly)
#### Post date: [28 February 2020 06:05 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/3 "2020-02-28T06:05:17Z")

</div>

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!

```auto
[{"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}]

```

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [28 February 2020 08:52 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/4 "2020-02-28T08:52:22Z")

</div>

Not loaded your flow (a picture is worth a thousand lines of flow by the way in cases like this 😀 ) 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.

---

<div class="post-metadata">

### Author: ![unixneo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/unixneo/32/17441_2.png) [@unixneo](https://discourse.nodered.org/u/unixneo)
#### Post date: [28 February 2020 10:34 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/5 "2020-02-28T10:34:33Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![molly](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@molly](https://discourse.nodered.org/u/molly)
#### Post date: [28 February 2020 14:43 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/6 "2020-02-28T14:43:37Z")

</div>

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

---

<div class="post-metadata">

### Author: ![molly](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@molly](https://discourse.nodered.org/u/molly)
#### Post date: [28 February 2020 14:46 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/7 "2020-02-28T14:46:18Z")

</div>

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

---

<div class="post-metadata">

### Author: ![molly](https://avatars.discourse-cdn.com/v4/letter/m/df788c/32.png) [@molly](https://discourse.nodered.org/u/molly)
#### Post date: [28 February 2020 14:46 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/8 "2020-02-28T14:46:46Z")

</div>

Thanks! it solved.

---

<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: [13 March 2020 14:46 UTC](https://discourse.nodered.org/t/solved-how-to-realise-auto-control-and-manual-control-of-the-light/22352/9 "2020-03-13T14:46:48Z")

</div>

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