Thanks.
Yeah, I kind of was on that path myself - strangely enough.
Though not with msg.label
.
Sorry, I don't want to drag you into this, but as you replied, would you mind looking at this sub-flow I wrote/made and see if it is at least on the way to being useful?
[{"id":"402169a8.8a791","type":"subflow","name":"B Toggle 2","info":"2023 11 23\n==\nRe-write code to allow force reloading of desired state.\n\nToggle output at receipt of message.\nConfigurable output and message to send back to button node.\n(2022 12 16)\n\nIf `msg.payload == 0` (number) the output is forced to the OFF condition.\n\nIf `msg.payload == 1` (number) the output is forced to the ON condition.\n\nIf `msg.payload == \"RELOAD\"` (text) the output is set to what you determined in the\n `StartMode` value.\n\nAny other input toggles the output.\n\n## ENV variables:\n```\nStartMode - set start condition (`0` off `1` on).\nOnCLR - the colour when ON condition active.\nOnTXT - the text when ON condition active.\nOffCLR - the colour when OFF condition active.\nOffTXT - the text when OFF conditin active.\nON - payload when ON condition active.\nOFF - payload when OFF condition active.\nCTOPIC - the topic of the output message.\n```\n\nOutputs:\n - 1 $OFF for OFF and $ON for ON.\n - 2 $ON for OFF and $OFF for ON. (Opposite of 1)\n - 3 to be sent back to button with `msg.colour` to set buttons colour and `msg.txt` for the text to be displayed.\n","category":"","in":[{"x":80,"y":190,"wires":[{"id":"69ae694095adea75"}]}],"out":[{"x":670,"y":180,"wires":[{"id":"5a9848b4303ef8d2","port":0},{"id":"8c41e6c213bcdefe","port":0}]},{"x":670,"y":280,"wires":[{"id":"3a564786d2308bdd","port":0},{"id":"a2ec504194f78107","port":0}]},{"x":670,"y":380,"wires":[{"id":"f14d0daf4ad33691","port":0},{"id":"aff48be4199bcfab","port":0},{"id":"69ae694095adea75","port":1}]}],"env":[{"name":"StartMode","type":"num","value":"","ui":{"label":{"en-US":"Start Mode (0/1) (off/on)"},"type":"input","opts":{"types":["num"]}}},{"name":"OffTXT","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","num"]}}},{"name":"OffCLR","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"OnTXT","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","num"]}}},{"name":"OnCLR","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"OFF","type":"str","value":""},{"name":"ON","type":"str","value":""},{"name":"CTOPIC","type":"str","value":""}],"meta":{"desc":"Button toggle node with feedback to button"},"color":"#D8BFD8","outputLabels":["Normal output","Inverted output","To button"],"icon":"node-red-dashboard/ui_switch.png","status":{"x":690,"y":510,"wires":[{"id":"4cca89516db73bd2","port":0}]}},{"id":"69ae694095adea75","type":"function","z":"402169a8.8a791","name":"toggle","func":"let a = msg.payload;\nlet msg1 = {};\nlet x = context.get(\"counter\") || 0;\n\nif (msg.enabled != undefined)\n{\n // Work to be done here.\n const en = msg.enabled;\n if (en == true)\n {\n // ENABLE\n context.set(\"disabled\",0);\n a = context.get(\"counter\") || 0;\n }\n else\n if (en == false)\n {\n // DISABLE\n context.set(\"disabled\",1);\n msg1.txt = \"disabled\";\n msg1.colour = env.get(\"OffCLR\");\n node.status({text:\"DISABLED\"});\n return [null,msg1];\n }\n}\n\nif (context.get(\"disabled\") == 1)\n{\n // Can't do anything.\n node.status({text:\"skipped\"});\n return;\n}\n\nif (a == \"RELOAD\")\n{\n a = env.get(\"StartMode\");\n}\n\nif (a == 0)\n{\n context.set(\"counter\",0);\n msg.payload = 0;\n node.status({text:\"Force OFF\"});\n return [msg,null];\n}\nif (a == 1)\n{\n context.set(\"counter\",1);\n msg.payload = 1;\n node.status({ text: \"Force ON\" });\n return [msg,null];\n}\n\nif (x === 0)\n{\n msg.payload = 1;\n node.status({ text: \"ON\" });\n} else\nif (x === 1)\n{\n msg.payload = 0;\n node.status({ text: \"OFF\" });\n}\n\nx = (x + 1) % 2;\n\ncontext.set(\"counter\",x);\n\nreturn [msg,null];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":190,"wires":[["0db7c2da3958ea2c"],[]],"info":"## Outputs `1` or `0` for ON/OFF and `msg.colour` to send to button."},{"id":"f14d0daf4ad33691","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"colour","pt":"msg","to":"OffCLR","tot":"env"},{"t":"set","p":"txt","pt":"msg","to":"OffTXT","tot":"env","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":350,"wires":[[]]},{"id":"aff48be4199bcfab","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"colour","pt":"msg","to":"OnCLR","tot":"env"},{"t":"set","p":"txt","pt":"msg","to":"OnTXT","tot":"env","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":410,"wires":[[]]},{"id":"0db7c2da3958ea2c","type":"switch","z":"402169a8.8a791","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":190,"wires":[["5a9848b4303ef8d2","3a564786d2308bdd","f14d0daf4ad33691"],["8c41e6c213bcdefe","a2ec504194f78107","aff48be4199bcfab"]]},{"id":"5a9848b4303ef8d2","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":160,"wires":[[]]},{"id":"8c41e6c213bcdefe","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":210,"wires":[[]]},{"id":"a2ec504194f78107","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":300,"wires":[[]]},{"id":"3a564786d2308bdd","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":250,"wires":[[]]},{"id":"a035346e85f036ba","type":"inject","z":"402169a8.8a791","name":"Start Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"StartMode","payloadType":"env","x":130,"y":140,"wires":[["69ae694095adea75"]]},{"id":"4cca89516db73bd2","type":"status","z":"402169a8.8a791","name":"","scope":["69ae694095adea75"],"x":370,"y":510,"wires":[[]]},{"id":"a830a46179143049","type":"subflow:402169a8.8a791","z":"1283f6a97005461c","name":"","x":440,"y":510,"wires":[[],[],[]]}]
No foreign nodes.
Oh, just so establish what/how it is used a basic flow.
No dashboard nodes.
[{"id":"402169a8.8a791","type":"subflow","name":"B Toggle 2","info":"2023 11 23\n==\nRe-write code to allow force reloading of desired state.\n\nToggle output at receipt of message.\nConfigurable output and message to send back to button node.\n(2022 12 16)\n\nIf `msg.payload == 0` (number) the output is forced to the OFF condition.\n\nIf `msg.payload == 1` (number) the output is forced to the ON condition.\n\nIf `msg.payload == \"RELOAD\"` (text) the output is set to what you determined in the\n `StartMode` value.\n\nAny other input toggles the output.\n\n## ENV variables:\n```\nStartMode - set start condition (`0` off `1` on).\nOnCLR - the colour when ON condition active.\nOnTXT - the text when ON condition active.\nOffCLR - the colour when OFF condition active.\nOffTXT - the text when OFF conditin active.\nON - payload when ON condition active.\nOFF - payload when OFF condition active.\nCTOPIC - the topic of the output message.\n```\n\nOutputs:\n - 1 $OFF for OFF and $ON for ON.\n - 2 $ON for OFF and $OFF for ON. (Opposite of 1)\n - 3 to be sent back to button with `msg.colour` to set buttons colour and `msg.txt` for the text to be displayed.\n","category":"","in":[{"x":80,"y":190,"wires":[{"id":"69ae694095adea75"}]}],"out":[{"x":670,"y":180,"wires":[{"id":"5a9848b4303ef8d2","port":0},{"id":"8c41e6c213bcdefe","port":0}]},{"x":670,"y":280,"wires":[{"id":"3a564786d2308bdd","port":0},{"id":"a2ec504194f78107","port":0}]},{"x":670,"y":380,"wires":[{"id":"f14d0daf4ad33691","port":0},{"id":"aff48be4199bcfab","port":0},{"id":"69ae694095adea75","port":1}]}],"env":[{"name":"StartMode","type":"num","value":"","ui":{"label":{"en-US":"Start Mode (0/1) (off/on)"},"type":"input","opts":{"types":["num"]}}},{"name":"OffTXT","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","num"]}}},{"name":"OffCLR","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"OnTXT","type":"str","value":"","ui":{"type":"input","opts":{"types":["str","num"]}}},{"name":"OnCLR","type":"str","value":"","ui":{"type":"input","opts":{"types":["str"]}}},{"name":"OFF","type":"str","value":""},{"name":"ON","type":"str","value":""},{"name":"CTOPIC","type":"str","value":""}],"meta":{"desc":"Button toggle node with feedback to button"},"color":"#D8BFD8","outputLabels":["Normal output","Inverted output","To button"],"icon":"node-red-dashboard/ui_switch.png","status":{"x":690,"y":510,"wires":[{"id":"4cca89516db73bd2","port":0}]}},{"id":"69ae694095adea75","type":"function","z":"402169a8.8a791","name":"toggle","func":"let a = msg.payload;\nlet msg1 = {};\nlet x = context.get(\"counter\") || 0;\n\nif (msg.enabled != undefined)\n{\n // Work to be done here.\n const en = msg.enabled;\n if (en == true)\n {\n // ENABLE\n context.set(\"disabled\",0);\n a = context.get(\"counter\") || 0;\n }\n else\n if (en == false)\n {\n // DISABLE\n context.set(\"disabled\",1);\n msg1.txt = \"disabled\";\n msg1.colour = env.get(\"OffCLR\");\n node.status({text:\"DISABLED\"});\n return [null,msg1];\n }\n}\n\nif (context.get(\"disabled\") == 1)\n{\n // Can't do anything.\n node.status({text:\"skipped\"});\n return;\n}\n\nif (a == \"RELOAD\")\n{\n a = env.get(\"StartMode\");\n}\n\nif (a == 0)\n{\n context.set(\"counter\",0);\n msg.payload = 0;\n node.status({text:\"Force OFF\"});\n return [msg,null];\n}\nif (a == 1)\n{\n context.set(\"counter\",1);\n msg.payload = 1;\n node.status({ text: \"Force ON\" });\n return [msg,null];\n}\n\nif (x === 0)\n{\n msg.payload = 1;\n node.status({ text: \"ON\" });\n} else\nif (x === 1)\n{\n msg.payload = 0;\n node.status({ text: \"OFF\" });\n}\n\nx = (x + 1) % 2;\n\ncontext.set(\"counter\",x);\n\nreturn [msg,null];","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":210,"y":190,"wires":[["0db7c2da3958ea2c"],[]],"info":"## Outputs `1` or `0` for ON/OFF and `msg.colour` to send to button."},{"id":"f14d0daf4ad33691","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"colour","pt":"msg","to":"OffCLR","tot":"env"},{"t":"set","p":"txt","pt":"msg","to":"OffTXT","tot":"env","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":350,"wires":[[]]},{"id":"aff48be4199bcfab","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"colour","pt":"msg","to":"OnCLR","tot":"env"},{"t":"set","p":"txt","pt":"msg","to":"OnTXT","tot":"env","dc":true}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":410,"wires":[[]]},{"id":"0db7c2da3958ea2c","type":"switch","z":"402169a8.8a791","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":190,"wires":[["5a9848b4303ef8d2","3a564786d2308bdd","f14d0daf4ad33691"],["8c41e6c213bcdefe","a2ec504194f78107","aff48be4199bcfab"]]},{"id":"5a9848b4303ef8d2","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":160,"wires":[[]]},{"id":"8c41e6c213bcdefe","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":210,"wires":[[]]},{"id":"a2ec504194f78107","type":"change","z":"402169a8.8a791","name":"OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"OFF","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":300,"wires":[[]]},{"id":"3a564786d2308bdd","type":"change","z":"402169a8.8a791","name":"ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"ON","tot":"env"},{"t":"set","p":"topic","pt":"msg","to":"CTOPIC","tot":"env"}],"action":"","property":"","from":"","to":"","reg":false,"x":510,"y":250,"wires":[[]]},{"id":"a035346e85f036ba","type":"inject","z":"402169a8.8a791","name":"Start Mode","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.2","topic":"","payload":"StartMode","payloadType":"env","x":130,"y":140,"wires":[["69ae694095adea75"]]},{"id":"4cca89516db73bd2","type":"status","z":"402169a8.8a791","name":"","scope":["69ae694095adea75"],"x":370,"y":510,"wires":[[]]},{"id":"5077b4ba298d5790","type":"subflow:402169a8.8a791","z":"fe5670ff.ea94e","name":"","env":[{"name":"StartMode","value":"1","type":"num"},{"name":"OffTXT","value":"OFF","type":"str"},{"name":"OffCLR","value":"red","type":"str"},{"name":"OnTXT","value":"ON","type":"str"},{"name":"OnCLR","value":"green","type":"str"},{"name":"OFF","value":"off command","type":"str"},{"name":"ON","value":"on command","type":"str"},{"name":"CTOPIC","value":"ctl_topic","type":"str"}],"x":2330,"y":310,"wires":[["8c31cf77f3bb4a8f"],["313d32e3301a1334"],["55852d37f54ce4aa"]]},{"id":"8c31cf77f3bb4a8f","type":"debug","z":"fe5670ff.ea94e","name":"debug 291","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2540,"y":260,"wires":[]},{"id":"313d32e3301a1334","type":"debug","z":"fe5670ff.ea94e","name":"debug 292","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2540,"y":310,"wires":[]},{"id":"55852d37f54ce4aa","type":"debug","z":"fe5670ff.ea94e","name":"debug 293","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2540,"y":360,"wires":[]},{"id":"a983f23c1fe734e3","type":"inject","z":"fe5670ff.ea94e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":2070,"y":250,"wires":[["5077b4ba298d5790"]]},{"id":"6161f88f12c31c21","type":"inject","z":"fe5670ff.ea94e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":2070,"y":310,"wires":[["5077b4ba298d5790"]]},{"id":"2bf216ccb9770f76","type":"inject","z":"fe5670ff.ea94e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"X","payloadType":"str","x":2070,"y":370,"wires":[["5077b4ba298d5790"]]},{"id":"3d273f7721b4b809","type":"inject","z":"fe5670ff.ea94e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"RELOAD","payloadType":"str","x":2080,"y":420,"wires":[["5077b4ba298d5790"]]},{"id":"ee742bf63945e992","type":"inject","z":"fe5670ff.ea94e","name":"disable","props":[{"p":"enabled","v":"false","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2050,"y":130,"wires":[["5077b4ba298d5790"]]},{"id":"8b819c8ad5c4bcd9","type":"inject","z":"fe5670ff.ea94e","name":"enable","props":[{"p":"enabled","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":2050,"y":170,"wires":[["5077b4ba298d5790"]]}]
1
sets the output to the ON state
0
sets the output to the OFF state
RELOAD
is used to force the text to what is was set to initially.
X
toggles the output.
The two enable
/ disable
are used to en/disable the node.
These signals would also go to the GUI
node to control it's condition.