MQTT is driving me crazy with inconsistent doings

Not to sure what you mean by that.
The transition from 'off' to 'on' is nearly instantaneous (well within a fraction of a second) !!!

I meant it was just cosmetic for a normal local case, it as you say instantaneous, I agree

But if your command has to "travel very long" like to Mars, it could take some time until you get the feedback. In the mean time you would eventually show "command in progress"

Like a traffic light: green -> yellow -> red

I thought that was what you meant.

Have a great weekend - cheers from DynamicDave.

PS:
Just for a laugh some of my IoT students used a MQTT broker in the US (BeeBotte) where the round trip was 12,000 miles. It still only took less than a second from pressing a button to turning an LED on/off.

Thats great!!!
Same to you! See you soon again
Best regards, Walter

Ok, progress has been made, but I'm still missing something.

working from what @krambriw said, I got things working a lot easier.

But there are still Gremlins in there - hiding.

To restate:
There are more than 1 machine which has this flow. That in itself may be the problem.
It isn't crucial, but while testing it is on the bigger/faster machine.

That, actually, may be the problem.

I won't show you the old code, but this is the new code:

Extra nodes needed: node-red-contrib-simple-gate
node-red-contrib-queue-gate But I don't know it is needed.

[{"id":"161c75d.9f6668a","type":"switch","z":"38b5a988.1c1756","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":610,"y":920,"wires":[["e461ef74.880be8"],["bb611069.b7adc"]]},{"id":"bb611069.b7adc","type":"change","z":"38b5a988.1c1756","name":"ON","rules":[{"t":"set","p":"background","pt":"msg","to":"black","tot":"str"},{"t":"set","p":"icon","pt":"msg","to":"<font color = \"lime\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>","tot":"str"},{"t":"set","p":"BULB1_POWER","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":980,"wires":[["7a5a3f8a.227298"]]},{"id":"e461ef74.880be8","type":"change","z":"38b5a988.1c1756","name":"OFF","rules":[{"t":"set","p":"background","pt":"msg","to":"black","tot":"str"},{"t":"set","p":"icon","pt":"msg","to":"<font color = \"red\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>","tot":"str"},{"t":"set","p":"BULB1_POWER","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":610,"y":860,"wires":[["7a5a3f8a.227298"]]},{"id":"7a5a3f8a.227298","type":"ui_button","z":"38b5a988.1c1756","name":"BULB#1","group":"4e6fc561.de1484","order":2,"width":"1","height":"3","passthru":false,"label":"{{msg.icon}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"X","payloadType":"str","topic":"","x":870,"y":920,"wires":[["f1f9e416.19af7","bb72e322.d85db8"]]},{"id":"f1f9e416.19af7","type":"change","z":"38b5a988.1c1756","name":"BGC","rules":[{"t":"set","p":"icon","pt":"msg","to":"<font color = \"orangered\"><i class=\"fa fa-lightbulb-o fa-3x\"></i></font>","tot":"str"},{"t":"set","p":"background","pt":"msg","to":"black","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":860,"y":860,"wires":[["7a5a3f8a.227298"]]},{"id":"bb72e322.d85db8","type":"function","z":"38b5a988.1c1756","name":"","func":"var state = flow.get('BULB1_POWER')||'OFF';\n//node.warn(state);\n\nswitch (state) {\n    case 'OFF':\n        msg.payload = \"ON\";\n        break;\n    case 'ON':\n        msg.payload = \"OFF\";\n        break;\n    default:\n        msg.payload = \"OFF\";\n        break;\n}\n\nnode.send(msg);","outputs":"1","noerr":0,"initialize":"","finalize":"","x":1040,"y":920,"wires":[["259c21f.d557ade"]]},{"id":"4a0cb59a.d5335c","type":"function","z":"38b5a988.1c1756","name":"","func":"msg1 = {};\nmsg2 = {};\nmsg3 = {};\n\nvar a = msg.payload.POWER;\nvar b = msg.payload.Dimmer;\nvar c = msg.payload.CT;\nmsg1.payload = a;\nmsg2.payload = b;\nmsg3.payload = c;\nreturn [msg1,msg2,msg3];","outputs":3,"noerr":0,"initialize":"","finalize":"","x":460,"y":750,"wires":[["3c161e83.221f52","1823ef4a.ba9e71"],["e9b369e.9063018","bf3b6442.cf44f"],["3035c478.15956c","79bae06b.407ec"]]},{"id":"bcbe7a9c.185d8","type":"json","z":"38b5a988.1c1756","name":"","property":"payload","action":"","pretty":false,"x":450,"y":700,"wires":[["4a0cb59a.d5335c"]]},{"id":"3c161e83.221f52","type":"debug","z":"38b5a988.1c1756","name":"Power","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":720,"wires":[]},{"id":"e9b369e.9063018","type":"debug","z":"38b5a988.1c1756","name":"Dimmer","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":720,"y":750,"wires":[]},{"id":"3035c478.15956c","type":"debug","z":"38b5a988.1c1756","name":"CT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":780,"wires":[]},{"id":"b013aace.b80708","type":"switch","z":"38b5a988.1c1756","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"BULB-1/tele/LWT","vt":"str"},{"t":"eq","v":"BULB-1/stat/RESULT","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":660,"wires":[["1ca13733.5fca81","3440cc7b.2523b4"],["bcbe7a9c.185d8"]]},{"id":"a33cf35f.6decf","type":"mqtt in","z":"38b5a988.1c1756","name":"Bulb-1 *","topic":"BULB-1/#","qos":"2","datatype":"auto","broker":"bbf26a6c.b7922","x":110,"y":660,"wires":[["87900b20.e9509"]],"info":"This needs editing for different BULBS"},{"id":"1ca13733.5fca81","type":"debug","z":"38b5a988.1c1756","name":"LWT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":630,"wires":[]},{"id":"6f5bee3.8fc231","type":"debug","z":"38b5a988.1c1756","name":"*******************","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":522.2222290039062,"y":580.0000152587891,"wires":[]},{"id":"3440cc7b.2523b4","type":"link out","z":"38b5a988.1c1756","name":"LWT","links":["868a1bdf.260538"],"x":565,"y":660,"wires":[]},{"id":"868a1bdf.260538","type":"link in","z":"38b5a988.1c1756","name":"LWT","links":["3440cc7b.2523b4"],"x":675,"y":660,"wires":[["b8733a43.51c558"]]},{"id":"1823ef4a.ba9e71","type":"link out","z":"38b5a988.1c1756","name":"POWER","links":["806cc847.54c3f","3e2ae6db.546912","2193a962.ae9bde"],"x":565,"y":720,"wires":[]},{"id":"806cc847.54c3f","type":"link in","z":"38b5a988.1c1756","name":"POWER","links":["1823ef4a.ba9e71"],"x":425,"y":920,"wires":[["161c75d.9f6668a","d29be62f.debaf"]]},{"id":"bf3b6442.cf44f","type":"link out","z":"38b5a988.1c1756","name":"Brightness","links":["1a490a40.d5f426"],"x":565,"y":750,"wires":[]},{"id":"1a490a40.d5f426","type":"link in","z":"38b5a988.1c1756","name":"Brightness","links":["bf3b6442.cf44f"],"x":325,"y":1200,"wires":[["6fc22820.5e2388"]]},{"id":"79bae06b.407ec","type":"link out","z":"38b5a988.1c1756","name":"CT","links":["3f5779b3.f7b2fe"],"x":565,"y":780,"wires":[]},{"id":"3f5779b3.f7b2fe","type":"link in","z":"38b5a988.1c1756","name":"CT","links":["79bae06b.407ec"],"x":325,"y":1240,"wires":[["e1e2c7d8.f92fa"]]},{"id":"2b61474c.3dbf38","type":"mqtt out","z":"38b5a988.1c1756","name":"","topic":"","qos":"","retain":"","broker":"bbf26a6c.b7922","x":1630,"y":960,"wires":[]},{"id":"259c21f.d557ade","type":"change","z":"38b5a988.1c1756","name":"#1 *","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-1/cmnd/power1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":960,"wires":[["6409ff52.e57e18","e3b5b83f.fea22","9e5503d3.261258"]],"info":"This needs editing for different BULBS"},{"id":"62f2053d.66f554","type":"inject","z":"38b5a988.1c1756","name":"OFF","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":450,"y":800,"wires":[["1823ef4a.ba9e71"]]},{"id":"5d7fa794.4fa14","type":"inject","z":"38b5a988.1c1756","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":450,"y":840,"wires":[["1823ef4a.ba9e71"]]},{"id":"d29be62f.debaf","type":"debug","z":"38b5a988.1c1756","name":"Button state","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":1020,"wires":[]},{"id":"6409ff52.e57e18","type":"delay","z":"38b5a988.1c1756","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1340,"y":960,"wires":[["4310efc1.e8d288"]]},{"id":"fe15f00a.10a31","type":"ui_slider","z":"38b5a988.1c1756","name":"Brightness","label":"Brightness","tooltip":"","group":"4e6fc561.de1484","order":6,"width":"1","height":"2","passthru":false,"outs":"end","topic":"BULB-2/cmnd/dimmer","min":0,"max":10,"step":1,"x":900,"y":1180,"wires":[["7645ed3b.f9251c"]]},{"id":"7d408c70.ba8d1c","type":"function","z":"38b5a988.1c1756","name":"","func":"msg.payload = (msg.payload / 10);\nreturn msg;","outputs":1,"noerr":0,"x":750,"y":1200,"wires":[["fe15f00a.10a31"]]},{"id":"7645ed3b.f9251c","type":"function","z":"38b5a988.1c1756","name":"","func":"msg.payload = msg.payload * 10;\nreturn msg;","outputs":1,"noerr":0,"x":1070,"y":1200,"wires":[["5c69b3c9.59779c"]]},{"id":"ff6172c7.f21e5","type":"q-gate","z":"38b5a988.1c1756","name":"","controlTopic":"CONTROL","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","queueCmd":"queue","defaultCmd":"default","triggerCmd":"trigger","flushCmd":"flush","resetCmd":"reset","maxQueueLength":"1","keepNewest":true,"qToggle":false,"persist":false,"x":1360,"y":1200,"wires":[["f7504ecd.f1d8a"]]},{"id":"f89da06c.615dc","type":"inject","z":"38b5a988.1c1756","name":"Close","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"close","payloadType":"str","x":610,"y":1280,"wires":[["cedaa29.e9a98e","e1e2c7d8.f92fa"]]},{"id":"a58943bf.4300c","type":"inject","z":"38b5a988.1c1756","name":"Open","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"open","payloadType":"str","x":610,"y":1320,"wires":[["cedaa29.e9a98e","e1e2c7d8.f92fa"]]},{"id":"cac8f03d.3345c8","type":"change","z":"38b5a988.1c1756","name":"Topic *","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-1/cmnd/ct","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":1240,"wires":[["ff6172c7.f21e5"]],"info":"Set for brightness"},{"id":"d6e08647.3b0a68","type":"range","z":"38b5a988.1c1756","minin":"1","maxin":"20","minout":"153","maxout":"500","action":"scale","round":false,"property":"payload","name":"","x":1070,"y":1240,"wires":[["cac8f03d.3345c8"]]},{"id":"83899604.0a3bb8","type":"range","z":"38b5a988.1c1756","minin":"153","maxin":"500","minout":"1","maxout":"20","action":"scale","round":false,"property":"payload","name":"","x":740,"y":1240,"wires":[["7d1fb13a.87c598"]]},{"id":"7d1fb13a.87c598","type":"ui_slider","z":"38b5a988.1c1756","name":"Temp'","label":"Temp'","tooltip":"","group":"4e6fc561.de1484","order":7,"width":"1","height":"2","passthru":false,"outs":"end","topic":"","min":0,"max":"20","step":1,"x":880,"y":1240,"wires":[["d6e08647.3b0a68"]]},{"id":"f7504ecd.f1d8a","type":"link out","z":"38b5a988.1c1756","name":"","links":["de44f852.c2038"],"x":1455,"y":1200,"wires":[]},{"id":"de44f852.c2038","type":"link in","z":"38b5a988.1c1756","name":"","links":["f7504ecd.f1d8a"],"x":1235,"y":1000,"wires":[["6409ff52.e57e18"]]},{"id":"27a5df72.8ffb78","type":"inject","z":"38b5a988.1c1756","name":"Close","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"close","payloadType":"str","x":1490,"y":880,"wires":[["4310efc1.e8d288"]]},{"id":"b34fb58e.e46848","type":"inject","z":"38b5a988.1c1756","name":"Open","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"open","payloadType":"str","x":1490,"y":920,"wires":[["4310efc1.e8d288"]]},{"id":"4310efc1.e8d288","type":"gate","z":"38b5a988.1c1756","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1490,"y":960,"wires":[["2b61474c.3dbf38","5fc6b249.543fdc"]]},{"id":"17de4c5b.edeb74","type":"inject","z":"38b5a988.1c1756","name":"Close","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"close","payloadType":"str","x":240,"y":580,"wires":[["87900b20.e9509"]]},{"id":"b5fd52a0.bd5ab8","type":"inject","z":"38b5a988.1c1756","name":"Open","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"open","payloadType":"str","x":240,"y":620,"wires":[["87900b20.e9509"]]},{"id":"87900b20.e9509","type":"gate","z":"38b5a988.1c1756","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":240,"y":660,"wires":[["6f5bee3.8fc231","b013aace.b80708"]]},{"id":"5fc6b249.543fdc","type":"debug","z":"38b5a988.1c1756","name":"************  OUTPUT  ************","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1570,"y":1020,"wires":[]},{"id":"2eeaf4a9.bc4d5c","type":"inject","z":"38b5a988.1c1756","name":"Close","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"close","payloadType":"str","x":1110,"y":500,"wires":[["da6dc67e.29d7f8"]]},{"id":"35ab5c99.2ef0f4","type":"inject","z":"38b5a988.1c1756","name":"Open","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"open","payloadType":"str","x":1110,"y":540,"wires":[["da6dc67e.29d7f8"]]},{"id":"da6dc67e.29d7f8","type":"link out","z":"38b5a988.1c1756","name":"","links":["e8c9674f.750e88","cde4224c.450588","1e92ef6c.e2ce71"],"x":1205,"y":520,"wires":[]},{"id":"cde4224c.450588","type":"link in","z":"38b5a988.1c1756","name":"","links":["da6dc67e.29d7f8"],"x":275,"y":540,"wires":[["87900b20.e9509"]]},{"id":"1e92ef6c.e2ce71","type":"link in","z":"38b5a988.1c1756","name":"","links":["da6dc67e.29d7f8"],"x":1525,"y":840,"wires":[["4310efc1.e8d288"]]},{"id":"5c69b3c9.59779c","type":"change","z":"38b5a988.1c1756","name":"Topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-1/cmnd/dimmer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1220,"y":1200,"wires":[["ff6172c7.f21e5"]]},{"id":"cedaa29.e9a98e","type":"gate","z":"38b5a988.1c1756","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":610,"y":1200,"wires":[["7d408c70.ba8d1c"]]},{"id":"e1e2c7d8.f92fa","type":"gate","z":"38b5a988.1c1756","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":610,"y":1240,"wires":[["83899604.0a3bb8"]]},{"id":"c02f051f.9d3c8","type":"inject","z":"38b5a988.1c1756","name":"Close","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"close","payloadType":"str","x":1220,"y":1290,"wires":[["ff6172c7.f21e5"]]},{"id":"f15e9781.aaede","type":"inject","z":"38b5a988.1c1756","name":"Open","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"CONTROL","payload":"open","payloadType":"str","x":1220,"y":1330,"wires":[["ff6172c7.f21e5"]]},{"id":"e9f29fab.b49fb","type":"switch","z":"38b5a988.1c1756","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":570,"y":1100,"wires":[["d7d00195.a633e8"],["c6006dad.9005"]]},{"id":"d7d00195.a633e8","type":"change","z":"38b5a988.1c1756","name":"Close","rules":[{"t":"set","p":"payload","pt":"msg","to":"close","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1070,"wires":[["cedaa29.e9a98e","e1e2c7d8.f92fa"]]},{"id":"c6006dad.9005","type":"change","z":"38b5a988.1c1756","name":"Open","rules":[{"t":"set","p":"payload","pt":"msg","to":"open","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":690,"y":1100,"wires":[["98c175de.41298"]]},{"id":"98c175de.41298","type":"delay","z":"38b5a988.1c1756","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":700,"y":1130,"wires":[["cedaa29.e9a98e","e1e2c7d8.f92fa"]]},{"id":"4f6b2755.e21898","type":"inject","z":"38b5a988.1c1756","name":"OFF","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":880,"y":960,"wires":[["259c21f.d557ade"]]},{"id":"4222bb9e.11200c","type":"inject","z":"38b5a988.1c1756","name":"ON","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":880,"y":1000,"wires":[["259c21f.d557ade"]]},{"id":"e3b5b83f.fea22","type":"link out","z":"38b5a988.1c1756","name":"","links":["2193a962.ae9bde"],"x":1145,"y":1000,"wires":[]},{"id":"9e5503d3.261258","type":"debug","z":"38b5a988.1c1756","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1230,"y":900,"wires":[]},{"id":"2193a962.ae9bde","type":"link in","z":"38b5a988.1c1756","name":"","links":["e3b5b83f.fea22","1823ef4a.ba9e71"],"x":485,"y":1100,"wires":[["e9f29fab.b49fb"]]},{"id":"d893827a.64dee","type":"comment","z":"38b5a988.1c1756","name":"Master control","info":"","x":1130,"y":460,"wires":[]},{"id":"b8733a43.51c558","type":"delay","z":"38b5a988.1c1756","name":"Delay","pauseType":"delay","timeout":"200","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":880,"y":660,"wires":[["a4d650ae.2f2d3"]]},{"id":"a4d650ae.2f2d3","type":"switch","z":"38b5a988.1c1756","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":1050,"y":660,"wires":[["8c5a9564.95af08"],["66f5c0ab.cfbba8"]]},{"id":"8b84df35.71d038","type":"function","z":"38b5a988.1c1756","name":"BAN","func":"msg = {icon: '<font color = \"red\"><i class=\"fa fa-ban fa-3x\"></i></font>', enabled: false};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1220,"y":710,"wires":[["276caac6.0e5cb6"]]},{"id":"8c5a9564.95af08","type":"change","z":"38b5a988.1c1756","name":"Enable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1210,"y":660,"wires":[["276caac6.0e5cb6","947ba50a.9ac198"]]},{"id":"66f5c0ab.cfbba8","type":"change","z":"38b5a988.1c1756","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1060,"y":710,"wires":[["8b84df35.71d038","947ba50a.9ac198"]]},{"id":"276caac6.0e5cb6","type":"link out","z":"38b5a988.1c1756","name":"","links":["ad03228b.6a86a8","668fbbd2.56717c","f3a57dba.42b328"],"x":1325,"y":670,"wires":[]},{"id":"ad03228b.6a86a8","type":"link in","z":"38b5a988.1c1756","name":"","links":["276caac6.0e5cb6"],"x":1415,"y":670,"wires":[["5b5cb721.f2ea38"]]},{"id":"668fbbd2.56717c","type":"link in","z":"38b5a988.1c1756","name":"","links":["276caac6.0e5cb6"],"x":715,"y":920,"wires":[["7a5a3f8a.227298"]]},{"id":"947ba50a.9ac198","type":"link out","z":"38b5a988.1c1756","name":"","links":["7c1f77a6.c09d08","5c3007a3.ec40e8"],"x":1185,"y":750,"wires":[]},{"id":"5c3007a3.ec40e8","type":"link in","z":"38b5a988.1c1756","name":"","links":["947ba50a.9ac198"],"x":775,"y":1280,"wires":[["fe15f00a.10a31","7d1fb13a.87c598"]]},{"id":"33b2539.f9668ac","type":"inject","z":"38b5a988.1c1756","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Online","payloadType":"str","x":880,"y":620,"wires":[["a4d650ae.2f2d3"]]},{"id":"8a5a1089.c17de","type":"inject","z":"38b5a988.1c1756","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Offline","payloadType":"str","x":880,"y":580,"wires":[["a4d650ae.2f2d3"]]},{"id":"5b5cb721.f2ea38","type":"debug","z":"38b5a988.1c1756","name":"Dis/En able icon","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1550,"y":670,"wires":[]},{"id":"6fc22820.5e2388","type":"delay","z":"38b5a988.1c1756","name":"Delay","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":1200,"wires":[["cedaa29.e9a98e"]]},{"id":"ffda27a2.13a338","type":"comment","z":"38b5a988.1c1756","name":"Test","info":"","x":860,"y":540,"wires":[]},{"id":"f96dbd26.7fa8c8","type":"comment","z":"38b5a988.1c1756","name":"Test","info":"","x":870,"y":1040,"wires":[]},{"id":"f426e7f4.bf9a88","type":"comment","z":"38b5a988.1c1756","name":"Test","info":"","x":450,"y":880,"wires":[]},{"id":"4e6fc561.de1484","type":"ui_group","z":"","name":"BULB-1","tab":"e92ac76d.c24e7","order":5,"disp":true,"width":"5","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 a couple of places where there is a test set of nodes.
They are there to let me test from the edit screen so I can see what is happening.

It looks ok so far.

One thing which I need to get working is using the flow context to save the brightness and colour temperature values. Brightness and CT.

I know I should be able to nut it out myself, but alas I can't seem to.

:frowning:

OK, here we go

  1. I understand that it might be a bit difficult to follow & find where things can go wrong, it's a rather complex structure you have built but in general I think it should work. There is a lot of "things" added for debugging, thats good but also makes the flow a bit difficult to read

  2. In the LWT part I do not see that you are setting the icon back correctly when/if you go from offline to online. Could that be one "gremlin"? I mean it would/could indicate offline while it actually is online. I think. Or is it sorted out automatically when the device comes back online, it starts to send current state and as a result the correct icon & background is set? But if so, it means you have to wait for a state msg to arrive until the icon and background is correct

  3. I think you have many "un-necessary" link nodes where a straight connection would do just fine

  4. You say you have this flow on several machines. I would be worried if they can control the same device/lamp that you could end up in a race condition between the various machines. Is there a reason why you need to have the same flow running on several machines controlling the devices?

  5. To save the Brightness and CT you could use the same method as for saving the state. You could add a change node in the flow where the msg with those properties are passing through. Or do it with code already in the function node with the 3 outputs (my choice) and then use them anywhere in your flow

msg1 = {};
msg2 = {};
msg3 = {};

var a = msg.payload.POWER;
var b = msg.payload.Dimmer;
var c = msg.payload.CT;
msg1.payload = a;
msg2.payload = b;
msg3.payload = c;

flow.set('BULB1_Brightness', b);
flow.set('BULB1_CT', c);

return [msg1,msg2,msg3];

Yeah, interesting.

I will look at it, but for now I have it working after ...... several hours chasing my tail.

One thing which was tripping me up was when I turned the bulb off, the brightness value went to 0 - kinda obvious - and so when I turned it back on, it turned on, but had a brightness of 0, so it kind of did, but kind of didn't.

Your trick with saving the on/off state in flow context is/was good, but I can't do it with the other two, as it isn't that easy. It isn't a simple on off signal.

And, saying there were no previous values, what did it do?

This is how I got around that problem - which was a lot of time invested:

[{"id":"31523b12.6b0a14","type":"ui_slider","z":"6dd5ca4d.d1958c","name":"Brightness","label":"Brightness","tooltip":"","group":"12c72eb4.18b9d9","order":3,"width":"1","height":"2","passthru":false,"outs":"end","topic":"BULB-2/cmnd/dimmer","min":0,"max":10,"step":1,"x":2790,"y":2250,"wires":[["727d34a9.94d1c4"]]},{"id":"727d34a9.94d1c4","type":"function","z":"6dd5ca4d.d1958c","name":"Get Brightness *","func":"var s = flow.get(\"BULB2_BRIGHTNESS\");\nif (s != undefined)\n\n//node.warn(\"S is of value \" + s)\n\n{\n    if (msg.payload == \"X\")\n    {\n        msg.payload = s;\n        return msg;\n    } else\n    if (msg.payload != s)\n    {\n        return msg;\n    }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2970,"y":2250,"wires":[["e83f00bb.3f63e"]],"info":"Edit for device being used"},{"id":"4daa09bf.586ed","type":"change","z":"6dd5ca4d.d1958c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"X","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3020,"y":2200,"wires":[["727d34a9.94d1c4","3f7172b7.834016"]]},{"id":"e83f00bb.3f63e","type":"function","z":"6dd5ca4d.d1958c","name":"Scale","func":"msg.payload = msg.payload * 10;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":3150,"y":2250,"wires":[["606fe2af.d55654"]]},{"id":"d1b68fa0.dab248","type":"function","z":"6dd5ca4d.d1958c","name":"Scale","func":"msg.payload = (msg.payload / 10);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":2560,"y":2250,"wires":[["6ccc868c.417c78","31523b12.6b0a14"]]},{"id":"12c72eb4.18b9d9","type":"ui_group","z":"","name":"BULB-2","tab":"e92ac76d.c24e7","order":6,"disp":true,"width":"3","collapse":false},{"id":"e92ac76d.c24e7","type":"ui_tab","z":"","name":"Real_World_Control","icon":"dashboard","order":13,"disabled":false,"hidden":false}]

The trick here being it checks if there is (or not) a stored value. If there isn't, it uses the new one from the slider.

I'll explain my reason.

As much as @krambriw is right.

Yes, instantaneous is an interesting concept.

So, there are delays which just are.

You move the mouse and click. Nothing happens. Did you really press the button or was it a miss?

This delay (feature) changes the colour of the button to indicate you didn't miss it and a short time there after when the command is acknowledged, it changes to the final colour.

I add a nominal 100ms delay just to make things look more real.

Just one more, I do not know your purpose or need using those gates but you should be aware that if the first one (after the MQTT in node) is off, I fear the correct statuses will not be presented if the bulb changes state

And it looks like turning the bulb ON from OFF opens the gates for brightness and ct but since the opening is delayed 3 seconds, it looks like the brightness & ct properties will be blocked for this initial ON command

That's because your electrons are faster than mine! I'm in the southern hemisphere. The electrons are slower here. :wink:

the gates are left overs from when I had it on multiple machines.

On the machine NOT being tested, I would stop messages getting through.

Yes the brightness control is stopped because when I turn the bulb off - via software - I get a message back saying the bulb is OFF and the brightness is 0.

I mentioned this problem. For a while when I turned the bulb on, it sat there blinking at me - because of the delay node - and I couldn't work out why.

Or it would indicate it was ON but not glowing.

Then I realised the brightness slider was on 0. Didn't help.

Then when I went to the dashboard and saw the brightness slider bobbing up and down..... I realised there was feedback there.

That was how I stopped that problem.

So you are all set now?

For now it seems to be working.

What happens in the next 12 hours - who knows?

:wink:

But thanks for the time and effort.

Now what I may need to do is work out how to make it support other devices controlling it.

That is a need that will crop up.
Not specifically for this, but other things I have.

As much as now I will try to keep it as one machine actually controlling the device, other things may need to control it, and need feedback (status, etc) and this to be shared.

I am not sure how that will work. Because as much as it will keep one machine as the only controller, how do I discemintae (?spelling) the status to multiple other devices?

If you want to distribute statuses to other clients I would publish those to specific & separate topics on the MQTT broker. In this way you can assure that other clients receives the correct information but they cannot interfere with the sources

disseminate or distribute is equivalent I guess

Yes, I do agree.

So I use different names in MQTT between the main and remote machines.

But the same thing is going to happen at that level sending status updates between the machines.

So in some ways it will be the same problem, just at a different level.

I don't really now. When I design a solution like this I always try to model an architecture like this:

devices <--> backend <--> frontend

For me the backend in this case is responsible for things like

  • controlling the devices
  • reading/receiving their statuses
  • serving commands from the frontend
  • providing status feedback to frontend
    etc etc

The frontend would be the typical client

  • sending commands to the backend
  • receiving feedbacks and status updates
    etc etc

The backend could be a NR instance, the frontend could be another NR instance or a any other client with proper interface to the NR backend

But I would never run several backends controlling the same devices for simpler home automation solutions like this. For redundancy reasons in professional solutions we would have to consider multi server systems but I guess we can skip that for these type of applications

If you look at your flow I think it has potential to be divided into a backend and frontend part respectively. Basically you could say anything belonging to the gui should not be part of the backend

If you use MQTT as the interface between backend and frontend you can have multiple machines with the frontend NR installed and they would all be synchronized with correct statuses

1 Like

You are talking to not just a village idiot, but an idiot of many villages.

As much as I kind of get this "front end" and "back end" stuff, I have no practical experience with it and I was hoping that was what I was doing.

Obviously not.

I think I will have to design some stuff in Node-Red to emulate the end device (light bulb for example) and see if I can get things working.

At one stage I had two front ends controlling the bulb.
I would adjust a slider on one and the other would obediently oblige to the same position.

It all started off nice, but quickly fell over for reasons unknown.

I made the two front ends by copying the code to two different tabs and was using flow context.

So as far as the code was concerned it was a whole other machine.

So while it was nice to adjust the settings on one and see it be reciprocated on the other, it didn't last long. :frowning:
Oh well.

More testing needed.

Here are 3 flows.

Flow 1 - the device:

[{"id":"ce19aee0.440758","type":"tab","label":"FAKE DEVICE","disabled":false,"info":""},{"id":"f9b782e.b756b","type":"mqtt in","z":"ce19aee0.440758","name":"","topic":"TEST-CHANNEL/IN","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":200,"y":400,"wires":[["cd60bcd5.cfcb7"]]},{"id":"b8b71445.5b897","type":"mqtt out","z":"ce19aee0.440758","name":"","topic":"TEST-CHANNEL/OUT","qos":"","retain":"","broker":"378c0403.8cda04","x":840,"y":400,"wires":[]},{"id":"cd60bcd5.cfcb7","type":"delay","z":"ce19aee0.440758","name":"","pauseType":"delay","timeout":"2","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":380,"y":400,"wires":[["5e96755.ab4850c","b8b71445.5b897"]]},{"id":"96b61562.fadb88","type":"debug","z":"ce19aee0.440758","name":"DEVICE OUT","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":820,"y":450,"wires":[]},{"id":"5e96755.ab4850c","type":"debug","z":"ce19aee0.440758","name":"DEVICE IN","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":610,"y":450,"wires":[]},{"id":"baef0906.70745","type":"inject","z":"ce19aee0.440758","name":"","topic":"","payload":"A","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":300,"wires":[["cd60bcd5.cfcb7"]]},{"id":"63e8988d.be1a8","type":"inject","z":"ce19aee0.440758","name":"","topic":"","payload":"B","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":230,"y":340,"wires":[["cd60bcd5.cfcb7"]]},{"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":""}]

Flow 2 - one of any number of devices controlling the device.

[{"id":"f4e2181b.a32fb8","type":"tab","label":"Control 1","disabled":false,"info":""},{"id":"ee5133ea.428548","type":"mqtt out","z":"f4e2181b.a32fb8","name":"","topic":"TEST-CHANNEL/IN","qos":"","retain":"","broker":"378c0403.8cda04","x":1260,"y":620,"wires":[]},{"id":"aa0566ed.d6eac8","type":"mqtt in","z":"f4e2181b.a32fb8","name":"","topic":"TEST-CHANNEL/OUT","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":330,"y":670,"wires":[["93e114ba.df096"]]},{"id":"93e114ba.df096","type":"change","z":"f4e2181b.a32fb8","name":"FLOW STATE","rules":[{"t":"set","p":"DEVICE1_STATUS","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":620,"wires":[["cf807b3f.c36708","2997266d.05f242","606d7505.236104"]]},{"id":"cf807b3f.c36708","type":"switch","z":"f4e2181b.a32fb8","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":620,"wires":[["25d06e4a.bd60c2"],["403d2508.772abc"]]},{"id":"25d06e4a.bd60c2","type":"change","z":"f4e2181b.a32fb8","name":"A","rules":[{"t":"set","p":"payload","pt":"msg","to":"red","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":570,"wires":[["bdc4c163.7389c8"]]},{"id":"403d2508.772abc","type":"change","z":"f4e2181b.a32fb8","name":"B","rules":[{"t":"set","p":"payload","pt":"msg","to":"lime","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":670,"wires":[["bdc4c163.7389c8"]]},{"id":"bdc4c163.7389c8","type":"ui_led","z":"f4e2181b.a32fb8","group":"ab063660.c0deb8","order":4,"width":"2","height":"1","label":"","labelPlacement":"right","labelAlignment":"left","colorForValue":[{"color":"red","value":"red","valueType":"str"},{"color":"lime","value":"lime","valueType":"str"}],"allowColorForValueInMessage":false,"name":"","x":700,"y":620,"wires":[]},{"id":"757cd38c.b06534","type":"ui_button","z":"f4e2181b.a32fb8","name":"","group":"ab063660.c0deb8","order":1,"width":"2","height":"1","passthru":false,"label":"{{msg.payload}}","tooltip":"","color":"","bgcolor":"","icon":"","payload":"x","payloadType":"str","topic":"","x":920,"y":620,"wires":[["928c8bed.38c06","f826c245.a300b8"]]},{"id":"928c8bed.38c06","type":"function","z":"f4e2181b.a32fb8","name":"","func":"var state = flow.get('DEVICE1_STATUS')||'OFF';\n//node.warn(state);\n\nswitch (state) {\n    case 'ON':\n        msg.payload = \"OFF\";\n        break;\n    case 'OFF':\n        msg.payload = \"ON\";\n        break;\n    default:\n        msg.payload = \"OFF\";\n        break;\n}\n\nnode.send(msg);","outputs":1,"noerr":0,"x":1040,"y":620,"wires":[["ee5133ea.428548","8f2515db.07276","2cb706a0.54ff12"]]},{"id":"2997266d.05f242","type":"debug","z":"f4e2181b.a32fb8","name":"IN","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":510,"y":530,"wires":[]},{"id":"8f2515db.07276","type":"debug","z":"f4e2181b.a32fb8","name":"OUT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1210,"y":690,"wires":[]},{"id":"2cb706a0.54ff12","type":"ui_text","z":"f4e2181b.a32fb8","group":"ab063660.c0deb8","order":3,"width":"1","height":"1","name":"","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1210,"y":730,"wires":[]},{"id":"606d7505.236104","type":"link out","z":"f4e2181b.a32fb8","name":"","links":["ee3d02c7.48e59","5b69d11f.3253b"],"x":475,"y":730,"wires":[]},{"id":"ee3d02c7.48e59","type":"link in","z":"f4e2181b.a32fb8","name":"","links":["606d7505.236104"],"x":1095,"y":730,"wires":[["2cb706a0.54ff12"]]},{"id":"5b69d11f.3253b","type":"link in","z":"f4e2181b.a32fb8","name":"","links":["606d7505.236104"],"x":835,"y":620,"wires":[["757cd38c.b06534"]]},{"id":"f826c245.a300b8","type":"change","z":"f4e2181b.a32fb8","name":"Toggle","rules":[{"t":"set","p":"payload","pt":"msg","to":"Pressed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":660,"wires":[["757cd38c.b06534"]]},{"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":"ab063660.c0deb8","type":"ui_group","z":"","name":"D 1","tab":"94b6c6b8.090c78","order":1,"disp":true,"width":"6","collapse":false},{"id":"94b6c6b8.090c78","type":"ui_tab","z":"","name":"TEST DEVICE","icon":"dashboard","order":24,"disabled":false,"hidden":false}]

Third flow

[{"id":"6f38a32a.a80104","type":"tab","label":"Control 2","disabled":false,"info":""},{"id":"b2ef0ed0.aad1b","type":"mqtt out","z":"6f38a32a.a80104","name":"","topic":"TEST-CHANNEL/IN","qos":"","retain":"","broker":"378c0403.8cda04","x":1110,"y":200,"wires":[]},{"id":"b7f8e566.c6b398","type":"mqtt in","z":"6f38a32a.a80104","name":"","topic":"TEST-CHANNEL/OUT","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":170,"y":250,"wires":[["8dcc07b3.6aa6c8"]]},{"id":"8dcc07b3.6aa6c8","type":"change","z":"6f38a32a.a80104","name":"FLOW STATE","rules":[{"t":"set","p":"DEVICE1_STATUS","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":200,"wires":[["86b5517.36d06b","ec3c9dfc.de8108","7f3e1dd3.0a0dd4"]]},{"id":"86b5517.36d06b","type":"switch","z":"6f38a32a.a80104","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"OFF","vt":"str"},{"t":"eq","v":"ON","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":350,"y":200,"wires":[["e11ffb0d.536e6"],["4d80d8b2.d86728"]]},{"id":"e11ffb0d.536e6","type":"change","z":"6f38a32a.a80104","name":"A","rules":[{"t":"set","p":"payload","pt":"msg","to":"red","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":150,"wires":[["d1da8f15.600c6"]]},{"id":"4d80d8b2.d86728","type":"change","z":"6f38a32a.a80104","name":"B","rules":[{"t":"set","p":"payload","pt":"msg","to":"lime","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":250,"wires":[["d1da8f15.600c6"]]},{"id":"d1da8f15.600c6","type":"ui_led","z":"6f38a32a.a80104","group":"d8ac6efd.16da3","order":4,"width":"2","height":"1","label":"","labelPlacement":"right","labelAlignment":"left","colorForValue":[{"color":"red","value":"red","valueType":"str"},{"color":"lime","value":"lime","valueType":"str"}],"allowColorForValueInMessage":false,"name":"","x":540,"y":200,"wires":[]},{"id":"6e3abf3f.d051b8","type":"ui_button","z":"6f38a32a.a80104","name":"","group":"d8ac6efd.16da3","order":1,"width":"2","height":"1","passthru":false,"label":"{{msg.payload}}","tooltip":"","color":"","bgcolor":"","icon":"","payload":"x","payloadType":"str","topic":"","x":740,"y":200,"wires":[["f94ec5b7.72feb8","7129367a.b3b8d"]]},{"id":"f94ec5b7.72feb8","type":"function","z":"6f38a32a.a80104","name":"","func":"var state = flow.get('DEVICE1_STATUS')||'OFF';\n//node.warn(state);\n\nswitch (state) {\n    case 'ON':\n        msg.payload = \"OFF\";\n        break;\n    case 'OFF':\n        msg.payload = \"ON\";\n        break;\n    default:\n        msg.payload = \"OFF\";\n        break;\n}\n\nnode.send(msg);","outputs":1,"noerr":0,"x":890,"y":200,"wires":[["b2ef0ed0.aad1b","4e818502.bed73c","64a98921.7fed18"]]},{"id":"ec3c9dfc.de8108","type":"debug","z":"6f38a32a.a80104","name":"IN","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":350,"y":110,"wires":[]},{"id":"4e818502.bed73c","type":"debug","z":"6f38a32a.a80104","name":"OUT","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1060,"y":270,"wires":[]},{"id":"64a98921.7fed18","type":"ui_text","z":"6f38a32a.a80104","group":"d8ac6efd.16da3","order":3,"width":"1","height":"1","name":"","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1060,"y":310,"wires":[]},{"id":"93323b7.00835c8","type":"link in","z":"6f38a32a.a80104","name":"","links":["7f3e1dd3.0a0dd4"],"x":925,"y":310,"wires":[["64a98921.7fed18"]]},{"id":"7f3e1dd3.0a0dd4","type":"link out","z":"6f38a32a.a80104","name":"","links":["93323b7.00835c8","22963528.ddad2a"],"x":325,"y":310,"wires":[]},{"id":"22963528.ddad2a","type":"link in","z":"6f38a32a.a80104","name":"","links":["7f3e1dd3.0a0dd4"],"x":655,"y":200,"wires":[["6e3abf3f.d051b8"]]},{"id":"7129367a.b3b8d","type":"change","z":"6f38a32a.a80104","name":"Toggle","rules":[{"t":"set","p":"payload","pt":"msg","to":"Pressed","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":240,"wires":[["6e3abf3f.d051b8"]]},{"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":"d8ac6efd.16da3","type":"ui_group","z":"","name":"D 2","tab":"94b6c6b8.090c78","order":2,"disp":true,"width":"6","collapse":false},{"id":"94b6c6b8.090c78","type":"ui_tab","z":"","name":"TEST DEVICE","icon":"dashboard","order":24,"disabled":false,"hidden":false}]

You will have to edit the MQTT nodes, but only their IP addresses.

This works?
The LED is a bit over the top but it helps get a visual state conveyed

The button changes when pressed.

Right, exactly (I will make a short example of your earlier shared flow, just a few minutes remaining...)

You got the idea. I guess the third flow is no different to the second??

Well, only in name..... So it can emulate another device.

If you import the flow again, you would have to rename the previous one first.