A slightly modified script to the one that breaks.
It just adds some text injection too.
[{"id":"402169a8.8a791","type":"subflow","name":"B Toggle 2","info":"2025 07 31\n==========\nForgot to add msg2 to update status of node\n\n2025 06 07\n==========\nNEEDS WORK!\nChange `RELOAD` to `RESET`\nChanged to `RESET`, but old code left in\nfor backward compatability.\nPLEAES UPDATE CODE TO NEW COMMAND\n\n\n2024 02 06\n==\nFurther update:\n`msg.enabled = true` and `msg.payload = X` will ENABLE the button node.\n`msg.enabled = false` and `msg.payload = X` will DISABLE the button node.\nbut please noted `msg.payload` has to be `X` also!\n\n2023 12 20\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\nIf `msg.payload == \"RESEND\"` the current condition is resent to the output.\n(Handy if button mode is wiped with deploy)\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":140,"y":190,"wires":[{"id":"69ae694095adea75"}]}],"out":[{"x":860,"y":180,"wires":[{"id":"5a9848b4303ef8d2","port":0},{"id":"8c41e6c213bcdefe","port":0}]},{"x":860,"y":280,"wires":[{"id":"3a564786d2308bdd","port":0},{"id":"a2ec504194f78107","port":0}]},{"x":860,"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":860,"y":490,"wires":[{"id":"a5b2ad35ad8518e2","port":0}]}},{"id":"69ae694095adea75","type":"function","z":"402169a8.8a791","name":"toggle","func":"let a = msg.payload\nlet msg1 = {}\nlet msg2 = {} // STATUS\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 node.warn(\"Enabled = true\")\n context.set(\"disabled\",0)\n a = \"RESEND\"\n }\n else\n if (en == false)\n {\n // DISABLE\n node.warn(\"Enabled = false\")\n context.set(\"disabled\",1)\n //msg1.txt = \"disabled\"\n msg1.txt = '<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>'\n msg1.colour = env.get(\"OffCLR\")\n //node.status({text:\"DISABLED\"})\n msg2.payload = { \"text\":\"DISABLED\" }\n return [null,msg1,msg2]\n }\n}\n\nif (context.get(\"disabled\") == 1)\n{\n // Can't do anything.\n //node.status({text:\"skipped\"})\n msg2.payload = {\"payload\":\"skipped\"}\n return[null,null,msg2]\n}\n\nif (a == \"RESET\")\n{\n a = env.get(\"StartMode\")\n context.set(\"counter\", a)\n msg.payload = a\n}\n\n// 2025 06 07\n/// OLD CODE. To be deleted ASAP\nif (a == \"RELOAD\")\n{\n a = env.get(\"StartMode\")\n context.set(\"counter\", a)\n msg.payload = a\n}\n\nif (a == \"RESEND\")\n{\n a = context.get(\"counter\")\n context.set(\"counter\", a)\n msg.payload = a\n}\n\nif (a == 0)\n{\n// context.set(\"counter\",0)\n// msg.payload = 0\n //node.status({text:\"Force OFF\"})\n msg2.payload = {\"text\":\"Force OFF\"}\n return [msg,null,msg2]\n}\nif (a == 1)\n{\n //node.status({ text: \"Force ON\" })\n msg2.payload = {\"text\":\"Force ON\"}\n return [msg,null,msg2]\n}\n\nif (x === 0)\n{\n msg.payload = 1\n //node.status({ text: \"ON\" })\n msg2.payload = { \"text\": \"ON\" }\n} else\nif (x === 1)\n{\n msg.payload = 0\n //node.status({ text: \"OFF\" })\n msg2.payload = { \"text\": \"OFF\" }\n}\n\nx = (x + 1) % 2\n\ncontext.set(\"counter\",x)\n\nreturn [msg,null,msg2]","outputs":3,"timeout":"","noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":190,"wires":[["0db7c2da3958ea2c"],[],["a5b2ad35ad8518e2"]],"outputLabels":["output","output inverted","status"],"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":700,"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":700,"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":540,"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":700,"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":700,"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":700,"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":700,"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":190,"y":140,"wires":[["69ae694095adea75"]]},{"id":"a5b2ad35ad8518e2","type":"junction","z":"402169a8.8a791","x":650,"y":490,"wires":[[]]},{"id":"93fb80fe63634587","type":"inject","z":"b39000460508d582","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"X","payloadType":"str","x":5520,"y":490,"wires":[["fc1b87d32a19ece6"]]},{"id":"fc1b87d32a19ece6","type":"subflow:402169a8.8a791","z":"b39000460508d582","name":"","env":[{"name":"StartMode","value":"1","type":"num"},{"name":"OffTXT","value":"HOLD","type":"str"},{"name":"OffCLR","value":"red","type":"str"},{"name":"OnTXT","value":"PASS","type":"str"},{"name":"OnCLR","value":"green","type":"str"},{"name":"OFF","value":"close","type":"str"},{"name":"ON","value":"open","type":"str"},{"name":"CTOPIC","value":"control","type":"str"}],"x":5695,"y":490,"wires":[["054dc0465cbdc6b9","0533dbcbf8e77a7a"],[],["03e108143aa23ce0","500994344ea0c0cb"]],"inputLabels":["from HOLD button"],"l":false},{"id":"020352927c165a64","type":"ui-button","z":"b39000460508d582","group":"6f4a6f88bfbb219b","name":"Hold","label":"","order":10,"width":"1","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"X","payloadType":"str","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","enableClick":true,"enablePointerdown":false,"pointerdownPayload":"","pointerdownPayloadType":"str","enablePointerup":false,"pointerupPayload":"","pointerupPayloadType":"str","x":5480,"y":650,"wires":[["a888ea107ac7f3bb","fc1b87d32a19ece6"]]},{"id":"054dc0465cbdc6b9","type":"gate","z":"b39000460508d582","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":5820,"y":550,"wires":[["d356048ed30c9e9a"]]},{"id":"0533dbcbf8e77a7a","type":"switch","z":"b39000460508d582","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"open","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":5785,"y":510,"wires":[["3ba6151acfca02e4"]],"l":false},{"id":"03e108143aa23ce0","type":"debug","z":"b39000460508d582","name":"debug 34","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":5860,"y":430,"wires":[]},{"id":"500994344ea0c0cb","type":"switch","z":"b39000460508d582","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":5205,"y":660,"wires":[["9ac368e01da4aa5f"],["e00e37f0d00a65c8"]],"l":false},{"id":"9ac368e01da4aa5f","type":"change","z":"b39000460508d582","name":"Normal","rules":[{"t":"set","p":"ui_update.label","pt":"msg","to":"PASS","tot":"str"},{"t":"set","p":"ui_update.buttonColor","pt":"msg","to":"blue","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":5310,"y":650,"wires":[["020352927c165a64"]]},{"id":"e00e37f0d00a65c8","type":"change","z":"b39000460508d582","name":"Hold","rules":[{"t":"set","p":"ui_update.label","pt":"msg","to":"HOLD","tot":"str"},{"t":"set","p":"ui_update.buttonColor","pt":"msg","to":"red","tot":"str"},{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":5300,"y":690,"wires":[["020352927c165a64"]]},{"id":"a888ea107ac7f3bb","type":"debug","z":"b39000460508d582","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":5680,"y":650,"wires":[]},{"id":"3ad8ee846db55472","type":"trigger","z":"b39000460508d582","name":"","op1":"","op2":" ","op1type":"nul","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":5695,"y":550,"wires":[["054dc0465cbdc6b9"]],"l":false},{"id":"d356048ed30c9e9a","type":"junction","z":"b39000460508d582","x":5950,"y":600,"wires":[["52ba28d889a8d6fb"]]},{"id":"3ba6151acfca02e4","type":"change","z":"b39000460508d582","name":"blank","rules":[{"t":"set","p":"payload","pt":"msg","to":" ","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":5855,"y":510,"wires":[["d356048ed30c9e9a"]],"l":false},{"id":"1e9960df0ae08524","type":"junction","z":"b39000460508d582","x":5640,"y":600,"wires":[["3ad8ee846db55472","d356048ed30c9e9a"]]},{"id":"52ba28d889a8d6fb","type":"ui-text","z":"b39000460508d582","group":"6f4a6f88bfbb219b","order":12,"width":"2","height":"1","name":"","label":"Test","format":"{{msg.payload}}","layout":"row-spread","style":false,"font":"","fontSize":16,"color":"#717171","wrapText":false,"className":"","x":6110,"y":600,"wires":[]},{"id":"e62ae55b7805711e","type":"inject","z":"b39000460508d582","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Test message","payloadType":"str","x":5460,"y":600,"wires":[["1e9960df0ae08524"]]},{"id":"82707be85485aa4f","type":"ui-button","z":"b39000460508d582","group":"6f4a6f88bfbb219b","name":"Message","label":"Inject","order":11,"width":"1","height":"1","emulateClick":false,"tooltip":"","color":"","bgcolor":"","className":"","icon":"","iconPosition":"left","payload":"Test message","payloadType":"str","topic":"topic","topicType":"msg","buttonColor":"","textColor":"","iconColor":"","enableClick":true,"enablePointerdown":false,"pointerdownPayload":"","pointerdownPayloadType":"str","enablePointerup":false,"pointerupPayload":"","pointerupPayloadType":"str","x":5490,"y":550,"wires":[["1e9960df0ae08524"]]},{"id":"6f4a6f88bfbb219b","type":"ui-group","name":"Group 1","page":"b9b507aa5c5840c2","width":"10","height":1,"order":1,"showTitle":false,"className":"","visible":true,"disabled":"false","groupType":"default"},{"id":"b9b507aa5c5840c2","type":"ui-page","name":"Down/Up load speed tester","ui":"379027033ed5c83a","path":"/page1","icon":"home","layout":"flex","theme":"84a68e3f4c6f8cdc","breakpoints":[{"name":"Default","px":"0","cols":"3"},{"name":"Tablet","px":"576","cols":"6"},{"name":"Small Desktop","px":"768","cols":"9"},{"name":"Desktop","px":"1024","cols":"12"}],"order":1,"className":"","visible":true,"disabled":false},{"id":"379027033ed5c83a","type":"ui-base","name":"My Dashboard","path":"/dashboard","appIcon":"","includeClientData":true,"acceptsClientConfig":["ui-notification","ui-control"],"showPathInSidebar":false,"headerContent":"page","navigationStyle":"default","titleBarStyle":"default","showReconnectNotification":true,"notificationDisplayTime":1,"showDisconnectNotification":true,"allowInstall":true},{"id":"84a68e3f4c6f8cdc","type":"ui-theme","name":"Default Theme","colors":{"surface":"#63452c","primary":"#0094ce","bgPage":"#63452c","groupBg":"#63452c","groupOutline":"#cccccc"},"sizes":{"density":"default","pagePadding":"12px","groupGap":"12px","groupBorderRadius":"4px","widgetGap":"12px"}}]
Start:
Press the inject
node.
Press the PASS
node.
See how the text changes.
Press the inject
node.