Cool! Actually I was looking at and have copied that specific thread. AND - Lord and behold - I have manged to make it work. (Proud Newbie!) The challenge is that I will be using 12 buttons, so I thought I'd copy each sequence over and over and - yeah you get it.
Unfortunately that doesn't seem to work. When starting from button 1 ->4 it works, but I can not seem to be able to turn off 1 again before i've turned off the higher number ones.
I think it is the global variable lightstate that creates the problem. Unfortunately, I'm too newbie to understand what I should do. Changing the name lightstate to lighstate1, ls2, ls3... didn't work so I need help.
The input from the mqtt from my Shelly RGBW switch is
ison: t/f
mode: "white"
brightness: nn
power: nn
overpower: t/f
Thankful for any assistance or pointers in this project!
[{"id":"932c9a5e.6c66f8","type":"tab","label":"Flow 6","disabled":false,"info":""},{"id":"cd8ee5a7.6a6d48","type":"mqtt out","z":"932c9a5e.6c66f8","name":"","topic":"","qos":"","retain":"","broker":"c86985b9.a9ab78","x":846,"y":70,"wires":[]},{"id":"e298b010.3eff","type":"template","z":"932c9a5e.6c66f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"brightness\" :{{payload}}}","output":"str","x":616,"y":70,"wires":[["cd8ee5a7.6a6d48","5db7e0e5.e58de"]]},{"id":"5db7e0e5.e58de","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":846,"y":110,"wires":[]},{"id":"27598731.c5b6f8","type":"change","z":"932c9a5e.6c66f8","name":"Brightness","rules":[{"t":"move","p":"payload.brightness","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":266,"y":70,"wires":[["5bade9f2.8815a8"]]},{"id":"64bdea3d.42a334","type":"json","z":"932c9a5e.6c66f8","name":"","property":"payload","action":"","pretty":false,"x":106,"y":110,"wires":[["27598731.c5b6f8","e5a8e727.96e478"]]},{"id":"12ab70a3.8bcd0f","type":"mqtt in","z":"932c9a5e.6c66f8","name":"Status 1_1","topic":"shellies/shellyrgbw2-B0D733/white/0/status","qos":"2","broker":"c86985b9.a9ab78","x":96,"y":50,"wires":[["64bdea3d.42a334"]]},{"id":"e5a8e727.96e478","type":"change","z":"932c9a5e.6c66f8","name":"On/off Status","rules":[{"t":"move","p":"payload.ison","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":266,"y":110,"wires":[["bdc56e85.850af"]]},{"id":"4da04575.f9b24c","type":"mqtt out","z":"932c9a5e.6c66f8","name":"S1_1 On/off","topic":"shellies/shellyrgbw2-B0D733/white/0/command","qos":"","retain":"","broker":"761dfb74.752d64","x":826,"y":150,"wires":[]},{"id":"8796405f.b5d5f","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":636,"y":150,"wires":[["4da04575.f9b24c"]]},{"id":"7b70b363.12362c","type":"ui_button","z":"932c9a5e.6c66f8","name":"on/off","group":"c6364af0.be9fe8","order":1,"width":3,"height":1,"passthru":false,"label":"{{msg.topic}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"lightstate","payloadType":"global","topic":"shellies/shellyrgbw2-B0D733/white/0/command","x":326,"y":150,"wires":[["d3896a5f.0c44a8","8796405f.b5d5f","e0188c68.fdae4"]]},{"id":"d3896a5f.0c44a8","type":"function","z":"932c9a5e.6c66f8","name":"buttonHandler","func":"//this function runs when you are pressing the button.\n\n// read current state of light\nvar state = global.get(\"lightstate\") || false;\n\nvar label;\nvar color;\n\nif(state === true){\n // current state is true (light is on) lets turn it off \n label = \"1\";\n color = \"red\";\n}\nelse{\n // current state is false (light is off) lets turn it on \n label = \"1\";\n color = \"green\";\n}\n\n// buttonstate is message, which goes straight back to button. It disables button. \n// button stays disabled until MQTT message comes in and tells to node-red \n// what is actual state of that light\nvar buttonstate = {enabled:false, background:color, topic:label};\n\n\n// I dont know anything about your mqtt commands\n// usually the commands are created by using msg topic for device select and and msg payload for command\n// Find info about it from your device documentation \n// if the command onoff/set does the toggle action, then it may work\n// but if not, then you must create the command with correct action (on or off)\n\n//msg.payload = \"here I need to way to set an on/off payload depending on state...\"\n\nreturn [buttonstate,msg];","outputs":"2","noerr":0,"x":476,"y":150,"wires":[["7b70b363.12362c"],[]],"inputLabels":["input"],"outputLabels":["to button","to proccessing"]},{"id":"795c95f.d0f286c","type":"function","z":"932c9a5e.6c66f8","name":"determineButtonState","func":"// this function runs every time the MQTT message is arrived (previous node changed the state of light).\n// read the state (if not set somehow, let assume it is false)\nvar state = global.get(\"lightstate\") || false;\nvar label;\nvar color;\n\nif(state === true){\n// state is true (lets make button green)\n label = \"1\";\n color = \"darkorange\";\n}\nelse{\n // state is false (lets make button red)\n label = \"1\";\n color = \"mediumgray\";\n}\n\n// send out message to button, this outgoing message only changes button visuals\nmsg = {enabled:true, topic:label, background:color};\nreturn msg;","outputs":1,"noerr":0,"x":156,"y":150,"wires":[["7b70b363.12362c"]]},{"id":"a4c990e2.05ea4","type":"function","z":"932c9a5e.6c66f8","name":"store the state of light","func":"// read current state of light \nvar lightstate = global.get(\"lightstate\") || undefined\nif(msg.payload === \"true\"){\n lightstate = true\n}\nelse{\n lightstate = false \n}\n// write state to global context, so we can read it where ever the state is needed\nglobal.set(\"lightstate\",lightstate)\n\n\n// return last known state (we dont use it but the flow must continue)\nmsg.payload = lightstate\nmsg.topic = \"state-of-light-changed\"\nreturn msg;","outputs":1,"noerr":0,"x":656,"y":110,"wires":[["795c95f.d0f286c"]]},{"id":"5bade9f2.8815a8","type":"ui_slider","z":"932c9a5e.6c66f8","name":"slider S1_1","label":"slider S1_1","group":"c6364af0.be9fe8","order":2,"width":9,"height":1,"passthru":true,"topic":"shellies/shellyrgbw2-B0D733/white/0/set","min":0,"max":"100","step":"5","x":446,"y":70,"wires":[["e298b010.3eff"]]},{"id":"bdc56e85.850af","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"true","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":456,"y":110,"wires":[["a4c990e2.05ea4"]]},{"id":"30840bae.a97b74","type":"mqtt out","z":"932c9a5e.6c66f8","name":"S1_2 On/off","topic":"shellies/shellyrgbw2-B0D733/white/1/command","qos":"","retain":"","broker":"761dfb74.752d64","x":826,"y":310,"wires":[]},{"id":"893c9409.723278","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":656,"y":310,"wires":[["30840bae.a97b74"]]},{"id":"1263cf58.a3b441","type":"ui_button","z":"932c9a5e.6c66f8","name":"on/off","group":"c6364af0.be9fe8","order":3,"width":3,"height":1,"passthru":false,"label":"{{msg.topic}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"lightstate","payloadType":"global","topic":"shellies/shellyrgbw2-B0D733/white/1/command","x":326,"y":310,"wires":[["5fe1a98a.1d9d48","893c9409.723278","a16579e1.d31c78"]]},{"id":"5fe1a98a.1d9d48","type":"function","z":"932c9a5e.6c66f8","name":"buttonHandler","func":"//this function runs when you are pressing the button.\n\n// read current state of light\nvar state = global.get(\"lightstate\") || false;\n\nvar label;\nvar color;\n\nif(state === true){\n // current state is true (light is on) lets turn it off \n label = \"2\";\n color = \"red\";\n}\nelse{\n // current state is false (light is off) lets turn it on \n label = \"2\";\n color = \"green\";\n}\n\n// buttonstate is message, which goes straight back to button. It disables button. \n// button stays disabled until MQTT message comes in and tells to node-red \n// what is actual state of that light\nvar buttonstate = {enabled:false, background:color, topic:label};\n\n\n// I dont know anything about your mqtt commands\n// usually the commands are created by using msg topic for device select and and msg payload for command\n// Find info about it from your device documentation \n// if the command onoff/set does the toggle action, then it may work\n// but if not, then you must create the command with correct action (on or off)\n\n//msg.payload = \"here I need to way to set an on/off payload depending on state...\"\n\nreturn [buttonstate,msg];","outputs":"2","noerr":0,"x":476,"y":310,"wires":[["1263cf58.a3b441"],[]],"inputLabels":["input"],"outputLabels":["to button","to proccessing"]},{"id":"6bb1c44c.fb56bc","type":"function","z":"932c9a5e.6c66f8","name":"determineButtonState","func":"// this function runs every time the MQTT message is arrived (previous node changed the state of light).\n// read the state (if not set somehow, let assume it is false)\nvar state = global.get(\"lightstate\") || false;\nvar label;\nvar color;\n\nif(state === true){\n// state is true (lets make button green)\n label = \"2\";\n color = \"darkorange\";\n}\nelse{\n // state is false (lets make button red)\n label = \"2\";\n color = \"mediumgray\";\n}\n\n// send out message to button, this outgoing message only changes button visuals\nmsg = {enabled:true, topic:label, background:color};\nreturn msg;","outputs":1,"noerr":0,"x":156,"y":310,"wires":[["1263cf58.a3b441"]]},{"id":"ee6489b4.7b97f8","type":"function","z":"932c9a5e.6c66f8","name":"store the state of light","func":"// read current state of light \nvar lightstate = global.get(\"lightstate\") || undefined\nif(msg.payload === \"true\"){\n lightstate = true\n}\nelse{\n lightstate = false \n}\n// write state to global context, so we can read it where ever the state is needed\nglobal.set(\"lightstate\",lightstate)\n\n\n// return last known state (we dont use it but the flow must continue)\nmsg.payload = lightstate\nmsg.topic = \"state-of-light-changed\"\nreturn msg;","outputs":1,"noerr":0,"x":656,"y":270,"wires":[["6bb1c44c.fb56bc"]]},{"id":"abfbee5c.b1c6f","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"true","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":456,"y":270,"wires":[["ee6489b4.7b97f8"]]},{"id":"109224ab.0a311b","type":"change","z":"932c9a5e.6c66f8","name":"On/off Status","rules":[{"t":"move","p":"payload.ison","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":266,"y":270,"wires":[["abfbee5c.b1c6f"]]},{"id":"ee86c2ab.f0251","type":"json","z":"932c9a5e.6c66f8","name":"","property":"payload","action":"","pretty":false,"x":106,"y":270,"wires":[["6c97f925.9a2828","109224ab.0a311b"]]},{"id":"6c97f925.9a2828","type":"change","z":"932c9a5e.6c66f8","name":"Brightness","rules":[{"t":"move","p":"payload.brightness","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":266,"y":230,"wires":[["82a647ca.4b8f68"]]},{"id":"ad69712.850479","type":"mqtt in","z":"932c9a5e.6c66f8","name":"Status 1_2","topic":"shellies/shellyrgbw2-B0D733/white/1/status","qos":"2","broker":"c86985b9.a9ab78","x":96,"y":210,"wires":[["ee86c2ab.f0251"]]},{"id":"82a647ca.4b8f68","type":"ui_slider","z":"932c9a5e.6c66f8","name":"slider S1_2","label":"slider S1_2","group":"c6364af0.be9fe8","order":4,"width":9,"height":1,"passthru":true,"topic":"shellies/shellyrgbw2-B0D733/white/1/set","min":0,"max":"100","step":"5","x":446,"y":230,"wires":[["29371b43.65e7e4"]]},{"id":"29371b43.65e7e4","type":"template","z":"932c9a5e.6c66f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"brightness\" :{{payload}}}","output":"str","x":616,"y":230,"wires":[["24cc6d1f.95fc32","75137cf2.5b0534"]]},{"id":"24cc6d1f.95fc32","type":"mqtt out","z":"932c9a5e.6c66f8","name":"","topic":"","qos":"","retain":"","broker":"c86985b9.a9ab78","x":846,"y":230,"wires":[]},{"id":"75137cf2.5b0534","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":846,"y":270,"wires":[]},{"id":"a16579e1.d31c78","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":486,"y":350,"wires":[]},{"id":"e0188c68.fdae4","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":466,"y":190,"wires":[]},{"id":"230664c5.d45d2c","type":"mqtt out","z":"932c9a5e.6c66f8","name":"S1_3 On/off","topic":"shellies/shellyrgbw2-B0D733/white/2/command","qos":"","retain":"","broker":"761dfb74.752d64","x":826,"y":470,"wires":[]},{"id":"3f219df9.3f0802","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":636,"y":470,"wires":[["230664c5.d45d2c"]]},{"id":"c89b69a9.b0a1a8","type":"ui_button","z":"932c9a5e.6c66f8","name":"on/off","group":"c6364af0.be9fe8","order":5,"width":3,"height":1,"passthru":false,"label":"{{msg.topic}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"lightstate","payloadType":"global","topic":"shellies/shellyrgbw2-B0D733/white/2/command","x":326,"y":470,"wires":[["53d50749.8b3cd8","3f219df9.3f0802","2acea899.86a798"]]},{"id":"53d50749.8b3cd8","type":"function","z":"932c9a5e.6c66f8","name":"buttonHandler","func":"//this function runs when you are pressing the button.\n\n// read current state of light\nvar state = global.get(\"lightstate\") || false;\n\nvar label;\nvar color;\n\nif(state === true){\n // current state is true (light is on) lets turn it off \n label = \"3\";\n color = \"red\";\n}\nelse{\n // current state is false (light is off) lets turn it on \n label = \"3\";\n color = \"green\";\n}\n\n// buttonstate is message, which goes straight back to button. It disables button. \n// button stays disabled until MQTT message comes in and tells to node-red \n// what is actual state of that light\nvar buttonstate = {enabled:false, background:color, topic:label};\n\n\n// I dont know anything about your mqtt commands\n// usually the commands are created by using msg topic for device select and and msg payload for command\n// Find info about it from your device documentation \n// if the command onoff/set does the toggle action, then it may work\n// but if not, then you must create the command with correct action (on or off)\n\n//msg.payload = \"here I need to way to set an on/off payload depending on state...\"\n\nreturn [buttonstate,msg];","outputs":"2","noerr":0,"x":476,"y":470,"wires":[["c89b69a9.b0a1a8"],[]],"inputLabels":["input"],"outputLabels":["to button","to proccessing"]},{"id":"3a45d750.bb0578","type":"function","z":"932c9a5e.6c66f8","name":"determineButtonState","func":"// this function runs every time the MQTT message is arrived (previous node changed the state of light).\n// read the state (if not set somehow, let assume it is false)\nvar state = global.get(\"lightstate\") || false;\nvar label;\nvar color;\n\nif(state === true){\n// state is true (lets make button green)\n label = \"3\";\n color = \"darkorange\";\n}\nelse{\n // state is false (lets make button red)\n label = \"3\";\n color = \"mediumgray\";\n}\n\n// send out message to button, this outgoing message only changes button visuals\nmsg = {enabled:true, topic:label, background:color};\nreturn msg;","outputs":1,"noerr":0,"x":156,"y":470,"wires":[["c89b69a9.b0a1a8"]]},{"id":"2acea899.86a798","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":466,"y":510,"wires":[]},{"id":"199a9a13.0a4076","type":"function","z":"932c9a5e.6c66f8","name":"store the state of light","func":"// read current state of light \nvar lightstate = global.get(\"lightstate\") || undefined\nif(msg.payload === \"true\"){\n lightstate = true\n}\nelse{\n lightstate = false \n}\n// write state to global context, so we can read it where ever the state is needed\nglobal.set(\"lightstate\",lightstate)\n\n\n// return last known state (we dont use it but the flow must continue)\nmsg.payload = lightstate\nmsg.topic = \"state-of-light-changed\"\nreturn msg;","outputs":1,"noerr":0,"x":656,"y":430,"wires":[["3a45d750.bb0578"]]},{"id":"885a6776.943e38","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"true","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":456,"y":430,"wires":[["199a9a13.0a4076"]]},{"id":"16b0b10f.c9589f","type":"change","z":"932c9a5e.6c66f8","name":"On/off Status","rules":[{"t":"move","p":"payload.ison","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":266,"y":430,"wires":[["885a6776.943e38"]]},{"id":"75ba85d7.2a7f2c","type":"json","z":"932c9a5e.6c66f8","name":"","property":"payload","action":"","pretty":false,"x":106,"y":430,"wires":[["a0e79d88.3a49e","16b0b10f.c9589f"]]},{"id":"a0e79d88.3a49e","type":"change","z":"932c9a5e.6c66f8","name":"Brightness","rules":[{"t":"move","p":"payload.brightness","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":266,"y":390,"wires":[["22485e30.2d8b92"]]},{"id":"95083081.157c7","type":"mqtt in","z":"932c9a5e.6c66f8","name":"Status 1_3","topic":"shellies/shellyrgbw2-B0D733/white/2/status","qos":"2","broker":"c86985b9.a9ab78","x":96,"y":370,"wires":[["75ba85d7.2a7f2c"]]},{"id":"22485e30.2d8b92","type":"ui_slider","z":"932c9a5e.6c66f8","name":"slider S1_3","label":"slider S1_3","group":"c6364af0.be9fe8","order":6,"width":9,"height":1,"passthru":true,"topic":"shellies/shellyrgbw2-B0D733/white/2/set","min":0,"max":"100","step":"5","x":446,"y":390,"wires":[["ed4114b4.150248"]]},{"id":"ed4114b4.150248","type":"template","z":"932c9a5e.6c66f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"brightness\" :{{payload}}}","output":"str","x":616,"y":390,"wires":[["a3804ed9.6f47a","bf4cffe3.5bb88"]]},{"id":"a3804ed9.6f47a","type":"mqtt out","z":"932c9a5e.6c66f8","name":"","topic":"","qos":"","retain":"","broker":"c86985b9.a9ab78","x":846,"y":390,"wires":[]},{"id":"bf4cffe3.5bb88","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":846,"y":430,"wires":[]},{"id":"b6715d55.c552e","type":"mqtt out","z":"932c9a5e.6c66f8","name":"S1_4 On/off","topic":"shellies/shellyrgbw2-B0D733/white/3/command","qos":"","retain":"","broker":"761dfb74.752d64","x":824,"y":633,"wires":[]},{"id":"b5aac05.c2b954","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"off","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":634,"y":633,"wires":[["b6715d55.c552e"]]},{"id":"5b21a3cc.b8f66c","type":"ui_button","z":"932c9a5e.6c66f8","name":"on/off","group":"c6364af0.be9fe8","order":7,"width":3,"height":1,"passthru":false,"label":"{{msg.topic}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"lightstate","payloadType":"global","topic":"shellies/shellyrgbw2-B0D733/white/3/command","x":324,"y":633,"wires":[["e8e8ad71.3e2c7","b5aac05.c2b954","ed5b9cbd.383c1"]]},{"id":"e8e8ad71.3e2c7","type":"function","z":"932c9a5e.6c66f8","name":"buttonHandler","func":"//this function runs when you are pressing the button.\n\n// read current state of light\nvar state = global.get(\"lightstate\") || false;\n\nvar label;\nvar color;\n\nif(state === true){\n // current state is true (light is on) lets turn it off \n label = \"4\";\n color = \"red\";\n}\nelse{\n // current state is false (light is off) lets turn it on \n label = \"4\";\n color = \"green\";\n}\n\n// buttonstate is message, which goes straight back to button. It disables button. \n// button stays disabled until MQTT message comes in and tells to node-red \n// what is actual state of that light\nvar buttonstate = {enabled:false, background:color, topic:label};\n\n\n// I dont know anything about your mqtt commands\n// usually the commands are created by using msg topic for device select and and msg payload for command\n// Find info about it from your device documentation \n// if the command onoff/set does the toggle action, then it may work\n// but if not, then you must create the command with correct action (on or off)\n\n//msg.payload = \"here I need to way to set an on/off payload depending on state...\"\n\nreturn [buttonstate,msg];","outputs":"2","noerr":0,"x":474,"y":633,"wires":[["5b21a3cc.b8f66c"],[]],"inputLabels":["input"],"outputLabels":["to button","to proccessing"]},{"id":"ed5b9cbd.383c1","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":464,"y":673,"wires":[]},{"id":"26a90a47.0dc9c6","type":"function","z":"932c9a5e.6c66f8","name":"determineButtonState","func":"// this function runs every time the MQTT message is arrived (previous node changed the state of light).\n// read the state (if not set somehow, let assume it is false)\nvar state = global.get(\"lightstate\") || false;\nvar label;\nvar color;\n\nif(state === true){\n// state is true (lets make button green)\n label = \"4\";\n color = \"darkorange\";\n}\nelse{\n // state is false (lets make button red)\n label = \"4\";\n color = \"mediumgray\";\n}\n\n// send out message to button, this outgoing message only changes button visuals\nmsg = {enabled:true, topic:label, background:color};\nreturn msg;","outputs":1,"noerr":0,"x":154,"y":633,"wires":[["5b21a3cc.b8f66c"]]},{"id":"c90ba206.29967","type":"function","z":"932c9a5e.6c66f8","name":"store the state of light","func":"// read current state of light \nvar lightstate = global.get(\"lightstate\") || undefined\nif(msg.payload === \"true\"){\n lightstate = true\n}\nelse{\n lightstate = false \n}\n// write state to global context, so we can read it where ever the state is needed\nglobal.set(\"lightstate\",lightstate)\n\n\n// return last known state (we dont use it but the flow must continue)\nmsg.payload = lightstate\nmsg.topic = \"state-of-light-changed\"\nreturn msg;","outputs":1,"noerr":0,"x":654,"y":593,"wires":[["26a90a47.0dc9c6"]]},{"id":"3191abbd.355684","type":"change","z":"932c9a5e.6c66f8","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"true","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"false","fromt":"bool","to":"false","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":454,"y":593,"wires":[["c90ba206.29967"]]},{"id":"2f3c1bb0.1da084","type":"change","z":"932c9a5e.6c66f8","name":"On/off Status","rules":[{"t":"move","p":"payload.ison","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":264,"y":593,"wires":[["3191abbd.355684"]]},{"id":"e19335fe.9b8228","type":"json","z":"932c9a5e.6c66f8","name":"","property":"payload","action":"","pretty":false,"x":104,"y":593,"wires":[["a3e3c4da.f537f8","2f3c1bb0.1da084"]]},{"id":"a3e3c4da.f537f8","type":"change","z":"932c9a5e.6c66f8","name":"Brightness","rules":[{"t":"move","p":"payload.brightness","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":264,"y":553,"wires":[["39c54957.6406f6"]]},{"id":"316822e7.007d7e","type":"mqtt in","z":"932c9a5e.6c66f8","name":"Status 1_4","topic":"shellies/shellyrgbw2-B0D733/white/3/status","qos":"2","broker":"c86985b9.a9ab78","x":94,"y":533,"wires":[["e19335fe.9b8228"]]},{"id":"39c54957.6406f6","type":"ui_slider","z":"932c9a5e.6c66f8","name":"slider S1_4","label":"slider S1_3","group":"c6364af0.be9fe8","order":8,"width":9,"height":1,"passthru":true,"topic":"shellies/shellyrgbw2-B0D733/white/3/set","min":0,"max":"100","step":"5","x":444,"y":553,"wires":[["1c5ee82a.cab098"]]},{"id":"1c5ee82a.cab098","type":"template","z":"932c9a5e.6c66f8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{\"brightness\" :{{payload}}}","output":"str","x":614,"y":553,"wires":[["3a516240.5b51ae","4afae4da.a0009c"]]},{"id":"3a516240.5b51ae","type":"mqtt out","z":"932c9a5e.6c66f8","name":"","topic":"","qos":"","retain":"","broker":"c86985b9.a9ab78","x":844,"y":553,"wires":[]},{"id":"4afae4da.a0009c","type":"debug","z":"932c9a5e.6c66f8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":844,"y":593,"wires":[]},{"id":"c86985b9.a9ab78","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"761dfb74.752d64","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c6364af0.be9fe8","type":"ui_group","z":"","name":"Light","tab":"7be54798.217718","disp":true,"width":"12","collapse":false},{"id":"7be54798.217718","type":"ui_tab","z":"","name":"Home","icon":"dashboard","order":1}]```