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
}
]