Oh, the bulb only changes colour. It is kind of obvious for that.
Here is one where the icon also changes:
[{"id":"716ea8b3.eb3f38","type":"mqtt in","z":"26262ba1.62dcbc","name":"","topic":"ARLEC-1/stat/POWER","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":3800,"y":290,"wires":[["c5d78882.56af18","5c2ac838.421088","29666e3e.057e4a"]]},{"id":"3c5ba392.1296dc","type":"ui_button","z":"26262ba1.62dcbc","name":"ARLEC#1","group":"53172374.eec964","order":2,"width":"1","height":"2","passthru":false,"label":"{{msg.icon}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"X","payloadType":"str","topic":"","x":4430,"y":380,"wires":[["8c55ac4c.427c5"]]},{"id":"8c55ac4c.427c5","type":"function","z":"26262ba1.62dcbc","name":"Button control ARLEC1","func":"var msg1 = {};\n\nvar x = msg.payload;\nvar counter = context.get(\"counter\") || 0;\nif (x == \"X\")\n{\n counter = (counter + 1) % 2;\n context.set(\"counter\",counter);\n if (counter === 0)\n {\n //\n msg.payload = \"OFF\";\n msg1= {icon: '<font color = \"orangered\"><i class=\"fa fa-toggle-on fa-rotate-270 fa-3x\"></i></font>'};\n msg1.background = \"black\";\n\n } else\n {\n //\n msg.payload = \"ON\";\n msg1= {icon: '<font color = \"orangered\"><i class=\"fa fa-toggle-on fa-rotate-90 fa-3x\"></i></font>'};\n msg1.background = \"black\";\n }\n}\nreturn [msg,msg1];","outputs":2,"noerr":0,"x":4480,"y":420,"wires":[["48ca3cf9.dbd9a4"],["3c5ba392.1296dc"]]},{"id":"5816ca56.86d904","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"X","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":4230,"y":460,"wires":[["8c55ac4c.427c5"]]},{"id":"14a34aab.cea675","type":"change","z":"26262ba1.62dcbc","name":"Setup","rules":[{"t":"set","p":"topic","pt":"msg","to":"SETUP","tot":"str"},{"t":"set","p":"id","pt":"msg","to":"ARLEC-1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":4420,"y":340,"wires":[["8c55ac4c.427c5"]]},{"id":"8babb7cf.fd2d6","type":"inject","z":"26262ba1.62dcbc","name":"Setup *","topic":"","payload":"X","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"0.8","x":4240,"y":300,"wires":[["14a34aab.cea675"]],"info":"Probably not needed."},{"id":"3d7848a.af5ceb8","type":"catch","z":"26262ba1.62dcbc","name":"Not set","scope":["8c55ac4c.427c5"],"uncaught":false,"x":4420,"y":460,"wires":[["14a34aab.cea675","925354de.a40798"]]},{"id":"925354de.a40798","type":"trigger","z":"26262ba1.62dcbc","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"8","extend":false,"units":"s","reset":"","bytopic":"all","name":"Indicator","x":4430,"y":500,"wires":[[]]},{"id":"48ca3cf9.dbd9a4","type":"delay","z":"26262ba1.62dcbc","name":"Delay","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":4690,"y":420,"wires":[["5c8a909a.6c961"]]},{"id":"29666e3e.057e4a","type":"function","z":"26262ba1.62dcbc","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-toggle-on fa-rotate-270 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-toggle-on fa-rotate-90 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-toggle-on fa-rotate-90 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-toggle-on fa-rotate-270 fa-3x\"></i></font>'};\n msg.background = \"black\";\n context.set(\"STATE\",0);\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":4220,"y":340,"wires":[["3c5ba392.1296dc"]]},{"id":"5c8a909a.6c961","type":"change","z":"26262ba1.62dcbc","name":"#1","rules":[{"t":"set","p":"topic","pt":"msg","to":"ARLEC-1/cmnd/power1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":4690,"y":460,"wires":[["184d1f65.9249c1","cd171f54.5f457"]]},{"id":"e895a8b2.195198","type":"inject","z":"26262ba1.62dcbc","name":"En","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3850,"y":420,"wires":[["260b5dfb.c97ada","94fe587a.6667c"]]},{"id":"540c4a0a.56351c","type":"delay","z":"26262ba1.62dcbc","name":"Delay","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":3850,"y":380,"wires":[["4e37aacf.5c1244"]]},{"id":"94fe587a.6667c","type":"change","z":"26262ba1.62dcbc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"RESET","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":4050,"y":340,"wires":[["29666e3e.057e4a"]]},{"id":"44ea3f37.7f444","type":"inject","z":"26262ba1.62dcbc","name":"Dis","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3850,"y":460,"wires":[["fdc783f7.a3a58"]]},{"id":"fdc783f7.a3a58","type":"function","z":"26262ba1.62dcbc","name":"BAN","func":"msg = {icon: '<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>'};\nreturn msg;","outputs":1,"noerr":0,"x":4020,"y":420,"wires":[["36e5dcd9.1f572c"]]},{"id":"36e5dcd9.1f572c","type":"change","z":"26262ba1.62dcbc","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":4220,"y":420,"wires":[["3c5ba392.1296dc"]]},{"id":"260b5dfb.c97ada","type":"change","z":"26262ba1.62dcbc","name":"Enable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":4220,"y":380,"wires":[["3c5ba392.1296dc"]]},{"id":"4e37aacf.5c1244","type":"switch","z":"26262ba1.62dcbc","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":4020,"y":380,"wires":[["260b5dfb.c97ada","94fe587a.6667c"],["fdc783f7.a3a58"]]},{"id":"78507f10.ebafd8","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"Offline","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3850,"y":500,"wires":[["4e37aacf.5c1244"]]},{"id":"39f777de.763868","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"Online","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3850,"y":540,"wires":[["4e37aacf.5c1244"]]},{"id":"c8616b5.3b70098","type":"mqtt in","z":"26262ba1.62dcbc","name":"ARLEC-1/tele/LWT *","topic":"ARLEC-1/tele/LWT","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":3810,"y":340,"wires":[["68d9126f.ed930c","b511771b.5b31e","540c4a0a.56351c"]],"info":"Needs editing if used for another device"},{"id":"68d9126f.ed930c","type":"debug","z":"26262ba1.62dcbc","name":"ARLEC1 LWT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":4050,"y":460,"wires":[]},{"id":"cd171f54.5f457","type":"mqtt out","z":"26262ba1.62dcbc","name":"","topic":"","qos":"","retain":"true","broker":"378c0403.8cda04","x":4850,"y":460,"wires":[]},{"id":"378c0403.8cda04","type":"mqtt-broker","z":"","name":"MQTT HOST","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthRetain":"true","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"53172374.eec964","type":"ui_group","z":"","name":"ARLEC-1","tab":"aa487daa.33c1c","order":2,"disp":true,"width":"3","collapse":false},{"id":"aa487daa.33c1c","type":"ui_tab","z":"","name":"Real_World_Control","icon":"dashboard","order":3,"disabled":false,"hidden":false}]
Though it hasn't been updated to allow multiple computers control is as there is no sync from machine to machine when another one changes the state.
The catch is the function
node and it's toggle (X
) when the button is pressed.
It isn't updated. Just the icon/state/colour.
The other code has the inter-machine messages flow.
But it is still a rat's nest of stuff. Work in progress is the term I believe.