MQTT is driving me crazy with inconsistent doings

I'm not deploying anyway....

N.P. It is just to establish a working base line and how the messages go between things.

There is an initial glitch for the first time it is run as the flow context isn't set. But there after it is ok.

This is how I would design the backend. With some clever coding I'm sure it can be made generic so it can handle all your bulbs, just needed is to set the topics based on incoming messages instead of hardcoding

I guess with real devices this will fix itself since the statuses will arrive sooner or later? At least this is the case with my Shellies, the send out their current statuses at regular & configurable time intervals

Ok, I have that structure you showed me but keeping things more local.
I think it was @JGKK to whom I showed that bit of code.

Yeah, I am not wanting your stratargy with too many status messages happening.

The initial glitch will sort itself out as you say, and I agree. (or is that the other way around?)

I am slowly trying to apply it to my existing stuff, cutting out the old and putting in the new.

On a crowded tab it is annoying.

If/when this works, I will then roll it out to other devices like them.
Not that this will really be hugely done, just ask I explained: It is for one machine, but testing/development is done on another bigger/faster one and it would be nicer if I didn't have to disable the stuff on the other machine when developing stuff on this one.

It can make for some annoying things happening.

This is what I think should all be stuffed inte the frontend. Looks a bit messy but I'm sure you can navigate through it :wink:
The backend you shall install only once, controlling your devices etc and the frontend in as many flows/machines you like, All and only communication between them is via MQTT

In this way you keep the various parts of the "business logic" separated, it will be much easier to follow and maintain. I'm not sure if you need all those gates and delays at the end. To start I would take them all out and see what works. Eventually add them again one-by-one if needed

Wow! Thanks.

The gates are (as I mentioned) only for isolation during testing.
The delay is there to give it a realistic look/feel when I press the button.

It is a bit tricky seeing it all as the links aren't shown.

Yeah, ok. I shall look at how you did it. But I am trying to do what you did but slightly different. :wink:

I shall muddle through it an see what I get. I will use your example to help me if/when I get stuck on things.

Again: Greatly appreciated. It is nice to see we are kind of thinking along the same path. Though I do get you are more flexing to my style of doing it.
But we are all different in how we lay out the flows.

I am still playing with that.

I'd better leave you alone so you can do that which you need to do.

It's my pleasure, always nice with a challenge for your mind!!!

The key essence here, at least my philosophy, break things down and separate what can/should be done as a service and presentation respectively. It will make it easier to understand, debug and maintain. It is also required if you want to serve multiple clients

The beauty contest to follow is to make a generic backend and frontend that will handle all your existing and future bulbs. Like bulb-x or something. So you might then have to think about the MQTT structure the bulbs are publishing to. Now you have "BULB-1/#". I do not know if it will be ok for the backend to subscribe to "#", it might be we would receive a lot of other "rubbish" as well. So it might be better if bulbs would publish like "MyBulbs/BULB-1/#" and the backend subscribes to "MyBulbs/#" if you wanna go generic. Obviously all publishing to MQTT would need a similar re-thinking

However, nothing prevents making x copies of the backed flow, one for each bulb and the same for each frontend flow. It will be efficient & good enough I think, it's not just as elegant and it involves more copy & pasting and it will be boring if you need to change anything else in the flows, you will have to edit all of them

Thanks.

It would seem you know a lot more about this than me.

Yeah, the idea about the topic is good. I may apply it that way. I never thought it would get to this scale.

Here is my last working one.

[{"id":"e7854c23.60add","type":"mqtt out","z":"26262ba1.62dcbc","name":"","topic":"","qos":"","retain":"","broker":"378c0403.8cda04","x":3550,"y":570,"wires":[]},{"id":"71acbf80.1650a","type":"inject","z":"26262ba1.62dcbc","name":"Close","topic":"CONTROL","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2360,"y":530,"wires":[["d8c1d7dc.092c28"]]},{"id":"89ec3dd5.a9b3c8","type":"inject","z":"26262ba1.62dcbc","name":"Open","topic":"CONTROL","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2360,"y":570,"wires":[["d8c1d7dc.092c28"]]},{"id":"d8c1d7dc.092c28","type":"q-gate","z":"26262ba1.62dcbc","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":2360,"y":450,"wires":[["232e07c6.42adf","61c9ac9b.3ccc34"]]},{"id":"232e07c6.42adf","type":"switch","z":"26262ba1.62dcbc","name":"EDIT *","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":2540,"y":450,"wires":[["dd1294d3.6b7e08"],["1b02fc4a.d70b9c"]],"info":"Edit for device being used"},{"id":"1b02fc4a.d70b9c","type":"json","z":"26262ba1.62dcbc","name":"","property":"payload","action":"","pretty":false,"x":2540,"y":520,"wires":[["66c09e27.b6e788"]]},{"id":"dd1294d3.6b7e08","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":2680,"y":450,"wires":[["62362580.ce602c"]]},{"id":"66c09e27.b6e788","type":"function","z":"26262ba1.62dcbc","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,"x":2680,"y":520,"wires":[["c53d10dc.0cf348"],["d353aeaf.c4c77"],["4018bf5a.9eb458"]],"outputLabels":["POWER","DIMMER","CT"]},{"id":"e20960d2.84739","type":"mqtt in","z":"26262ba1.62dcbc","name":"Bulb-1 *","topic":"BULB-1/#","qos":"2","datatype":"auto","broker":"378c0403.8cda04","x":2360,"y":400,"wires":[["d8c1d7dc.092c28"]],"info":"This needs editing for different BULBS"},{"id":"23d90ac9.a2dace","type":"link out","z":"26262ba1.62dcbc","name":"","links":["43219b47.a0bd7c"],"x":2505,"y":570,"wires":[]},{"id":"43219b47.a0bd7c","type":"link in","z":"26262ba1.62dcbc","name":"","links":["23d90ac9.a2dace"],"x":2605,"y":570,"wires":[[]]},{"id":"c53d10dc.0cf348","type":"link out","z":"26262ba1.62dcbc","name":"Power","links":["63723e08.c23468"],"x":2795,"y":490,"wires":[]},{"id":"63723e08.c23468","type":"link in","z":"26262ba1.62dcbc","name":"Power","links":["c53d10dc.0cf348"],"x":2905,"y":490,"wires":[["e9eba137.55889"]]},{"id":"ed51814e.94f98","type":"ui_button","z":"26262ba1.62dcbc","name":"BULB#1","group":"7893c6c4.30ede","order":2,"width":"1","height":"3","passthru":false,"label":"{{msg.icon}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"X","payloadType":"str","topic":"","x":3450,"y":440,"wires":[["e9864ae1.8f26e8","63d2cb96.03a5b4"]]},{"id":"a72b284c.5a127","type":"ui_slider","z":"26262ba1.62dcbc","name":"Brightness","label":"Brightness","tooltip":"","group":"7893c6c4.30ede","order":3,"width":"1","height":"2","passthru":false,"outs":"end","topic":"","min":0,"max":10,"step":1,"x":2910,"y":750,"wires":[["6ddc3fad.e97fa"]]},{"id":"40c780ec.227a7","type":"ui_slider","z":"26262ba1.62dcbc","name":"Temp'","label":"Temp'","tooltip":"","group":"7893c6c4.30ede","order":4,"width":"1","height":"2","passthru":false,"outs":"end","topic":"","min":0,"max":"20","step":1,"x":2890,"y":830,"wires":[["7461688c.631068"]]},{"id":"e9864ae1.8f26e8","type":"change","z":"26262ba1.62dcbc","name":"Pressed","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":3450,"y":490,"wires":[["ed51814e.94f98"]]},{"id":"a3660dfe.bc581","type":"function","z":"26262ba1.62dcbc","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,"x":3000,"y":530,"wires":[["e1117d83.9da71"]]},{"id":"e1117d83.9da71","type":"change","z":"26262ba1.62dcbc","name":"#1 *","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-1/cmnd/power1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3000,"y":570,"wires":[["3a8debe2.12aff4"]],"info":"This needs editing for different BULBS"},{"id":"3a8debe2.12aff4","type":"delay","z":"26262ba1.62dcbc","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":3210,"y":570,"wires":[["c6ad5215.8fbb88"]]},{"id":"1f2d9ccc.5d4f2b","type":"inject","z":"26262ba1.62dcbc","name":"Close","topic":"CONTROL","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3190,"y":610,"wires":[["c6ad5215.8fbb88"]]},{"id":"afb2c4dc.a502a","type":"inject","z":"26262ba1.62dcbc","name":"Open","topic":"CONTROL","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3190,"y":650,"wires":[["c6ad5215.8fbb88"]]},{"id":"c6ad5215.8fbb88","type":"gate","z":"26262ba1.62dcbc","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":3400,"y":570,"wires":[["e7854c23.60add","d04ad855.b36298"]]},{"id":"63d2cb96.03a5b4","type":"link out","z":"26262ba1.62dcbc","name":"","links":["9196592a.d2573","a012ca13.d83008"],"x":3585,"y":440,"wires":[]},{"id":"9196592a.d2573","type":"link in","z":"26262ba1.62dcbc","name":"","links":["63d2cb96.03a5b4"],"x":2905,"y":530,"wires":[["a3660dfe.bc581"]]},{"id":"d04ad855.b36298","type":"debug","z":"26262ba1.62dcbc","name":"*****  OUTPUT  *****","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":3440,"y":650,"wires":[]},{"id":"61c9ac9b.3ccc34","type":"debug","z":"26262ba1.62dcbc","name":"***** INPUT *****","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":2580,"y":410,"wires":[]},{"id":"7ea38ad6.724e2c","type":"switch","z":"26262ba1.62dcbc","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":3230,"y":440,"wires":[["e03edc42.6fd19"],["fa51a460.293cf"]]},{"id":"fa51a460.293cf","type":"change","z":"26262ba1.62dcbc","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":3230,"y":490,"wires":[["ed51814e.94f98"]]},{"id":"e03edc42.6fd19","type":"change","z":"26262ba1.62dcbc","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":3230,"y":390,"wires":[["ed51814e.94f98"]]},{"id":"e9eba137.55889","type":"change","z":"26262ba1.62dcbc","name":"FLOW STATE *","rules":[{"t":"set","p":"BULB1_POWER","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":3030,"y":490,"wires":[["7ea38ad6.724e2c"]],"info":"Edit for device being used"},{"id":"ad2e937d.122ae","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":2680,"y":370,"wires":[["76fd2a99.340a9c"]]},{"id":"5a878855.7d735","type":"link in","z":"26262ba1.62dcbc","name":"LWT","links":["6124b92a.c4a78","62362580.ce602c"],"x":2505,"y":370,"wires":[["ad2e937d.122ae"]]},{"id":"76fd2a99.340a9c","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":2830,"y":340,"wires":[["3bfae8d.bc31198","387e86e7.cbb53a"],["7c5c9e59.8be31"]]},{"id":"3bfae8d.bc31198","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":2990,"y":340,"wires":[["ddaf6334.7f0748","3ee3220d.cf1dee"]]},{"id":"387e86e7.cbb53a","type":"link out","z":"26262ba1.62dcbc","name":"Online","links":["bd153540.f944b8","cfbb9fa5.e275d8"],"x":2945,"y":300,"wires":[]},{"id":"7c5c9e59.8be31","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":2840,"y":390,"wires":[["beda217f.ebf5c8","3ee3220d.cf1dee"]]},{"id":"d6492913.f52d78","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"Online","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2680,"y":300,"wires":[["76fd2a99.340a9c"]]},{"id":"7c86828c.f7536c","type":"inject","z":"26262ba1.62dcbc","name":"","topic":"","payload":"Offline","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2680,"y":260,"wires":[["76fd2a99.340a9c"]]},{"id":"1f09a901.c3a44f","type":"change","z":"26262ba1.62dcbc","name":"LWT *","rules":[{"t":"set","p":"payload","pt":"msg","to":"BULB1_LWT","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":2540,"y":340,"wires":[["76fd2a99.340a9c"]],"info":"Edit for device being used"},{"id":"ddaf6334.7f0748","type":"link out","z":"26262ba1.62dcbc","name":"To button","links":["25bb3a98.ea8686"],"x":3105,"y":390,"wires":[]},{"id":"3ee3220d.cf1dee","type":"link out","z":"26262ba1.62dcbc","name":"Disable","links":["ba5efb96.425db8"],"x":3105,"y":340,"wires":[]},{"id":"beda217f.ebf5c8","type":"function","z":"26262ba1.62dcbc","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,"x":2980,"y":390,"wires":[["ddaf6334.7f0748"]]},{"id":"698725d6.755f3c","type":"inject","z":"26262ba1.62dcbc","name":"Set","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"onceDelay":"2","x":2360,"y":340,"wires":[["1f09a901.c3a44f"]]},{"id":"62362580.ce602c","type":"link out","z":"26262ba1.62dcbc","name":"LWT","links":["5a878855.7d735"],"x":2795,"y":450,"wires":[]},{"id":"d353aeaf.c4c77","type":"link out","z":"26262ba1.62dcbc","name":"Dimmer","links":["7e98e20.030e5a"],"x":2795,"y":520,"wires":[]},{"id":"7e98e20.030e5a","type":"link in","z":"26262ba1.62dcbc","name":"Dimmer","links":["d353aeaf.c4c77"],"x":2325,"y":750,"wires":[["1fa4070.4d730f9"]]},{"id":"4018bf5a.9eb458","type":"link out","z":"26262ba1.62dcbc","name":"CT","links":["c6c97028.56b3d8"],"x":2795,"y":550,"wires":[]},{"id":"c6c97028.56b3d8","type":"link in","z":"26262ba1.62dcbc","name":"CT","links":["4018bf5a.9eb458"],"x":2325,"y":830,"wires":[["2133c782.f276c8"]]},{"id":"25bb3a98.ea8686","type":"link in","z":"26262ba1.62dcbc","name":"","links":["ddaf6334.7f0748"],"x":3345,"y":440,"wires":[["ed51814e.94f98"]]},{"id":"ba5efb96.425db8","type":"link in","z":"26262ba1.62dcbc","name":"","links":["3ee3220d.cf1dee"],"x":2775,"y":790,"wires":[["a72b284c.5a127","40c780ec.227a7"]]},{"id":"a012ca13.d83008","type":"link in","z":"26262ba1.62dcbc","name":"","links":["1b6da9f5.d79bb6","63d2cb96.03a5b4","916b5adc.96a95"],"x":2325,"y":670,"wires":[["959b7a67.58a168"]]},{"id":"33f4e071.e9721","type":"function","z":"26262ba1.62dcbc","name":"Scale","func":"msg.payload = (msg.payload / 10);\nreturn msg;","outputs":1,"noerr":0,"x":2740,"y":750,"wires":[["e0da20a5.b84898","a72b284c.5a127"]]},{"id":"7435589b.f987d8","type":"inject","z":"26262ba1.62dcbc","name":"Close","topic":"CONTROL","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2580,"y":870,"wires":[["623e6e08.f29118","aefc828.74ed58"]]},{"id":"e87ae400.30783","type":"inject","z":"26262ba1.62dcbc","name":"Open","topic":"CONTROL","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2580,"y":910,"wires":[["623e6e08.f29118","aefc828.74ed58"]]},{"id":"4985fda2.801504","type":"range","z":"26262ba1.62dcbc","minin":"153","maxin":"500","minout":"1","maxout":"20","action":"scale","round":false,"property":"payload","name":"","x":2740,"y":830,"wires":[["d6e48222.06cae","40c780ec.227a7"]]},{"id":"623e6e08.f29118","type":"gate","z":"26262ba1.62dcbc","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":2580,"y":750,"wires":[["33f4e071.e9721"]]},{"id":"aefc828.74ed58","type":"gate","z":"26262ba1.62dcbc","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":2580,"y":830,"wires":[["4985fda2.801504"]]},{"id":"959b7a67.58a168","type":"switch","z":"26262ba1.62dcbc","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":2420,"y":670,"wires":[["71e8adeb.8de2e4"],["2b279690.9b9592"]]},{"id":"71e8adeb.8de2e4","type":"change","z":"26262ba1.62dcbc","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":2580,"y":640,"wires":[["623e6e08.f29118","aefc828.74ed58"]]},{"id":"2b279690.9b9592","type":"change","z":"26262ba1.62dcbc","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":2580,"y":670,"wires":[["b25ddd33.70e78"]]},{"id":"b25ddd33.70e78","type":"delay","z":"26262ba1.62dcbc","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2590,"y":700,"wires":[["623e6e08.f29118","aefc828.74ed58"]]},{"id":"e0da20a5.b84898","type":"change","z":"26262ba1.62dcbc","name":"Set Brightness *","rules":[{"t":"set","p":"BULB1_BRIGHTNESS","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2770,"y":700,"wires":[[]],"info":"Edit for device being used"},{"id":"d6e48222.06cae","type":"change","z":"26262ba1.62dcbc","name":"Set Temperature *","rules":[{"t":"set","p":"BULB1_CT","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2780,"y":870,"wires":[[]],"info":"Edit for device being used"},{"id":"1fa4070.4d730f9","type":"switch","z":"26262ba1.62dcbc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"}],"checkall":"true","repair":false,"outputs":1,"x":2420,"y":750,"wires":[["623e6e08.f29118"]]},{"id":"2133c782.f276c8","type":"switch","z":"26262ba1.62dcbc","name":"","property":"payload","propertyType":"msg","rules":[{"t":"istype","v":"number","vt":"number"}],"checkall":"true","repair":false,"outputs":1,"x":2420,"y":830,"wires":[["aefc828.74ed58"]]},{"id":"93166ee7.52c96","type":"function","z":"26262ba1.62dcbc","name":"Scale","func":"msg.payload = msg.payload * 10;\nreturn msg;","outputs":1,"noerr":0,"x":3260,"y":750,"wires":[["49fd83ae.fce074"]]},{"id":"b14aaa1.44661d8","type":"change","z":"26262ba1.62dcbc","name":"Topic *","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-1/cmnd/ct","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3400,"y":830,"wires":[["1fefec62.f10e74"]],"info":"Set for brightness"},{"id":"1595ada.2061052","type":"range","z":"26262ba1.62dcbc","minin":"1","maxin":"20","minout":"153","maxout":"500","action":"scale","round":false,"property":"payload","name":"","x":3270,"y":830,"wires":[["b14aaa1.44661d8"]]},{"id":"a5da5e1e.03d17","type":"link out","z":"26262ba1.62dcbc","name":"","links":["b81aa997.35bf1"],"x":3695,"y":830,"wires":[]},{"id":"49fd83ae.fce074","type":"change","z":"26262ba1.62dcbc","name":"Topic","rules":[{"t":"set","p":"topic","pt":"msg","to":"BULB-1/cmnd/dimmer","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3400,"y":750,"wires":[["1fefec62.f10e74"]]},{"id":"b31024bc.affdf8","type":"inject","z":"26262ba1.62dcbc","name":"Close","topic":"CONTROL","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3590,"y":750,"wires":[["1fefec62.f10e74"]]},{"id":"8053b10a.d53f","type":"inject","z":"26262ba1.62dcbc","name":"Open","topic":"CONTROL","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":3590,"y":790,"wires":[["1fefec62.f10e74"]]},{"id":"6ddc3fad.e97fa","type":"function","z":"26262ba1.62dcbc","name":"Get Brightness *","func":"var s = flow.get(\"BULB1_BRIGHTNESS\");\nif (s != undefined)\n\nnode.warn(\"S value is \" + s);\nnode.status({fill: \"green\",text:s});\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,"x":3090,"y":750,"wires":[["93166ee7.52c96"]],"info":"Edit for device being used"},{"id":"7461688c.631068","type":"function","z":"26262ba1.62dcbc","name":"Get Temperature *","func":"var s = flow.get(\"BULB1_CT\");\nif (s != undefined)\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,"x":3100,"y":830,"wires":[["1595ada.2061052"]],"info":"Edit for device being used"},{"id":"cfbb9fa5.e275d8","type":"link in","z":"26262ba1.62dcbc","name":"","links":["60102797.ec11e8","387e86e7.cbb53a"],"x":2805,"y":630,"wires":[["a05fac8b.a0869"]]},{"id":"99e8a384.c34bd8","type":"change","z":"26262ba1.62dcbc","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"X","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3090,"y":700,"wires":[["6ddc3fad.e97fa","7461688c.631068"]]},{"id":"b81aa997.35bf1","type":"link in","z":"26262ba1.62dcbc","name":"","links":["a5da5e1e.03d17"],"x":3155,"y":530,"wires":[["3a8debe2.12aff4"]]},{"id":"5d4e0021.5d99f8","type":"delay","z":"26262ba1.62dcbc","name":"Delay","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":2980,"y":430,"wires":[["3ee3220d.cf1dee"]]},{"id":"1fefec62.f10e74","type":"gate","z":"26262ba1.62dcbc","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":3590,"y":830,"wires":[["a5da5e1e.03d17"]]},{"id":"db3c66e1.653e08","type":"inject","z":"26262ba1.62dcbc","name":"Close","topic":"CONTROL","payload":"close","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2940,"y":620,"wires":[["a05fac8b.a0869"]]},{"id":"d84830d.1a087d","type":"inject","z":"26262ba1.62dcbc","name":"Open","topic":"CONTROL","payload":"open","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":2940,"y":660,"wires":[["a05fac8b.a0869"]]},{"id":"a05fac8b.a0869","type":"gate","z":"26262ba1.62dcbc","name":"","controlTopic":"control","defaultState":"open","openCmd":"open","closeCmd":"close","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":2940,"y":700,"wires":[["99e8a384.c34bd8"]]},{"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":"7893c6c4.30ede","type":"ui_group","z":"","name":"BULB-1","tab":"aa487daa.33c1c","order":4,"disp":true,"width":"4","collapse":false},{"id":"aa487daa.33c1c","type":"ui_tab","z":"","name":"Real_World_Control","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

What was killing me was the preservation when the device first powers up.
It didn't keep its previous level.

That had me going in circles for a long time.

But now I think it is working as it has worked thorugh my testing.
So ..... Let's hope.

Looks as it would work, at least for one bulb :wink:

Only thing, I see a warning in the function nodes "Get Brightness" and "GetTemperature" . Maybe not critical but fix it anyway

if (s !== undefined)
etc etc


Good catch.

I am still not sure about this, though I probably should be.

I want it to happen if s has not been defined a a flow context.

So I don't know if that mean I should use == or ===.

if (s != undefined) evaluates to true also if s is null and not only when it's undefined.

Then I think that is better as it covers more possibilities.

I am not sure you are on the right track yet Andrew.

You can have as many machines control the ligth as you want - just have them all talk to the same broker - not one on each machine

Then make sure you use the Tasmota messages correctly CMND STATE etc

Each machine should only send CMNDs to the one broker and they should only update their buttons/sliders etc on receipt of the STATE result from the same broker. - This will keep them all in check and will ensure if something is changed on one it will be reflected in all the others.

Craig

Yep, we have exchanged some ideas and possible flows offline, I'm sure we will reach there
Maybe we even can share something later if we manage to make it working correctly

The state of the button should be learned from a subscription to the broker. Your action driven by the button should send out a new message that says what the state of the button is now. It's important make that message retained so that newly subscribed clients get that message to know what the current state is. When the server starts up, it should write out the current state of the button to update any retained state that may be wrong.

Hey @greggwon.

This has been a sore point for me for a long time.

I am hoping that the messages (states) are retained.

But earlier on they didn't seem to be received. This is why I went to two MQTT nodes.
One receiving the general (overall) message for the device in question, and another one for the specific thing like LWT.

Anyway, things are progressing slowly.

Thanks though for the post. It is annoying because it can be working fine while I am testing it and I just do one more test - to be sure to be sure - and.... BANG! It goes crazy.

So I don't know if I am just unlucky or am poking a wasp's nest.

Time will tell.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.