@hotNipi
Thanks! This is what I have now. My light goes off when I press the button. On next press it does not go on. If I press the button in my home automation app the button does not show the state of the light.
[{"id":"9e1e78a2.63f928","type":"ui_button","z":"e185900c.bdc37","name":"on/off","group":"c09ef81b.346968","order":0,"width":"3","height":"2","passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"date","topic":"homie/homey-topic/gang-beneden/onoff/set","x":730,"y":480,"wires":[["e8162d5c.1afb8"]]},{"id":"e8162d5c.1afb8","type":"function","z":"e185900c.bdc37","name":"buttonHandler","func":"var state = global.get(\"devicestate\");\nvar label;\nvar color;\n\nif(state.active === true){\n state.active = false;\n label = \"OFF\";\n color = \"red\";\n}\nelse{\n state.active = true;\n label = \"ON\";\n color = \"green\";\n}\nglobal.set(\"devicestate\", state);\n\n\nvar buttonstate = {enabled:false, background:color, topic:label};\n\nmsg.payload = \"homie/homey-topic/gang-beneden/onoff/set\"\n\nreturn [buttonstate,msg];","outputs":"2","noerr":0,"x":920,"y":420,"wires":[["9e1e78a2.63f928"],["4052186d.749b38","fa6922a0.5160e"]],"inputLabels":["input"],"outputLabels":["to button","to proccessing"]},{"id":"4052186d.749b38","type":"delay","z":"e185900c.bdc37","name":"waste time to fake proccesing","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":950,"y":620,"wires":[["80dc1d9e.4120a"]]},{"id":"c62bdcdd.194fd","type":"function","z":"e185900c.bdc37","name":"Init","func":"var devicestate = {active:true};\nglobal.set(\"devicestate\",devicestate);\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":480,"wires":[["80dc1d9e.4120a"]]},{"id":"8817181d.552828","type":"inject","z":"e185900c.bdc37","name":"Once","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":480,"wires":[["c62bdcdd.194fd"]]},{"id":"80dc1d9e.4120a","type":"function","z":"e185900c.bdc37","name":"determineButtonState","func":"var state = global.get(\"devicestate\");\nvar label;\nvar color;\n\nif(state.active === true){\n label = \"ON\";\n color = \"green\";\n}\nelse{\n label = \"OFF\";\n color = \"red\";\n}\nmsg = {enabled:true, topic:label, background:color};\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":480,"wires":[["9e1e78a2.63f928"]]},{"id":"ef643fad.f4e64","type":"mqtt in","z":"e185900c.bdc37","name":"MQTT receiver","topic":"homie/homey-topic/gang-beneden/onoff","qos":"2","datatype":"auto","broker":"49dffeeb.596af","x":160,"y":580,"wires":[["4528ad3e.cfd0f4"]]},{"id":"4528ad3e.cfd0f4","type":"function","z":"e185900c.bdc37","name":"Convert string to Boolean","func":"\nif(msg.payload === \"true\"){ msg.payload = true; }else{ msg.payload = false; } return msg;","outputs":1,"noerr":0,"x":390,"y":580,"wires":[["80dc1d9e.4120a"]]},{"id":"fa6922a0.5160e","type":"mqtt out","z":"e185900c.bdc37","name":"MQTT Light transmit","topic":"","qos":"","retain":"","broker":"49dffeeb.596af","x":1220,"y":400,"wires":[]},{"id":"c09ef81b.346968","type":"ui_group","z":"","name":"Test tab","tab":"d8ed3d29.d7b81","disp":true,"width":"6","collapse":false},{"id":"49dffeeb.596af","type":"mqtt-broker","z":"","name":"Homey MQTT","broker":"192.168.1.22","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"d8ed3d29.d7b81","type":"ui_tab","z":"","name":"Testing","icon":"dashboard","order":3,"disabled":false,"hidden":false}]