Yeah, ok. Not the *full code but post 14 is an example taken directly from the actual flow.
Here is the real code. It is messy.
[{"id":"c3a6064e.05e3f8","type":"function","z":"6dd5ca4d.d1958c","name":"Button control BULB2","func":"var msg1 = {};\nvar counter = context.get(\"counter\") || 0;\ncounter = (counter + 1) % 2;\ncontext.set(\"counter\",counter);\n\nvar x = msg.payload;\n\nif (x == \"ON\")\n{\n counter = 1;\n context.set(\"counter\",1);\n return;\n} else\nif (x == \"OFF\")\n{\n counter = 0;\n context.set(\"counter\",0);\n return;\n}\n\nif (x == \"X\")\n{\n //\n if (counter == 0)\n {\n msg = {\n payload: \"OFF\",\n };\n } else\n {\n msg = {\n payload: \"ON\",\n };\n }\n msg.icon = '<font color = \"orangered\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>';\n msg.background = \"black\";\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":3100,"y":1450,"wires":[["1f7ab784.0af25","8ecacbe9.2c6dc","ff9e3205.7d3ef8"]]},{"id":"ff9e3205.7d3ef8","type":"ui_button","z":"6dd5ca4d.d1958c","name":"BULB#2","group":"12c72eb4.18b9d9","order":2,"width":"1","height":"3","passthru":false,"label":"{{msg.icon}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"X","payloadType":"str","topic":"","x":3060,"y":1410,"wires":[["c3a6064e.05e3f8"]]},{"id":"1f7ab784.0af25","type":"delay","z":"6dd5ca4d.d1958c","name":"Delay","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":3310,"y":1450,"wires":[["6298a2df.c8b0b4"]]},{"id":"8ecacbe9.2c6dc","type":"link out","z":"6dd5ca4d.d1958c","name":"","links":["27fa2e34.3b9c0a","fddab0da.b82168"],"x":3185,"y":1490,"wires":[]},{"id":"586c4129.55c178","type":"change","z":"6dd5ca4d.d1958c","name":"X *","rules":[{"t":"set","p":"payload","pt":"msg","to":"X","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2840,"y":1570,"wires":[["c3a6064e.05e3f8"]],"info":"The payload is `Y` (or !`X`) to initialise the\nbutton."},{"id":"d2275a52.fc9ec","type":"inject","z":"6dd5ca4d.d1958c","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"X","payloadType":"str","x":2860,"y":1610,"wires":[["c3a6064e.05e3f8"]]},{"id":"76fcfa8.682ab84","type":"change","z":"6dd5ca4d.d1958c","name":"Setup *","rules":[{"t":"set","p":"topic","pt":"msg","to":"SETUP","tot":"str"},{"t":"set","p":"id","pt":"msg","to":"BULB-2","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"X","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3060,"y":1370,"wires":[["c3a6064e.05e3f8"]],"info":"This needs editing for different BULBS"},{"id":"8bb0a132.6b5038","type":"switch","z":"6dd5ca4d.d1958c","name":"TOPICS *","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"BULB-2/cmnd/power1","vt":"str"},{"t":"eq","v":"BULB-2/cmnd/dimmer","vt":"str"},{"t":"eq","v":"BULB-2/cmnd/ct","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":4,"x":2650,"y":1320,"wires":[["3c7f955a.c14d32","c3a6064e.05e3f8","74fe3ef2.5812c8"],["ed81e075.75366"],["e9fb36f0.632778"],[]],"outputLabels":["State","",null,"LWT"],"info":"This needs editing for different BULBS"},{"id":"79e6bcfe.36e5ec","type":"change","z":"6dd5ca4d.d1958c","name":"Enable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2850,"y":1410,"wires":[["ff9e3205.7d3ef8"]]},{"id":"3c7f955a.c14d32","type":"function","z":"6dd5ca4d.d1958c","name":"Set state","func":"if (msg.payload == \"RESET\")\n{\n let state = context.get(\"STATE\");\n if (state === 0)\n {\n //\n msg= {icon: '<font color = \"red\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>'};\n msg.background = \"black\";\n return msg;\n } else\n {\n //\n msg= {icon: '<font color = \"lime\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>'};\n msg.background = \"black\";\n return msg;\n }\n}\nif (msg.payload == \"ON\")\n{\n msg= {icon: '<font color = \"lime\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>'};\n msg.background = \"black\";\n context.set(\"STATE\",1);\n} else\n{\n msg= {icon: '<font color = \"red\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>'};\n msg.background = \"black\";\n context.set(\"STATE\",0);\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":2850,"y":1370,"wires":[["5e5e2ade.7a0cb4","ff9e3205.7d3ef8"]]},{"id":"cf422c2c.6d35","type":"change","z":"6dd5ca4d.d1958c","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":2850,"y":1450,"wires":[["ff9e3205.7d3ef8"]]},{"id":"6298a2df.c8b0b4","type":"change","z":"6dd5ca4d.d1958c","name":"#2 *","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-2/cmnd/power1","tot":"str"},{"t":"set","p":"who","pt":"msg","to":"BedPi","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3310,"y":1490,"wires":[["261d3ca4.0f2b24","f40638e7.a90598"]],"info":"This needs editing for different BULBS"},{"id":"a8b8b766.983a1","type":"inject","z":"6dd5ca4d.d1958c","name":"Setup *","repeat":"","crontab":"","once":true,"onceDelay":"0.8","topic":"","payload":"X","payloadType":"str","x":2870,"y":1320,"wires":[["76fcfa8.682ab84"]],"info":"Probably not needed."},{"id":"c9eb1440.2a32b","type":"catch","z":"6dd5ca4d.d1958c","name":"Not set","scope":["c3a6064e.05e3f8"],"uncaught":false,"x":3050,"y":1490,"wires":[["76fcfa8.682ab84","5ae48904.55b0a8"]]},{"id":"56cc697.fbf8718","type":"mqtt in","z":"6dd5ca4d.d1958c","name":"Bulb-2 *","topic":"BULB-2/#","qos":"2","datatype":"auto","broker":"bbf26a6c.b7922","x":2470,"y":1320,"wires":[["d12a38bf.096b58","d52483f1.8a59d8","d3a62ce0.cf6778","8bb0a132.6b5038","7cd6e58b.0faa74"]],"info":"This needs editing for different BULBS"},{"id":"74fe3ef2.5812c8","type":"debug","z":"6dd5ca4d.d1958c","name":"Bulb 2 power status","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":3090,"y":1280,"wires":[]},{"id":"ed81e075.75366","type":"link out","z":"6dd5ca4d.d1958c","name":"","links":["ba823fac.35c1e","92a61fac.68ce1"],"x":2755,"y":1290,"wires":[]},{"id":"e9fb36f0.632778","type":"link out","z":"6dd5ca4d.d1958c","name":"","links":["3460262d.63677a"],"x":2755,"y":1320,"wires":[]},{"id":"ab02ce72.ca7f78","type":"inject","z":"6dd5ca4d.d1958c","name":"En","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2470,"y":1470,"wires":[["79e6bcfe.36e5ec","4e734307.a340cc"]]},{"id":"d08a95cf.e267","type":"switch","z":"6dd5ca4d.d1958c","name":"LWT","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Online","vt":"str"},{"t":"eq","v":"Offline","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":2640,"y":1410,"wires":[["79e6bcfe.36e5ec","4e734307.a340cc"],["4051e36d.ee7e5c"]]},{"id":"5e5e2ade.7a0cb4","type":"debug","z":"6dd5ca4d.d1958c","name":"From MQTT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":3070,"y":1320,"wires":[]},{"id":"4e734307.a340cc","type":"change","z":"6dd5ca4d.d1958c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"RESET","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2670,"y":1370,"wires":[["3c7f955a.c14d32"]]},{"id":"4051e36d.ee7e5c","type":"function","z":"6dd5ca4d.d1958c","name":"BAN","func":"msg = {icon: '<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>'};\nreturn msg;","outputs":1,"noerr":0,"x":2640,"y":1450,"wires":[["cf422c2c.6d35"]]},{"id":"261d3ca4.0f2b24","type":"debug","z":"6dd5ca4d.d1958c","name":"BULB #2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3480,"y":1450,"wires":[]},{"id":"f40638e7.a90598","type":"mqtt out","z":"6dd5ca4d.d1958c","name":"","topic":"","qos":"","retain":"","broker":"bbf26a6c.b7922","x":3470,"y":1490,"wires":[]},{"id":"5ae48904.55b0a8","type":"trigger","z":"6dd5ca4d.d1958c","name":"Indicator","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"8","extend":false,"units":"s","reset":"","bytopic":"all","outputs":1,"x":3060,"y":1530,"wires":[[]]},{"id":"d12a38bf.096b58","type":"debug","z":"6dd5ca4d.d1958c","name":"RAW BULB2 message","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2520,"y":1280,"wires":[]},{"id":"d52483f1.8a59d8","type":"link out","z":"6dd5ca4d.d1958c","name":"","links":["347dd852.c38258","a8f558c1.17bcc"],"x":2605,"y":1590,"wires":[]},{"id":"d3a62ce0.cf6778","type":"switch","z":"6dd5ca4d.d1958c","name":"power","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"BULB-2/stat/POWER","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":2640,"y":1510,"wires":[["59c25162.732be"]]},{"id":"7cd6e58b.0faa74","type":"link out","z":"6dd5ca4d.d1958c","name":"","links":["5aa1f4c2.f97dc4"],"x":2605,"y":1250,"wires":[]},{"id":"7c74a5ec.6093c4","type":"delay","z":"6dd5ca4d.d1958c","name":"Delay","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2470,"y":1410,"wires":[["d08a95cf.e267","de9617f6.3aa4b8"]]},{"id":"d974d852.ba3458","type":"inject","z":"6dd5ca4d.d1958c","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Offline","payloadType":"str","x":2470,"y":1550,"wires":[["d08a95cf.e267"]]},{"id":"29b1c67.de7ec3a","type":"inject","z":"6dd5ca4d.d1958c","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Online","payloadType":"str","x":2470,"y":1590,"wires":[["d08a95cf.e267"]]},{"id":"7c03ce7c.dcfaa","type":"inject","z":"6dd5ca4d.d1958c","name":"Dis","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":2470,"y":1510,"wires":[["4051e36d.ee7e5c"]]},{"id":"5f63f961.cdcbb","type":"link in","z":"6dd5ca4d.d1958c","name":"","links":["963dafc1.211fc8","1ec469a7.2569f6"],"x":3275,"y":1530,"wires":[["f40638e7.a90598"]]},{"id":"59c25162.732be","type":"change","z":"6dd5ca4d.d1958c","name":"Set FLOW","rules":[{"t":"set","p":"BULB2_STATE","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2860,"y":1510,"wires":[[]]},{"id":"de9617f6.3aa4b8","type":"change","z":"6dd5ca4d.d1958c","name":"Set FLOW","rules":[{"t":"set","p":"BULB2_LWT","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2660,"y":1550,"wires":[[]]},{"id":"544dd20.196943","type":"mqtt in","z":"6dd5ca4d.d1958c","name":"Bulb-2 *","topic":"BULB-2/tele/LWT","qos":"2","datatype":"auto","broker":"bbf26a6c.b7922","x":2470,"y":1370,"wires":[["34f1f3d2.646b7c","7c74a5ec.6093c4","58ba8156.89b418"]],"info":"This needs editing for different BULBS"},{"id":"34f1f3d2.646b7c","type":"debug","z":"6dd5ca4d.d1958c","name":"Bulb-2 LWT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":2860,"y":1280,"wires":[]},{"id":"58ba8156.89b418","type":"link out","z":"6dd5ca4d.d1958c","name":"","links":["9591f5de.83b88","f6016669.56664"],"x":2605,"y":1630,"wires":[]},{"id":"12c72eb4.18b9d9","type":"ui_group","z":"","name":"BULB-2","tab":"e92ac76d.c24e7","order":6,"disp":true,"width":"3","collapse":false},{"id":"bbf26a6c.b7922","type":"mqtt-broker","z":"","name":"MQTT host","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"SOM","birthQos":"0","birthRetain":"true","birthPayload":"BedPi UP","closeTopic":"EOM","closeQos":"0","closeRetain":"true","closePayload":"BedPi Shutting down","willTopic":"EOM","willQos":"0","willRetain":"false","willPayload":"BedPi COMMS FAIL"},{"id":"e92ac76d.c24e7","type":"ui_tab","z":"","name":"Real_World_Control","icon":"dashboard","order":13,"disabled":false,"hidden":false}]
There are parts missing for controlling the brightness, colour temperature and logging.
Those bits are a bit unneeded in finding the problem, I feel.