# Switch feedback

**URL:** <https://discourse.nodered.org/t/switch-feedback/50925>\
**Category:** General\
**Created:** [12 September 2021 17:58 UTC](https://discourse.nodered.org/t/switch-feedback/50925 "2021-09-12T17:58:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![holographic](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@holographic](https://discourse.nodered.org/u/holographic)\
**Post date:** [12 September 2021 17:58 UTC](https://discourse.nodered.org/t/switch-feedback/50925/1 "2021-09-12T17:58:24Z")

</div>

Hello all,  
I would like to integrate a switch feedback.

Difficult to explain:  
There are 3 switches that output different values in PWM.  
Switch 1 =100%.  
Switch 2 = 50%  
Switch 3 = 20%

When I press switch 1, switch 2 and 3 must be off,  
If I press switch 1 and after press switch 2, switch 1 must be off again, etc.

I tried to work with Boolean Logic but it did not work at all.  
Do you have an idea?  
attached is the flow...

Thanks in advance

Alex

```auto
[
    {
        "id": "10c6af45c4a00278",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": ""
    },
    {
        "id": "cea7b928d75b848f",
        "type": "function",
        "z": "10c6af45c4a00278",
        "name": "Start / Stop",
        "func": "if (msg.payload >= 1) {\n msg.payload = 'b1.txt=\"Stop\"';\n var textBuf = Buffer.from(msg.payload, 'ascii');\n var postFixBuf = new Buffer(\"FFFFFF\", \"hex\");\n\nmsg.payload = Buffer.concat([textBuf, postFixBuf]);\n} else {\n msg.payload = 'b1.txt=\"Start\"';\n var textBuf = Buffer.from(msg.payload, 'ascii');\n var postFixBuf = new Buffer(\"FFFFFF\", \"hex\");\n\nmsg.payload = Buffer.concat([textBuf, postFixBuf]);\n\n}\n\nreturn msg;\n",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1070,
        "y": 120,
        "wires": [
            [
                "51f2965a0fa007c3"
            ]
        ]
    },
    {
        "id": "ca9d7c91862908d4",
        "type": "toggle",
        "z": "10c6af45c4a00278",
        "name": "Schalter",
        "onOffTopic": "",
        "onValue": "1",
        "onType": "str",
        "offValue": "0",
        "offType": "str",
        "toggleTopic": "",
        "toggleValue": "4",
        "toggleType": "num",
        "passOnOff": "",
        "x": 960,
        "y": 180,
        "wires": [
            [
                "c2ab7708e2d72703",
                "cea7b928d75b848f",
                "a66ab220fa4f8124"
            ]
        ]
    },
    {
        "id": "51f2965a0fa007c3",
        "type": "serial out",
        "z": "10c6af45c4a00278",
        "name": "NEXTION",
        "serial": "f527860f.a985e8",
        "x": 1280,
        "y": 120,
        "wires": []
    },
    {
        "id": "c2ab7708e2d72703",
        "type": "function",
        "z": "10c6af45c4a00278",
        "name": "Analogumrechnung",
        "func": "if (msg.payload >= 1) {\n msg.payload = 100;\n} else {\n msg.payload = 0;\n}\nreturn msg;\n\n//msg.payload = 20; Nur für Analogumwandlug\n//return msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 1170,
        "y": 180,
        "wires": [
            [
                "0733141f4dcfe525"
            ]
        ]
    },
    {
        "id": "0733141f4dcfe525",
        "type": "rpi-gpio out",
        "z": "10c6af45c4a00278",
        "name": "",
        "pin": "22",
        "set": "",
        "level": "0",
        "freq": "100",
        "out": "pwm",
        "x": 1360,
        "y": 180,
        "wires": []
    },
    {
        "id": "a66ab220fa4f8124",
        "type": "rpi-gpio out",
        "z": "10c6af45c4a00278",
        "name": "FU",
        "pin": "38",
        "set": "",
        "level": "0",
        "freq": "",
        "out": "out",
        "x": 1350,
        "y": 280,
        "wires": []
    },
    {
        "id": "a3e28a2b50205e2a",
        "type": "switch",
        "z": "10c6af45c4a00278",
        "name": "Which Button",
        "property": "payload",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "4",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "6",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "8",
                "vt": "str"
            }
        ],
        "checkall": "false",
        "repair": false,
        "outputs": 3,
        "x": 750,
        "y": 200,
        "wires": [
            [
                "ca9d7c91862908d4"
            ],
            [],
            []
        ],
        "outputLabels": [
            "Licht Links",
            "Licht Rechts",
            ""
        ]
    },
    {
        "id": "99413749d5d6702a",
        "type": "function",
        "z": "10c6af45c4a00278",
        "name": "Extract Button ID",
        "func": "msg.payload = Number(msg.payload[2]);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 550,
        "y": 200,
        "wires": [
            [
                "a3e28a2b50205e2a"
            ]
        ]
    },
    {
        "id": "beece4d3ef5cb17b",
        "type": "switch",
        "z": "10c6af45c4a00278",
        "name": "Seitensortierung",
        "property": "payload[1]",
        "propertyType": "msg",
        "rules": [
            {
                "t": "eq",
                "v": "0x0",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0x1",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0x3",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0x4",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0x5",
                "vt": "str"
            },
            {
                "t": "eq",
                "v": "0x6",
                "vt": "str"
            }
        ],
        "checkall": "true",
        "repair": false,
        "outputs": 6,
        "x": 310,
        "y": 220,
        "wires": [
            [],
            [],
            [
                "99413749d5d6702a"
            ],
            [],
            [],
            []
        ]
    },
    {
        "id": "cea7f0bd27ed3a5b",
        "type": "serial in",
        "z": "10c6af45c4a00278",
        "name": "Nextion",
        "serial": "f527860f.a985e8",
        "x": 130,
        "y": 220,
        "wires": [
            [
                "beece4d3ef5cb17b"
            ]
        ]
    },
    {
        "id": "f527860f.a985e8",
        "type": "serial-port",
        "serialport": "/dev/ttyS0",
        "serialbaud": "9600",
        "databits": "8",
        "parity": "none",
        "stopbits": "1",
        "waitfor": "",
        "newline": "100",
        "bin": "bin",
        "out": "interbyte",
        "addchar": "",
        "responsetimeout": ""
    }
]

```

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [12 September 2021 21:42 UTC](https://discourse.nodered.org/t/switch-feedback/50925/2 "2021-09-12T21:42:49Z")

</div>

Add the _"turn off other switch's"_ to each of the switches _"start whatever"_ condition.

Eg. (in a sort of "pseudocode")

```auto
If switch 1 == ON {
switch 2 = 0
switch 3 = 0
Start whatever
} else {
Stop whatever
}

If switch 2 == ON {
switch 1 = 0
switch 3 = 0
Start whatever
} else {
Stop whatever
}

If switch 3 == ON {
switch 1 = 0
switch 2 = 0
Start whatever
} else {
Stop whatever
}

```

---

<div class="post-metadata">

**Author:** ![MyRandomThoughts](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/myrandomthoughts/32/41085_2.png) [@MyRandomThoughts](https://discourse.nodered.org/u/MyRandomThoughts)\
**Post date:** [12 September 2021 22:34 UTC](https://discourse.nodered.org/t/switch-feedback/50925/3 "2021-09-12T22:34:00Z")

</div>

Maybe have a look at [node-red-contrib-ui-multistate-switch (node) - Node-RED](https://flows.nodered.org/node/node-red-contrib-ui-multistate-switch)

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [12 September 2021 23:19 UTC](https://discourse.nodered.org/t/switch-feedback/50925/4 "2021-09-12T23:19:49Z")

</div>

The OP is using a Nextion and appears to have need to send the feedback to that device.

---

<div class="post-metadata">

**Author:** ![holographic](https://avatars.discourse-cdn.com/v4/letter/h/8e7dd6/32.png) [@holographic](https://discourse.nodered.org/u/holographic)\
**Post date:** [13 September 2021 05:24 UTC](https://discourse.nodered.org/t/switch-feedback/50925/5 "2021-09-13T05:24:52Z")

</div>

Hello Gunner,

thanks for your help.  
But i do not understand what you mean, wehre to put that code.

Thanks  
alex

---

<div class="post-metadata">

**Author:** ![Gunner](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gunner/32/43582_2.png) [@Gunner](https://discourse.nodered.org/u/Gunner)\
**Post date:** [13 September 2021 07:06 UTC](https://discourse.nodered.org/t/switch-feedback/50925/6 "2021-09-13T07:06:48Z")

</div>

I didn't give you actual code... pseudocode is more like a description, in plainer language, of the structure your need to write, in whatever language you need, to do what you asked. In this case Javascript.

You should already know how to receive a command from the Nextion and send one back, thus, when you receive an "ON" switch action, send two commands back to the Nextion to turn OFF the other switches, then do whatever that initial switch was supposed to do.

Of course with the Nextion, you should also be able to use it's internal "code" that upon any switch trigger, turns off all other switches... thus leaving the Node-Red side to only do the work required per switch triggering. But that is Nextion coding, not a Node-Red forum thing.

This guy has a few good videos on the Nextion

> **[Cheap Controls](https://www.youtube.com/channel/UCN18arXiSBS9NiGMQFsDGnA/featured)**
>
> This channel has a main focus on the Nextion Display and Arduino Programs. There are some Arduino tutorials along with some basic electronic tutorials. There are some fun videos on food and just general silliness.

---

<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:** [12 November 2021 07:07 UTC](https://discourse.nodered.org/t/switch-feedback/50925/7 "2021-11-12T07:07:42Z")

</div>

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