Switch feedback

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

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

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

Eg. (in a sort of "pseudocode")

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
}

Maybe have a look at node-red-contrib-ui-multistate-switch (node) - Node-RED

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

Hello Gunner,

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

Thanks
alex

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

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