# Value through switch permanently

**URL:** https://discourse.nodered.org/t/value-through-switch-permanently/30102
**Category:** Dashboard
**Created:** [15 July 2020 06:42 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102 "2020-07-15T06:42:51Z")
**Posts on this page:** 10
**Page:** 5

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [17 July 2020 10:10 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/81 "2020-07-17T10:10:43Z")

</div>

Point #2: After Setting two switches to "ON"  
Which looks like it is per the picture below. #1 and #3 on.

Point #3: What do you mean? After the first inject.......

This is going to be getting .... a lot of messages a second from what you are telling me.  
So?

Point #3 button picture.  
What happened there? The two switches are now off. Are you saying you didn't do that?

Here is my system with **multiple** pressses of the `inject` node and the correct data is getting through and the switches are remaining the same.

 ![Screenshot from 2020-07-17 20-08-23](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/9/396b03502234bb51d0e7353fcf4ab70a2d97a569.png)

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [17 July 2020 10:15 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/82 "2020-07-17T10:15:35Z")

</div>

1. thats right
2. thats right

my switches dont stay at theyre position. my flow behavior is different.  
i dont know why but it is so ☹

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [17 July 2020 10:16 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/83 "2020-07-17T10:16:27Z")

</div>

Paste the code.....

There is no other way to work out the problem.

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [17 July 2020 10:18 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/84 "2020-07-17T10:18:49Z")

</div>

Ok here it is:

```auto
[{"id":"4499275c.a97338","type":"function","z":"af61c022.bc96e","name":"","func":"msg = {\"topic\":\"ATESTEO/Wolfsburg/W16\",\"payload\":{\"MQTTWert1\":\"25.1\",\"MQTTWert1name\":\"T_BoxenLuft\",\"MQTTWert2\":\"-101\",\"MQTTWert2name\":\"N_EMA_VL\",\"MQTTWert3\":\"932\",\"MQTTWert3name\":\"n_Antrieb\",\"MQTTWert4\":\"269\",\"MQTTWert4name\":\"M_Antrieb\",\"Status\":\"Läuft\"},\"qos\":1,\"retain\":false,\"_topic\":\"ATESTEO/Wolfsburg/W16\",\"_msgid\":\"3f4512b0.dc5bee\",\"kColor\":\"black\",\"vColor\":\"black\",\"template\":\"<html>\\n<head>\\n<style>\\ntable.FixedTable\\n{\\n table-layout: fixed;\\n border: 0;\\n}\\n</style> \\n</head>\\n<body>\\n<table class=\\\"FixedTable\\\">\\n <tbody>\\n <tr ng-repeat=\\\"(k,v) in msg.payload\\\" ng-if=\\\"k != 'Item'\\\">\\n <td style=\\\"width: 250; color:{{msg.kColor}}\\\">{{k}}</td>\\n <td style=\\\"text-align:justify; color:{{msg.vColor}}\\\">{{v}}</td>\\n </tr>\\n </tbody>\\n</table>\\n</body>\\n</html>\",\"color\":\"lime\"};\nreturn msg;","outputs":1,"noerr":0,"x":3740,"y":1860,"wires":[["cdd158f.53ff5a8","fb660729.4f3078","3bce696a.0ad486","9235f258.0d0fa","80a585c.1926578"]]},{"id":"fed3f617.6dba38","type":"inject","z":"af61c022.bc96e","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3580,"y":1860,"wires":[["4499275c.a97338"]]},{"id":"cdd158f.53ff5a8","type":"debug","z":"af61c022.bc96e","name":"A","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":3720,"y":1920,"wires":[]},{"id":"fb660729.4f3078","type":"change","z":"af61c022.bc96e","name":"Part 1","rules":[{"t":"set","p":"value","pt":"msg","to":"payload.MQTTWert1","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"payload.MQTTWert1name","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"move","p":"value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3910,"y":1740,"wires":[["a038ac37.4bf61","ad1d2ea7.89726"]]},{"id":"3bce696a.0ad486","type":"change","z":"af61c022.bc96e","name":"Part 2","rules":[{"t":"set","p":"value","pt":"msg","to":"payload.MQTTWert2","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"payload.MQTTWert2name","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"move","p":"value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3910,"y":1820,"wires":[["1579598d.e8fe96","d542a959.78c438"]]},{"id":"9235f258.0d0fa","type":"change","z":"af61c022.bc96e","name":"Part 3","rules":[{"t":"set","p":"value","pt":"msg","to":"payload.MQTTWert3","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"payload.MQTTWert3name","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"move","p":"value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3910,"y":1910,"wires":[["397de4.6c65021c","82057e6e.fa098"]]},{"id":"80a585c.1926578","type":"change","z":"af61c022.bc96e","name":"Part 4","rules":[{"t":"set","p":"value","pt":"msg","to":"payload.MQTTWert4","tot":"msg"},{"t":"set","p":"topic","pt":"msg","to":"payload.MQTTWert4name","tot":"msg"},{"t":"delete","p":"payload","pt":"msg"},{"t":"move","p":"value","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3910,"y":1980,"wires":[["9055e4cd.054608","d6b3b106.10e2b"]]},{"id":"a038ac37.4bf61","type":"function","z":"af61c022.bc96e","name":"","func":"// Look for message from `switch`\n// and set context.\n\nif (msg.payload == \"true\")\n{\n context.set(\"ONOFF\",\"1\");\n node.status({fill:\"green\",shape:\"dot\",text:\"PASS\"});\n return;\n} else\nif (msg.payload == \"false\")\n{\n context.set(\"ONOFF\",\"0\");\n node.status({fill:\"red\",shape:\"dot\",text:\"BLOCK\"});\n return;\n}\nvar pass = context.get(\"ONOFF\") || 0;\nif (pass == \"0\")\n{\n //msg.payload = 0;\n return;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":4370,"y":1740,"wires":[["6c991197.d1a23","17d63c2a.a5a5f4"]]},{"id":"ad1d2ea7.89726","type":"ui_switch","z":"af61c022.bc96e","name":"","label":"{{msg.topic}}","tooltip":"","group":"4590e919.a4d868","order":1,"width":"3","height":"1","passthru":false,"decouple":"false","topic":"","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":4040,"y":1710,"wires":[["a038ac37.4bf61","72738f62.28c0a"]]},{"id":"1579598d.e8fe96","type":"ui_switch","z":"af61c022.bc96e","name":"","label":"{{msg.topic}}","tooltip":"","group":"4590e919.a4d868","order":2,"width":"3","height":"1","passthru":false,"decouple":"false","topic":"ATESTEO/Wolfsburg/W16","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":4040,"y":1780,"wires":[["d542a959.78c438"]]},{"id":"d542a959.78c438","type":"function","z":"af61c022.bc96e","name":"","func":"// Look for message from `switch`\n// and set context.\n\nif (msg.payload == \"true\")\n{\n context.set(\"ONOFF\",\"1\");\n node.status({fill:\"green\",shape:\"dot\",text:\"PASS\"});\n return;\n} else\nif (msg.payload == \"false\")\n{\n context.set(\"ONOFF\",\"0\");\n node.status({fill:\"red\",shape:\"dot\",text:\"BLOCK\"});\n return;\n}\nvar pass = context.get(\"ONOFF\") || 0;\nif (pass == \"0\")\n{\n //msg.payload = 0;\n return;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":4370,"y":1820,"wires":[["6353f523.ae4e5c","85063ef8.41c77"]]},{"id":"397de4.6c65021c","type":"ui_switch","z":"af61c022.bc96e","name":"","label":"{{msg.topic}}","tooltip":"","group":"4590e919.a4d868","order":3,"width":"3","height":"1","passthru":false,"decouple":"false","topic":"ATESTEO/Wolfsburg/W16","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":4040,"y":1870,"wires":[["82057e6e.fa098"]]},{"id":"82057e6e.fa098","type":"function","z":"af61c022.bc96e","name":"","func":"// Look for message from `switch`\n// and set context.\n\nif (msg.payload == \"true\")\n{\n context.set(\"ONOFF\",\"1\");\n node.status({fill:\"green\",shape:\"dot\",text:\"PASS\"});\n return;\n} else\nif (msg.payload == \"false\")\n{\n context.set(\"ONOFF\",\"0\");\n node.status({fill:\"red\",shape:\"dot\",text:\"BLOCK\"});\n return;\n}\nvar pass = context.get(\"ONOFF\") || 0;\nif (pass == \"0\")\n{\n //msg.payload = 0;\n return;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":4370,"y":1910,"wires":[["8f38ba64.dc5d38","8cd5d1b6.95fcf"]]},{"id":"9055e4cd.054608","type":"ui_switch","z":"af61c022.bc96e","name":"","label":"{{msg.topic}}","tooltip":"","group":"4590e919.a4d868","order":4,"width":"3","height":"1","passthru":false,"decouple":"false","topic":"ATESTEO/Wolfsburg/W16","style":"","onvalue":"true","onvalueType":"str","onicon":"","oncolor":"","offvalue":"false","offvalueType":"str","officon":"","offcolor":"","x":4040,"y":1950,"wires":[["d6b3b106.10e2b"]]},{"id":"d6b3b106.10e2b","type":"function","z":"af61c022.bc96e","name":"","func":"// Look for message from `switch`\n// and set context.\n\nif (msg.payload == \"true\")\n{\n context.set(\"ONOFF\",\"1\");\n node.status({fill:\"green\",shape:\"dot\",text:\"PASS\"});\n return;\n} else\nif (msg.payload == \"false\")\n{\n context.set(\"ONOFF\",\"0\");\n node.status({fill:\"red\",shape:\"dot\",text:\"BLOCK\"});\n return;\n}\nvar pass = context.get(\"ONOFF\") || 0;\nif (pass == \"0\")\n{\n //msg.payload = 0;\n return;\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":4370,"y":1980,"wires":[["475a584d.85b9b8","57d50499.2e0bac"]]},{"id":"6c991197.d1a23","type":"debug","z":"af61c022.bc96e","name":"1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":4500,"y":1740,"wires":[]},{"id":"17d63c2a.a5a5f4","type":"debug","z":"af61c022.bc96e","name":"a","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":4500,"y":1770,"wires":[]},{"id":"72738f62.28c0a","type":"debug","z":"af61c022.bc96e","name":"From switch","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":4390,"y":1710,"wires":[]},{"id":"6353f523.ae4e5c","type":"debug","z":"af61c022.bc96e","name":"2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":4500,"y":1820,"wires":[]},{"id":"85063ef8.41c77","type":"debug","z":"af61c022.bc96e","name":"b","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":4500,"y":1850,"wires":[]},{"id":"8f38ba64.dc5d38","type":"debug","z":"af61c022.bc96e","name":"3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":4500,"y":1910,"wires":[]},{"id":"8cd5d1b6.95fcf","type":"debug","z":"af61c022.bc96e","name":"c","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":4500,"y":1940,"wires":[]},{"id":"475a584d.85b9b8","type":"debug","z":"af61c022.bc96e","name":"4","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":4500,"y":1980,"wires":[]},{"id":"57d50499.2e0bac","type":"debug","z":"af61c022.bc96e","name":"d","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":4500,"y":2010,"wires":[]},{"id":"4590e919.a4d868","type":"ui_group","name":"Group 3","tab":"1ef82eaa.71cac1","order":3,"disp":true,"width":6},{"id":"1ef82eaa.71cac1","type":"ui_tab","z":"","name":"W16-Chart","icon":"dashboard","order":11,"disabled":false,"hidden":false}]

```

But i have a working solution with my changed flow...

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [17 July 2020 10:23 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/85 "2020-07-17T10:23:49Z")

</div>

There is something happening which either you aren't telling me, or is systemically doing things you don't know.

I load the code and it works exactly as expected.

I turn on switch 1 and 3 and sit there bashing the `inject` node and only get `a` and `c` outputs. Repeatedly.

How your switches are being turned off is way beyond my skills.

I have another thing to mention but will do it in another post to help keep things separate.

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [17 July 2020 10:25 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/86 "2020-07-17T10:25:52Z")

</div>

The message which is being injected:

It is a cut down version which will contain 18 messages.

You will be receiving a few messages at a pretty good rate which will require a lot of number crunching.

The sample message you gave me has a **lot** of overhead which you say is needed.... for.....? Dunno.

Stripping this at the start will greatly help with processing the messages later on.

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [17 July 2020 10:25 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/87 "2020-07-17T10:25:53Z")

</div>

I am sorry, i cant tell you why this happens.  
I agree to cuting the msg down to needed payload at the entry of that part of the flow.  
but i think i dont know how. u want to get rid of the remplate as i understand?  
For the payload : i thought deleting with a Change node is enough...

---

<div class="post-metadata">

### Author: ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)
#### Post date: [17 July 2020 10:29 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/88 "2020-07-17T10:29:01Z")

</div>

It is what it is.

I can't help you any more.

What I posted works to do what you want - as best I can understand - yet it does _weird things_ on your machine, which it doesn't do on mine.

Good luck.

---

<div class="post-metadata">

### Author: ![Chorum](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chorum/32/47644_2.png) [@Chorum](https://discourse.nodered.org/u/Chorum)
#### Post date: [17 July 2020 10:29 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/89 "2020-07-17T10:29:54Z")

</div>

Thanks for your help!

---

<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: [16 August 2020 10:29 UTC](https://discourse.nodered.org/t/value-through-switch-permanently/30102/90 "2020-08-16T10:29:54Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/value-through-switch-permanently/30102.md?page=4)
