How to disable a button from another button

Hi all
I am just starting to play with Nodered and ESP32 so I apologise if this is a basic question but I have to start somewhere !!.
I have got 2 flows the same the top one controls an antenna switch turning it on and off, the bottom one switches between 2 different feed lines ( on or off). What I want to do is disable the bottom button (greyed out) when the top one of switched off, but have it active when the top one is on. Hope this makes some sense. hope i have uploaded this correctly. Thanks for looking Paul

[
    {
        "id": "331a4c46c0b94a7d",
        "type": "function",
        "z": "494453487fce66d1",
        "name": "ant 1",
        "func": "\nlet payload=msg.payload;\nlet state=context.get(\"state\");\nif(msg.topic==\"init\")\n{\n    state = \"open\";\n    msg.payload = \"off\";\n    msg.background = \"grey\";\n    msg.label = \"Press to Start\";\n    msg.myicon = \"fa-toggle-off\";\n    msg.topic=\"control\";\n    context.set(\"state\", \"closed\");\n    return msg;\n}\n//toggle\nif (typeof state == \"undefined\" || state==\"open\")\n{\n//state=\"open\";\nmsg.payload= \"off\";\nmsg.background = \"grey\";\nmsg.label = \"Antenna 1 off\";\nmsg.myicon = \"fa-toggle-off\";\nstate=\"closed\";\n\n}\nelse if (typeof state == \"undefined\" || state == \"closed\") {\n//state = \"close\";\nmsg.payload= \"on\";\nmsg.background = \"green\";\n    msg.label = \"Antenna 1 selected\";\nmsg.myicon=\"fa-toggle-on\";\nstate=\"open\";\n\n}\ncontext.set(\"state\",state);\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"state\", \"closed\");",
        "finalize": "",
        "libs": [],
        "x": 470,
        "y": 310,
        "wires": [
            [
                "453afee6601230b9",
                "106fb70acae08d04",
                "6d3971975772ae72"
            ]
        ]
    },
    {
        "id": "4caa7eb9dbc9a685",
        "type": "ui_button",
        "z": "494453487fce66d1",
        "name": "",
        "group": "b2f76e121f1e3856",
        "order": 1,
        "width": "4",
        "height": "1",
        "passthru": false,
        "label": "{{topic}}",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{background}}",
        "className": "",
        "icon": "{{myicon}}",
        "payload": "off",
        "payloadType": "str",
        "topic": "relay/device1",
        "topicType": "str",
        "x": 370,
        "y": 420,
        "wires": [
            [
                "331a4c46c0b94a7d"
            ]
        ]
    },
    {
        "id": "453afee6601230b9",
        "type": "change",
        "z": "494453487fce66d1",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "label",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 190,
        "y": 420,
        "wires": [
            [
                "4caa7eb9dbc9a685"
            ]
        ]
    },
    {
        "id": "106fb70acae08d04",
        "type": "mqtt out",
        "z": "494453487fce66d1",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "f308ad008433f052",
        "x": 730,
        "y": 420,
        "wires": []
    },
    {
        "id": "9e793e4141ca5944",
        "type": "function",
        "z": "494453487fce66d1",
        "name": "ant 1",
        "func": "\nlet payload=msg.payload;\nlet state=context.get(\"state\");\nif(msg.topic==\"init\")\n{\n    state = \"open\";\n    msg.payload = \"off\";\n    msg.background = \"grey\";\n    msg.label = \"Press to Start\";\n    msg.myicon = \"fa-toggle-off\";\n    msg.topic=\"control\";\n    context.set(\"state\", \"closed\");\n    return msg;\n}\n//toggle\nif (typeof state == \"undefined\" || state==\"open\")\n{\n//state=\"open\";\nmsg.payload= \"off\";\nmsg.background = \"red\";\nmsg.label = \"red channel\";\nmsg.myicon = \"fa-toggle-off\";\nstate=\"closed\";\n\n}\nelse if (typeof state == \"undefined\" || state == \"closed\") {\n//state = \"close\";\nmsg.payload= \"on\";\nmsg.background = \"green\";\n    msg.label = \"green channel\";\nmsg.myicon=\"fa-toggle-on\";\nstate=\"open\";\n\n}\ncontext.set(\"state\",state);\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"state\", \"closed\");",
        "finalize": "",
        "libs": [],
        "x": 490,
        "y": 520,
        "wires": [
            [
                "3bdbe08c023fae13",
                "106fb70acae08d04",
                "6d3971975772ae72"
            ]
        ]
    },
    {
        "id": "083ed8df6a73e522",
        "type": "ui_button",
        "z": "494453487fce66d1",
        "name": "",
        "group": "b2f76e121f1e3856",
        "order": 1,
        "width": "4",
        "height": "1",
        "passthru": false,
        "label": "{{topic}}",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{background}}",
        "className": "",
        "icon": "{{myicon}}",
        "payload": "off",
        "payloadType": "str",
        "topic": "relay/device1",
        "topicType": "str",
        "x": 410,
        "y": 630,
        "wires": [
            [
                "9e793e4141ca5944"
            ]
        ]
    },
    {
        "id": "3bdbe08c023fae13",
        "type": "change",
        "z": "494453487fce66d1",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "label",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 230,
        "y": 630,
        "wires": [
            [
                "083ed8df6a73e522"
            ]
        ]
    },
    {
        "id": "6d3971975772ae72",
        "type": "debug",
        "z": "494453487fce66d1",
        "name": "debug 6",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 800,
        "y": 320,
        "wires": []
    },
    {
        "id": "b2f76e121f1e3856",
        "type": "ui_group",
        "name": "antenna on/off",
        "tab": "4f762449cfcb3fcf",
        "order": 1,
        "disp": true,
        "width": 6,
        "collapse": false,
        "className": ""
    },
    {
        "id": "f308ad008433f052",
        "type": "mqtt-broker",
        "name": "localhost",
        "broker": "localhost",
        "port": 1883,
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": 4,
        "keepalive": 60,
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "4f762449cfcb3fcf",
        "type": "ui_tab",
        "name": "antenna on/off",
        "icon": "dashboard",
        "order": 6,
        "disabled": false,
        "hidden": false
    }
]

Welcome to the forum @g0heu.

You can enable/disable your second button by passing it msg.enabled true/false.

So in your first function set eg msg.enablebutton2 = true (or false)
And use a change node to move this value into msg.enabled before feeding it into the second button.
(Sorry I had to rearrange your flow and rename some nodes so it made sense to me)

Note that there is a replacement for the node-red-dashboard component that you are using, @flowfuse/node-red-dashboard. It's relatively new and not as beginner-friendly unfortunately.

1 Like

hi jbudd

thanks for the replay
i have added msg.enablebutton2 = true into the top of the first funtion and setup the change node as you said i think, i am getting a error in the change node as shown. when i select the "antenna select" button it greys out the other button but it still functions

thanks

Hi @g0heu that is not right.

If you are new to node-red, I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.

It covers the change node and much more.


Regarding this immediate issue - read the change node form rules like a story: "Set" "msg.enabled" "to the value of" "msg.enablebutton2"

thanks Steve

I will have a look at the video's

your info on the issue has cleared the error but the second button is still not disabled when the first switched off
in the debut windows coming out of the change node i am getting

enablebutton2: false
enable: false

thanks

Details are important.

here is the complete flow

thanks

[
    {
        "id": "827719579c3a4aaa",
        "type": "function",
        "z": "74964b6a7a37dbbc",
        "name": "ant 1 on/off",
        "func": "\nlet payload=msg.payload;\nlet state=context.get(\"state\");\n\nif(msg.topic==\"init\")\n{\n    state = \"open\";\n  \n    msg.payload = \"off\";\n    msg.background = \"grey\";\n    msg.label = \"Press to Start\";\n    msg.myicon = \"fa-toggle-off\";\n    msg.topic=\"control\";\n    context.set(\"state\", \"closed\");\n    return msg;\n}\n//toggle\nif (typeof state == \"undefined\" || state==\"open\")\n{\n//state=\"open\";\nmsg.payload= \"off\";\n\nmsg.background = \"grey\";\nmsg.label = \"Antenna 1 off\";\nmsg.myicon = \"fa-toggle-off\";\nmsg.enablebutton2 = false\nmsg.enable = false\nstate=\"closed\";\n\n}\nelse if (typeof state == \"undefined\" || state == \"closed\") {\n//state = \"close\";\nmsg.payload= \"on\";\n\nmsg.background = \"green\";\n    msg.label = \"Antenna 1 selected\";\nmsg.myicon=\"fa-toggle-on\";\nstate=\"open\";\n\n}\ncontext.set(\"state\",state);\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"state\", \"closed\");",
        "finalize": "",
        "libs": [],
        "x": 730,
        "y": 140,
        "wires": [
            [
                "66b26a896a280d5d",
                "b4bede351dcffe4a",
                "26930ccca786f20c"
            ]
        ]
    },
    {
        "id": "6168e8180b7d6e14",
        "type": "ui_button",
        "z": "74964b6a7a37dbbc",
        "name": "",
        "group": "b2f76e121f1e3856",
        "order": 1,
        "width": "4",
        "height": "1",
        "passthru": false,
        "label": "ant1 on/off",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{background}}",
        "className": "",
        "icon": "{{myicon}}",
        "payload": "false",
        "payloadType": "bool",
        "topic": "relay/device1",
        "topicType": "str",
        "x": 450,
        "y": 140,
        "wires": [
            [
                "827719579c3a4aaa",
                "c80ab9298e6d89bd"
            ]
        ]
    },
    {
        "id": "66b26a896a280d5d",
        "type": "change",
        "z": "74964b6a7a37dbbc",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "label",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 270,
        "y": 140,
        "wires": [
            [
                "6168e8180b7d6e14"
            ]
        ]
    },
    {
        "id": "b4bede351dcffe4a",
        "type": "mqtt out",
        "z": "74964b6a7a37dbbc",
        "name": "",
        "topic": "",
        "qos": "",
        "retain": "",
        "respTopic": "",
        "contentType": "",
        "userProps": "",
        "correl": "",
        "expiry": "",
        "broker": "f308ad008433f052",
        "x": 1050,
        "y": 260,
        "wires": []
    },
    {
        "id": "fef9af0080e511b5",
        "type": "function",
        "z": "74964b6a7a37dbbc",
        "name": "Blue or orange",
        "func": "\nlet payload=msg.payload;\nlet state=context.get(\"state\");\nif(msg.topic==\"init\")\n{\n    state = \"open\";\n    msg.payload = \"off\";\n    msg.background = \"blue\";\n    msg.label = \"Press to Start\";\n    msg.myicon = \"fa-toggle-off\";\n    msg.topic=\"control\";\n    context.set(\"state\", \"closed\");\n    return msg;\n}\n//toggle\nif (typeof state == \"undefined\" || state==\"open\")\n{\n//state=\"open\";\nmsg.payload= \"off\";\nmsg.background = \"blue\";\nmsg.label = \"red channel\";\nmsg.myicon = \"fa-toggle-off\";\nstate=\"closed\";\n\n}\nelse if (typeof state == \"undefined\" || state == \"closed\") {\n//state = \"close\";\nmsg.payload= \"on\";\nmsg.background = \"orange\";\n    msg.label = \"green channel\";\nmsg.myicon=\"fa-toggle-on\";\nstate=\"open\";\n\n}\ncontext.set(\"state\",state);\nreturn msg;",
        "outputs": 1,
        "timeout": "",
        "noerr": 0,
        "initialize": "// Code added here will be run once\n// whenever the node is started.\ncontext.set(\"state\", \"closed\");",
        "finalize": "",
        "libs": [],
        "x": 740,
        "y": 260,
        "wires": [
            [
                "0e5850189d63e5a1",
                "b4bede351dcffe4a"
            ]
        ]
    },
    {
        "id": "d713e4905614a725",
        "type": "ui_button",
        "z": "74964b6a7a37dbbc",
        "name": "",
        "group": "b2f76e121f1e3856",
        "order": 1,
        "width": "4",
        "height": "1",
        "passthru": false,
        "label": "Ant1 -- Blue or orange",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{background}}",
        "className": "",
        "icon": "{{myicon}}",
        "payload": "",
        "payloadType": "str",
        "topic": "relay/device5",
        "topicType": "str",
        "x": 480,
        "y": 260,
        "wires": [
            [
                "fef9af0080e511b5",
                "26930ccca786f20c"
            ]
        ]
    },
    {
        "id": "0e5850189d63e5a1",
        "type": "change",
        "z": "74964b6a7a37dbbc",
        "name": "",
        "rules": [
            {
                "t": "set",
                "p": "topic",
                "pt": "msg",
                "to": "label",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 270,
        "y": 260,
        "wires": [
            [
                "d713e4905614a725"
            ]
        ]
    },
    {
        "id": "c80ab9298e6d89bd",
        "type": "change",
        "z": "74964b6a7a37dbbc",
        "name": "button enable",
        "rules": [
            {
                "t": "set",
                "p": "enable",
                "pt": "msg",
                "to": "payload",
                "tot": "msg"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 420,
        "y": 200,
        "wires": [
            [
                "d713e4905614a725",
                "26930ccca786f20c"
            ]
        ]
    },
    {
        "id": "26930ccca786f20c",
        "type": "debug",
        "z": "74964b6a7a37dbbc",
        "name": "debug 8",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 1040,
        "y": 180,
        "wires": []
    },
    {
        "id": "b2f76e121f1e3856",
        "type": "ui_group",
        "name": "antenna on/off",
        "tab": "4f762449cfcb3fcf",
        "order": 1,
        "disp": true,
        "width": 6,
        "collapse": false,
        "className": ""
    },
    {
        "id": "f308ad008433f052",
        "type": "mqtt-broker",
        "name": "localhost",
        "broker": "localhost",
        "port": 1883,
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": 4,
        "keepalive": 60,
        "cleansession": true,
        "autoUnsubscribe": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthRetain": "false",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closeRetain": "false",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willRetain": "false",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    },
    {
        "id": "4f762449cfcb3fcf",
        "type": "ui_tab",
        "name": "antenna on/off",
        "icon": "dashboard",
        "order": 6,
        "disabled": false,
        "hidden": false
    }
]

Take a slow and careful look at your change node.


Pay special attention to the names of the message properties you are working on.

Now look at what @Steve-Mcl said

Regarding this immediate issue - read the change node form rules like a story: "Set" "msg.enabled" "to the value of" "msg.enablebutton2"

Or what I said

You can enable/disable your second button by passing it msg.enabled true/false.

If you cannot see the difference then you are not reading what is there, you are reading what you think is there.

hi jbudd

I am sorry i just cant see it ????

i think i have spent to much time trying to work it out

give me a clue ???

thanks

image

msg.enable versus msg.enabled

thanks Colin

I just couldnt see it !!!! been looking to long !!!

thanks

I think you had better thank @jbudd for identifying the problem it in the first place.

hi Colin

yes thanks to jbudd well spotted

evan after looking at the messages i still didnt see it

thanks again for your help

cheers