# Switch with indicator

**URL:** <https://discourse.nodered.org/t/switch-with-indicator/14125>\
**Category:** Dashboard\
**Created:** [8 August 2019 07:20 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125 "2019-08-08T07:20:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adas1978](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Adas1978](https://discourse.nodered.org/u/Adas1978)\
**Post date:** [8 August 2019 07:20 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/1 "2019-08-08T07:20:38Z")

</div>

Hi Guys,

I use the PLC for my house. Between my PLC and Node Red I use Modbus communication. I would like to use special switch with indicator. I want to use PLC digital output as feedback at the switch. I would use the same switch to control the PLC output. When the PLC output changes, that changes the indicator of the switch. My problem is if the PLC output is controlled outside of Node Red. The status of the switch does not change.  
Sorry for my English 😉

Thanks, for the help!

Adam

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 August 2019 08:24 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/2 "2019-08-08T08:24:12Z")

</div>

I presume this is a node red dashboard switch you are talking about.  
If so then to solve the problem you need to pickup the current PLC output state in node-red and feed it into the front of the switch, so the switch will change if the output changes.

---

<div class="post-metadata">

**Author:** ![Adas1978](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Adas1978](https://discourse.nodered.org/u/Adas1978)\
**Post date:** [8 August 2019 09:52 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/3 "2019-08-08T09:52:23Z")

</div>

Thanks for the reply. I've tried this solution before. It used at one PLC output. When I copied it, the others didn't work properly.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [8 August 2019 10:17 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/4 "2019-08-08T10:17:37Z")

</div>

Well that is the only way to do it, you cannot make the switch follow the PLC output unless you know what the output is. The solution is to try again and find out what the problem was the first time.

---

<div class="post-metadata">

**Author:** ![krambriw](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/krambriw/32/5429_2.png) [@krambriw](https://discourse.nodered.org/u/krambriw)\
**Post date:** [9 August 2019 05:10 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/5 "2019-08-09T05:10:42Z")

</div>

Try again with a smaller simpler flow and if it doesn't work, share the flow so people have something to investigate for you

---

<div class="post-metadata">

**Author:** ![Adas1978](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Adas1978](https://discourse.nodered.org/u/Adas1978)\
**Post date:** [9 August 2019 06:06 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/6 "2019-08-09T06:06:23Z")

</div>

So this my simple flow:

[{"id":"e4e6562f.f1a698","type":"modbus-write","z":"350f034d.94afcc","name":"Mosok\_vil\_write","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"15002","quantity":"1","server":"4d5e1b27.37ea5c","x":1020,"y":80,"wires":[,]},{"id":"ec77ff58.f3d2","type":"ui\_switch","z":"350f034d.94afcc","name":"","label":"Mosokonyha ","tooltip":"","group":"b7362e82.2a474","order":13,"width":"0","height":"0","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-power-off","oncolor":"green","offvalue":"false","offvalueType":"bool","officon":"fa-power-off","offcolor":"red","x":700,"y":80,"wires":[["e4e6562f.f1a698"]]},{"id":"7dece348.20398c","type":"modbus-read","z":"350f034d.94afcc","name":"Mosok\_vilagitas","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"15002","quantity":"1","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"4d5e1b27.37ea5c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":220,"y":80,"wires":[,["d401976f.87f3b"]]},{"id":"d401976f.87f3b","type":"function","z":"350f034d.94afcc","name":" Decode array","func":"// The message returned from the read node is an\n// array as there could be multiple registers returned\n// This reads the first value in the array.\nm = msg.payload.data[0]\nreturn {payload: m};\n","outputs":1,"noerr":0,"x":420,"y":80,"wires":[["ec77ff58.f3d2"]]},{"id":"4d5e1b27.37ea5c","type":"modbus-client","z":"350f034d.94afcc","name":"Mester","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.1.144","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit\_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectTimeout":2000},{"id":"b7362e82.2a474","type":"ui\_group","z":"350f034d.94afcc","name":"Foldszint vilagítas","tab":"ff28c5b9.5fd548","disp":true,"width":"6","collapse":false},{"id":"ff28c5b9.5fd548","type":"ui\_tab","z":"350f034d.94afcc","name":"Mester u. 1/b.","icon":"fa-home","order":1,"disabled":false,"hidden":false}]

---

<div class="post-metadata">

**Author:** ![Adas1978](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Adas1978](https://discourse.nodered.org/u/Adas1978)\
**Post date:** [9 August 2019 06:11 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/7 "2019-08-09T06:11:49Z")

</div>

> [@Adas1978](#):
>
> [{"id":"e4e6562f.f1a698","type":"modbus-write","z":"350f034d.94afcc","name":"Mosok\_vil\_write","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"15002","quantity":"1","server":"4d5e1b27.37ea5c","x":1020,"y":80,"wires":[,]},{"id":"ec77ff58.f3d2","type":"ui\_switch","z":"350f034d.94afcc","name":"","label":"Mosokonyha ","tooltip":"","group":"b7362e82.2a474","order":13,"width":"0","height":"0","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-power-off","oncolor":"green","offvalue":"false","offvalueType":"bool","officon":"fa-power-off","offcolor":"red","x":700,"y":80,"wires":[["e4e6562f.f1a698"]]},{"id":"7dece348.20398c","type":"modbus-read","z":"350f034d.94afcc","name":"Mosok\_vilagitas","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"15002","quantity":"1","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"4d5e1b27.37ea5c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":220,"y":80,"wires":[,["d401976f.87f3b"]]},{"id":"d401976f.87f3b","type":"function","z":"350f034d.94afcc","name":" Decode array","func":"// The message returned from the read node is an\n// array as there could be multiple registers returned\n// This reads the first value in the array.\nm = msg.payload.data[0]\nreturn {payload: m};\n","outputs":1,"noerr":0,"x":420,"y":80,"wires":[["ec77ff58.f3d2"]]},{"id":"4d5e1b27.37ea5c","type":"modbus-client","z":"350f034d.94afcc","name":"Mester","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.1.144","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit\_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectTimeout":2000},{"id":"b7362e82.2a474","type":"ui\_group","z":"350f034d.94afcc","name":"Foldszint vilagítas","tab":"ff28c5b9.5fd548","disp":true,"width":"6","collapse":false},{"id":"ff28c5b9.5fd548","type":"ui\_tab","z":"350f034d.94afcc","name":"Mester u. 1/b.","icon":"fa-home","order":1,"disabled":false,"hidden":false}]

 ![picture](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/2/22d4182e02d2813a3772ce82b0a133e2ef836a30.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 August 2019 07:31 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/8 "2019-08-09T07:31:54Z")

</div>

Unfortunately the flow is not importable. Please see this post for how to share the flow. You can edit the previous post to insert the backticks.

> [@How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506):
>
> To share code samples or flow json in this forum, you need to take care to format it properly so that it is displayed correctly. The easiest way to do that is to click the 'Preformatted Text' button in the toolbar: [image] Then paste in your code or flow json. You should end up with three back-tick characters - ``` - on their own line before and after the code. On standard US English keyboards, this is on the same key as the ~ character. Using the backticks will ens…

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 August 2019 07:33 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/9 "2019-08-09T07:33:03Z")

</div>

However before doing that put a debug node on the output of the first and second nodes and see what is coming from them.

---

<div class="post-metadata">

**Author:** ![Adas1978](https://avatars.discourse-cdn.com/v4/letter/a/f9ae1b/32.png) [@Adas1978](https://discourse.nodered.org/u/Adas1978)\
**Post date:** [9 August 2019 08:23 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/10 "2019-08-09T08:23:03Z")

</div>

```auto
[{"id":"e4e6562f.f1a698","type":"modbus-write","z":"350f034d.94afcc","name":"Mosok_vil_write","showStatusActivities":true,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"15002","quantity":"1","server":"4d5e1b27.37ea5c","x":1020,"y":80,"wires":[[],[]]},{"id":"ec77ff58.f3d2","type":"ui_switch","z":"350f034d.94afcc","name":"","label":"Mosokonyha ","tooltip":"","group":"b7362e82.2a474","order":13,"width":"0","height":"0","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"bool","onicon":"fa-power-off","oncolor":"green","offvalue":"false","offvalueType":"bool","officon":"fa-power-off","offcolor":"red","x":700,"y":80,"wires":[["e4e6562f.f1a698"]]},{"id":"7dece348.20398c","type":"modbus-read","z":"350f034d.94afcc","name":"Mosok_vilagitas","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"Coil","adr":"15002","quantity":"1","rate":"1","rateUnit":"s","delayOnStart":false,"startDelayTime":"","server":"4d5e1b27.37ea5c","useIOFile":false,"ioFile":"","useIOForPayload":false,"x":220,"y":80,"wires":[[],["d401976f.87f3b"]]},{"id":"d401976f.87f3b","type":"function","z":"350f034d.94afcc","name":" Decode array","func":"// The message returned from the read node is an\n// array as there could be multiple registers returned\n// This reads the first value in the array.\nm = msg.payload.data[0]\nreturn {payload: m};\n","outputs":1,"noerr":0,"x":420,"y":80,"wires":[["ec77ff58.f3d2"]]},{"id":"4d5e1b27.37ea5c","type":"modbus-client","z":"350f034d.94afcc","name":"Mester","clienttype":"tcp","bufferCommands":true,"stateLogEnabled":false,"tcpHost":"192.168.1.144","tcpPort":"502","tcpType":"DEFAULT","serialPort":"/dev/ttyUSB","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":1,"commandDelay":1,"clientTimeout":1000,"reconnectTimeout":2000},{"id":"b7362e82.2a474","type":"ui_group","z":"350f034d.94afcc","name":"Foldszint vilagítas","tab":"ff28c5b9.5fd548","disp":true,"width":"6","collapse":false},{"id":"ff28c5b9.5fd548","type":"ui_tab","z":"350f034d.94afcc","name":"Mester u. 1/b.","icon":"fa-home","order":1,"disabled":false,"hidden":false}]

```

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [9 August 2019 08:34 UTC](https://discourse.nodered.org/t/switch-with-indicator/14125/11 "2019-08-09T08:34:37Z")

</div>

Note that you have specified that the switch sends the boolean values true and false. This means that you must make sure that the value you are passing it is also a boolean value true or false, otherwise the switch will not understand the value it is being sent.  
So as suggested put debug nodes on the modbus read and the function node and check that they are sending the correct values.
