Variable switching in flow not working as expected

(Second go at this.)
I posted one but it wasn't good enough, so I worked on it to get it even better. But not perfect.

Ok, thanks for all the help with my recent questions.

Here is the flow as best I can make it.

** There is the GATE node used. NON-standard. I can't find a better way around this.
(And the LED node)

This is an entire flow, so it will import as a whole new page.
(Just to be nicer for anyone importing it.)
There is a GUI side to it. I'll get to that shortly.

Idea:
There are two relays that control power to charge devices. (Phones, etc)
A phone (or device) is plugged in to the charger, or the charger is plugged into the device - as is usual.
When the device needs power, it sends a request (simulated by inject nodes).
That then starts the two relays turning on/off "searching" for which one will charge the device.
When the device sees power it sends a detected signal back (again: simulated by the inject nodes)
That signal stops the searching and the relays stop toggling. (This is done at about an 8 second interval, giving time for the plug pack to power up and the device to see it is being charged.)

When the device is full - or unplugged - it sends a FULL or DISCONNECTED signal and the relay is released.

That is the main bit.

It gets tricky when/if a second request is sent by another device.
It is simple to know which charger to use, but it is needed to keep the signals separate.

This is where the flow.who comes into it.
Given the message.who will be different the new signal is sent to the second part of the flow.
That turns on the relay with the REQUEST signal.

But it isn't working as expected.
It seems to not work reliably when there is no flow.who set (for the first time around on a new session) and it is sent to the wrong part of the flow.

The GUI:
There is two sets of buttons for the two devices.
There is a Device1 power request,
Device 1 power seen,
Device 1 Full,
Device 1 Un-Plugged

Likewise for Device 2.
Press either request and the LEDs should toggle at about every 12 seconds or so.
This is to give time for the power to be "seen" and the message sent that it is available.
Press the Detected button when ever.
That will stop the toggle.
Press either the Full or UnPlugged button and the relay (LED) will turn off and all will go back to doing nothing.

Repeat (with same or other device) and select which ever LED with the Detected button.

Now, press the other Request button.
The other LED will come on.
(All good so far)

But that's where it all falls over.
Pressing that device's Full, or UnPlugged button should turn THAT LED Off.
It doesn't. It turns the other's LED off.

Stuck there.
Thanks in advance for looking and any help received.

Here is the flow:
[{"id":"53ee0b9d.14f434","type":"debug","z":"6857e430.f6d30c","name":"Second device command","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1180,"y":1620,"wires":[]}]

Is someone bored enough to have a play with this and see what I am trying to do and maybe find out why it isn't doing what I hope it should?

Once again, the title doesn't explain anything about the problem you are experiencing.

In order to be useful for other people with similar problems who are searching the forum, and also to allow people who respond to see from the title if they might know the answer, it is good practice to make the title relevant to the problem...

3 Likes

That flow only contains one debug node...

1 Like

That's weird.

This is the screen shot of the flow:

I won't argue. I am trying to be as helpful as possible as much as possible.

I'm not perfect.

This flow has me going nuts.

I nearly posted a bad version of the flow and deleted the post shortly there after.
I then sat down and nutted out more things with it and nearly got it working.

I can't explain the problem in the space provided, so I improvise.
Sure, I am not good at it, but I have to do through the motions of learning to get better.

Because it was said that there is only one debug node in the entire flow, here is an export of the flow again:

I counted about 12 debug nodes.

[{"id":"6857e430.f6d30c","type":"tab","label":"Flow 3","disabled":false,"info":""},{"id":"46b020fb.fbb12","type":"mqtt in","z":"6857e430.f6d30c","name":"","topic":"POWER/REQUEST1","qos":"2","datatype":"auto","broker":"8a2e80be.f7c928","x":510,"y":650,"wires":[["193d798f.7f3b4e","f1b5d35f.9101d"]]},{"id":"f1b5d35f.9101d","type":"debug","z":"6857e430.f6d30c","name":"********** Device Input ***********","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":710,"y":750,"wires":[]},{"id":"2d220ce9.1e5e0c","type":"switch","z":"6857e430.f6d30c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"REQUEST","vt":"str"},{"t":"eq","v":"DETECTED","vt":"str"},{"t":"eq","v":"FULL","vt":"str"},{"t":"eq","v":"DISCONNECTED","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1140,"y":650,"wires":[["ec2e36aa.e5389"],["41558571.297f34","b771e11.08c87a"],["f27aa38a.279858","c21a245b.a732d8"],["f27aa38a.279858","c21a245b.a732d8"]],"outputLabels":["Request","Detected","Full",null]},{"id":"ec2e36aa.e5389","type":"change","z":"6857e430.f6d30c","name":"start","rules":[{"t":"set","p":"payload","pt":"msg","to":"start","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":620,"wires":[["eea97116.3cd3d8","bc4bbb62.2cd07"]]},{"id":"41558571.297f34","type":"change","z":"6857e430.f6d30c","name":"reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"cancel","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":650,"wires":[["eea97116.3cd3d8","ca6ffad5.144e5"]]},{"id":"eea97116.3cd3d8","type":"mytimeout","z":"6857e430.f6d30c","name":"","outtopic":"","outsafe":"1","outwarning":"","outunsafe":"0","warning":"","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1350,"y":740,"wires":[["8f861653.dd9798","9eed7175.b86bf"],["8ead79e1.cc549"]]},{"id":"f27aa38a.279858","type":"change","z":"6857e430.f6d30c","name":"reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":1330,"y":680,"wires":[["eea97116.3cd3d8","7307333f.008e14"]]},{"id":"5a84ac71.b0bdb4","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"REQUEST","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":530,"y":500,"wires":[["3c73ee77.0d2762"]]},{"id":"ab025bd8.105d2","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"DETECTED","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":520,"y":530,"wires":[["2b6dbbd.91f5e44"]]},{"id":"65dceced.e158c4","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"FULL","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":560,"wires":[["e98e2197.7bccc8"]]},{"id":"8f861653.dd9798","type":"debug","z":"6857e430.f6d30c","name":"Output","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1600,"y":760,"wires":[]},{"id":"b1cfc72a.bd866","type":"debug","z":"6857e430.f6d30c","name":"Message","active":false,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":1790,"y":920,"wires":[]},{"id":"57d5a16d.698ed","type":"switch","z":"6857e430.f6d30c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1350,"y":870,"wires":[["938bfc97.fe9928"]]},{"id":"42999298.f34cbc","type":"trigger","z":"6857e430.f6d30c","op1":"stop","op2":"go","op1type":"str","op2type":"str","duration":"2","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":1200,"y":830,"wires":[["c9cc6e2a.2dcd18"]]},{"id":"b3432ef6.eec208","type":"gate","z":"6857e430.f6d30c","name":"","controlTopic":"control","defaultState":"open","openCmd":"go","closeCmd":"stop","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1190,"y":870,"wires":[["57d5a16d.698ed"]]},{"id":"c9cc6e2a.2dcd18","type":"change","z":"6857e430.f6d30c","name":"reset","rules":[{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1350,"y":830,"wires":[["b3432ef6.eec208"]]},{"id":"938bfc97.fe9928","type":"change","z":"6857e430.f6d30c","name":"reset","rules":[{"t":"set","p":"payload","pt":"msg","to":"Failed to connect","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1560,"y":870,"wires":[["b1cfc72a.bd866"]]},{"id":"7253689c.d9051","type":"delay","z":"6857e430.f6d30c","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1570,"y":830,"wires":[["b3432ef6.eec208"]]},{"id":"829b3296.70ed18","type":"comment","z":"6857e430.f6d30c","name":"Relay control","info":"Output to the relay and maybe some indication\nthat it is \"in use\".","x":1760,"y":680,"wires":[]},{"id":"5aeaf67e.f92878","type":"comment","z":"6857e430.f6d30c","name":"Text output","info":"This is a text message indicating the state of\nwhat is happening.\n","x":1790,"y":880,"wires":[]},{"id":"8b930a43.9cfa7","type":"link in","z":"6857e430.f6d30c","name":"","links":["7307333f.008e14"],"x":1095,"y":830,"wires":[["42999298.f34cbc","892b38d4.d338c8"]]},{"id":"7307333f.008e14","type":"link out","z":"6857e430.f6d30c","name":"","links":["8b930a43.9cfa7"],"x":1445,"y":680,"wires":[]},{"id":"ca6ffad5.144e5","type":"link out","z":"6857e430.f6d30c","name":"","links":["b47d2dc1.8a7448"],"x":1445,"y":650,"wires":[]},{"id":"b47d2dc1.8a7448","type":"link in","z":"6857e430.f6d30c","name":"","links":["ca6ffad5.144e5"],"x":1095,"y":1050,"wires":[["58a62763.d4ca68","101b2f42.e48061"]]},{"id":"58a62763.d4ca68","type":"change","z":"6857e430.f6d30c","name":"Detected","rules":[{"t":"set","p":"payload","pt":"msg","to":"Detected","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1200,"y":1090,"wires":[["b1cfc72a.bd866"]]},{"id":"479104fb.b3c57c","type":"change","z":"6857e430.f6d30c","name":"Request","rules":[{"t":"set","p":"payload","pt":"msg","to":"Request","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1200,"y":960,"wires":[["b1cfc72a.bd866"]]},{"id":"bc4bbb62.2cd07","type":"link out","z":"6857e430.f6d30c","name":"","links":["14250beb.16e54c"],"x":1445,"y":620,"wires":[]},{"id":"14250beb.16e54c","type":"link in","z":"6857e430.f6d30c","name":"","links":["bc4bbb62.2cd07"],"x":1095,"y":960,"wires":[["479104fb.b3c57c","8b8da88f.e96be"]]},{"id":"892b38d4.d338c8","type":"change","z":"6857e430.f6d30c","name":"Full","rules":[{"t":"set","p":"payload","pt":"msg","to":"Full","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":920,"wires":[["b3dfffd6.307b68","b1cfc72a.bd866","6d487ae0.0d42ec"]]},{"id":"9eed7175.b86bf","type":"change","z":"6857e430.f6d30c","name":"set","rules":[{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1600,"y":730,"wires":[["dba72950.12bf4"]]},{"id":"23bf7421.4e28c4","type":"udp out","z":"6857e430.f6d30c","name":"","addr":"192.168.0.21","iface":"","port":"6723","ipv":"udp4","outport":"","base64":false,"multicast":"false","x":2680,"y":1280,"wires":[]},{"id":"ae18dc1c.f0445","type":"link in","z":"6857e430.f6d30c","name":"","links":["dba72950.12bf4"],"x":1005,"y":1240,"wires":[["db8ee5e5.7ba0a8"]]},{"id":"dba72950.12bf4","type":"link out","z":"6857e430.f6d30c","name":"","links":["ae18dc1c.f0445"],"x":1765,"y":730,"wires":[]},{"id":"11d0df79.5b21d1","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"foo","payloadType":"str","repeat":"4","crontab":"","once":false,"onceDelay":0.1,"x":1100,"y":1280,"wires":[["48d58c55.c48744"]]},{"id":"48d58c55.c48744","type":"function","z":"6857e430.f6d30c","name":"loop","func":"if (msg.topic == \"RESET\")\n{\n context.set(\"value\",0);\n return;\n}\nvar value = context.get(\"value\")||0;\nvalue = (value + 1)%2;\ncontext.set(\"value\",value);\nmsg.payload = value;\nreturn msg;","outputs":1,"noerr":0,"x":1260,"y":1280,"wires":[["eb971b97.ad26e8"]]},{"id":"eb971b97.ad26e8","type":"gate","z":"6857e430.f6d30c","name":"","controlTopic":"control","defaultState":"closed","openCmd":"GO","closeCmd":"STOP","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1420,"y":1240,"wires":[["ddaf06a1.93f2"]]},{"id":"db8ee5e5.7ba0a8","type":"function","z":"6857e430.f6d30c","name":"","func":"msg.topic = \"CONTROL\";\nif (msg.payload === \"1\")\n{\n msg.payload = \"GO\";\n} else\n{\n msg.payload = \"STOP\";\n}\nreturn msg;","outputs":1,"noerr":0,"x":1100,"y":1240,"wires":[["f8fc3bcd.05547","eb971b97.ad26e8"]]},{"id":"ddaf06a1.93f2","type":"switch","z":"6857e430.f6d30c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1420,"y":1280,"wires":[["397645c.b3929ba"],["b6b84661.c95cb"]]},{"id":"397645c.b3929ba","type":"function","z":"6857e430.f6d30c","name":"ONE","func":"msg.payload = \"ONE\";\nmsg1 = {payload:\"OFF\"};\nreturn [msg,msg1];","outputs":2,"noerr":0,"x":1590,"y":1230,"wires":[["31003b18.17b7dc","76d3ece5.9740dc"],["206c0b8b.3719b4"]]},{"id":"b6b84661.c95cb","type":"function","z":"6857e430.f6d30c","name":"TWO","func":"msg.payload = \"TWO\";\nmsg1 = {payload:\"OFF\"};\nreturn [msg,msg1];","outputs":2,"noerr":0,"x":1590,"y":1330,"wires":[["5d306c6.6120094","76d3ece5.9740dc"],["3c22093c.92e6be"]]},{"id":"f8fc3bcd.05547","type":"switch","z":"6857e430.f6d30c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"STOP","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1590,"y":1280,"wires":[["3c22093c.92e6be","206c0b8b.3719b4","bbdc86a5.6d69b","1e41a236.47de5e"]]},{"id":"101b2f42.e48061","type":"change","z":"6857e430.f6d30c","name":"Stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":1050,"wires":[["f7e36eef.9922","6d487ae0.0d42ec"]]},{"id":"31003b18.17b7dc","type":"change","z":"6857e430.f6d30c","name":"Relay 1 ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"11","tot":"str"},{"t":"set","p":"charger_number","pt":"flow","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2440,"y":1220,"wires":[["23bf7421.4e28c4"]]},{"id":"3c22093c.92e6be","type":"change","z":"6857e430.f6d30c","name":"Relay 1 OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"21","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2440,"y":1260,"wires":[["23bf7421.4e28c4"]]},{"id":"5d306c6.6120094","type":"change","z":"6857e430.f6d30c","name":"Relay 2 ON","rules":[{"t":"set","p":"payload","pt":"msg","to":"12","tot":"str"},{"t":"set","p":"charger_number","pt":"flow","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":2440,"y":1340,"wires":[["23bf7421.4e28c4"]]},{"id":"206c0b8b.3719b4","type":"change","z":"6857e430.f6d30c","name":"Relay 2 OFF","rules":[{"t":"set","p":"payload","pt":"msg","to":"22","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":2440,"y":1300,"wires":[["23bf7421.4e28c4"]]},{"id":"76d3ece5.9740dc","type":"gate","z":"6857e430.f6d30c","name":"","controlTopic":"control","defaultState":"open","openCmd":"GO","closeCmd":"STOP","toggleCmd":"toggle","defaultCmd":"default","persist":false,"x":1620,"y":1120,"wires":[["9ea98a30.320348","ca2e53a2.5d4408"]]},{"id":"9ea98a30.320348","type":"ui_led","z":"6857e430.f6d30c","group":"873ae8e8.aa8f2","order":0,"width":"3","height":"1","label":"Charger 1","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"TWO","valueType":"str"},{"color":"lime","value":"ONE","valueType":"str"}],"name":"","x":2270,"y":1120,"wires":[]},{"id":"6d487ae0.0d42ec","type":"link out","z":"6857e430.f6d30c","name":"","links":["d7f96207.2d54f8"],"x":1455,"y":1050,"wires":[]},{"id":"d7f96207.2d54f8","type":"link in","z":"6857e430.f6d30c","name":"","links":["6d487ae0.0d42ec"],"x":1495,"y":1120,"wires":[["76d3ece5.9740dc"]]},{"id":"bbdc86a5.6d69b","type":"change","z":"6857e430.f6d30c","name":"Wipe","rules":[{"t":"set","p":"payload","pt":"msg","to":"foo","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1840,"y":1190,"wires":[["ca2e53a2.5d4408","9ea98a30.320348"]]},{"id":"ca2e53a2.5d4408","type":"ui_led","z":"6857e430.f6d30c","group":"873ae8e8.aa8f2","order":0,"width":"3","height":"1","label":"Charger 2","labelPlacement":"left","labelAlignment":"left","colorForValue":[{"color":"red","value":"ONE","valueType":"str"},{"color":"lime","value":"TWO","valueType":"str"}],"name":"","x":2270,"y":1160,"wires":[]},{"id":"e98e2197.7bccc8","type":"ui_button","z":"6857e430.f6d30c","name":"Full","group":"695293e8.77b0a4","order":7,"width":0,"height":0,"passthru":true,"label":"D2 Full","tooltip":"","color":"","bgcolor":"","icon":"","payload":"FULL","payloadType":"str","topic":"","x":670,"y":560,"wires":[["ce734aa1.a7f74"]]},{"id":"3c73ee77.0d2762","type":"ui_button","z":"6857e430.f6d30c","name":"Request","group":"695293e8.77b0a4","order":5,"width":0,"height":0,"passthru":true,"label":"D2 Request","tooltip":"","color":"","bgcolor":"","icon":"","payload":"REQUEST","payloadType":"str","topic":"","x":680,"y":500,"wires":[["ce734aa1.a7f74"]]},{"id":"2b6dbbd.91f5e44","type":"ui_button","z":"6857e430.f6d30c","name":"Detected","group":"695293e8.77b0a4","order":6,"width":0,"height":0,"passthru":true,"label":"D2 Detected","tooltip":"","color":"","bgcolor":"","icon":"","payload":"DETECTED","payloadType":"str","topic":"","x":680,"y":530,"wires":[["ce734aa1.a7f74"]]},{"id":"8b8da88f.e96be","type":"change","z":"6857e430.f6d30c","name":"Go","rules":[{"t":"set","p":"payload","pt":"msg","to":"GO","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"CONTROL","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1190,"y":1000,"wires":[["6d487ae0.0d42ec"]]},{"id":"f7e36eef.9922","type":"link out","z":"6857e430.f6d30c","name":"","links":["7b8ffd65.47e40c"],"x":1315,"y":1090,"wires":[]},{"id":"7b8ffd65.47e40c","type":"link in","z":"6857e430.f6d30c","name":"","links":["f7e36eef.9922"],"x":1315,"y":1190,"wires":[["eb971b97.ad26e8"]]},{"id":"b771e11.08c87a","type":"change","z":"6857e430.f6d30c","name":"in_use","rules":[{"t":"set","p":"in_use","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"who","pt":"flow","to":"who","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":510,"wires":[[]]},{"id":"c21a245b.a732d8","type":"change","z":"6857e430.f6d30c","name":"clear","rules":[{"t":"set","p":"in_use","pt":"flow","to":"false","tot":"bool"},{"t":"delete","p":"who","pt":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":540,"wires":[[]]},{"id":"ac71c649.cb547","type":"comment","z":"6857e430.f6d30c","name":"Flow variables","info":"","x":1350,"y":470,"wires":[]},{"id":"193d798f.7f3b4e","type":"switch","z":"6857e430.f6d30c","name":"","property":"who","propertyType":"flow","rules":[{"t":"null"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":820,"y":650,"wires":[["2d220ce9.1e5e0c","3b1394d7.247a9c"],["4bf9c507.98507c"]]},{"id":"92ae0f15.ae5538","type":"link out","z":"6857e430.f6d30c","name":"","links":["3b5b8833.9f51c8","9f9c153b.4998c"],"x":965,"y":780,"wires":[]},{"id":"3b5b8833.9f51c8","type":"link in","z":"6857e430.f6d30c","name":"","links":["92ae0f15.ae5538"],"x":1005,"y":1560,"wires":[["53ee0b9d.14f434","66838455.4cc644"]]},{"id":"f05b85d5.7c5a8","type":"comment","z":"6857e430.f6d30c","name":"Second charge request handler","info":"This is for all requests.\nSo if it gets the FULL or DISCONNECTED message,\nit will have to be sent back to the original\npart of the flow.\n","x":1130,"y":1490,"wires":[]},{"id":"9dd94554.e23d78","type":"change","z":"6857e430.f6d30c","name":"Get charger in use","rules":[{"t":"move","p":"payload","pt":"msg","to":"command","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"charger_number","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":1550,"wires":[["88d49640.b869e"]]},{"id":"88d49640.b869e","type":"switch","z":"6857e430.f6d30c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"2","vt":"num"},{"t":"eq","v":"1","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":1530,"y":1550,"wires":[["856ba16c.85746","57c02251.12401c"],["837be04d.5b27d8","2bcb7fcb.309ad"]]},{"id":"2f3aa12e.26f2b6","type":"comment","z":"6857e430.f6d30c","name":"README","info":"The incoming power request MUST have a \nmsg.who to help with identifying who is \nwho if there are two power requests at the same\ntime.\n","x":1080,"y":440,"wires":[]},{"id":"8872ea1e.1b54f","type":"ui_button","z":"6857e430.f6d30c","name":"Disconnected","group":"695293e8.77b0a4","order":8,"width":0,"height":0,"passthru":true,"label":"D2 Disconnected","tooltip":"","color":"","bgcolor":"","icon":"","payload":"DISCONNECTED","payloadType":"str","topic":"","x":700,"y":590,"wires":[["ce734aa1.a7f74"]]},{"id":"f06599d7.559798","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"DISCONNECTED","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":500,"y":590,"wires":[["8872ea1e.1b54f"]]},{"id":"3b1394d7.247a9c","type":"debug","z":"6857e430.f6d30c","name":"Device Input","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1160,"y":590,"wires":[]},{"id":"2bcb7fcb.309ad","type":"debug","z":"6857e430.f6d30c","name":"Switch on Charger 2","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1450,"y":1620,"wires":[]},{"id":"57c02251.12401c","type":"debug","z":"6857e430.f6d30c","name":"Switch on Charger 1","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1440,"y":1490,"wires":[]},{"id":"594fa692.8dcbe8","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"REQUEST","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":530,"y":330,"wires":[["d84a9c5e.f1aad8"]]},{"id":"6b0466f4.cf015","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"DETECTED","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":520,"y":360,"wires":[["8acc6983.c813c8"]]},{"id":"57e88b92.b1d844","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"FULL","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":540,"y":390,"wires":[["66397fa5.224a7"]]},{"id":"66397fa5.224a7","type":"ui_button","z":"6857e430.f6d30c","name":"Full","group":"695293e8.77b0a4","order":3,"width":0,"height":0,"passthru":true,"label":"D1 Full","tooltip":"","color":"","bgcolor":"","icon":"","payload":"FULL","payloadType":"str","topic":"","x":670,"y":390,"wires":[["d502fb8e.fda35"]]},{"id":"d84a9c5e.f1aad8","type":"ui_button","z":"6857e430.f6d30c","name":"Request","group":"695293e8.77b0a4","order":1,"width":0,"height":0,"passthru":true,"label":"D1 Request","tooltip":"","color":"","bgcolor":"","icon":"","payload":"REQUEST","payloadType":"str","topic":"","x":680,"y":330,"wires":[["d502fb8e.fda35"]]},{"id":"8acc6983.c813c8","type":"ui_button","z":"6857e430.f6d30c","name":"Detected","group":"695293e8.77b0a4","order":2,"width":0,"height":0,"passthru":true,"label":"D1 Detected","tooltip":"","color":"","bgcolor":"","icon":"","payload":"DETECTED","payloadType":"str","topic":"","x":680,"y":360,"wires":[["d502fb8e.fda35"]]},{"id":"8208d59b.6b76b","type":"ui_button","z":"6857e430.f6d30c","name":"Disconnected","group":"695293e8.77b0a4","order":4,"width":0,"height":0,"passthru":true,"label":"D1 Disconnected","tooltip":"","color":"","bgcolor":"","icon":"","payload":"DISCONNECTED","payloadType":"str","topic":"","x":700,"y":420,"wires":[["d502fb8e.fda35"]]},{"id":"369cebd5.6569bc","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"DISCONNECTED","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":500,"y":420,"wires":[["8208d59b.6b76b"]]},{"id":"66e2e4cf.ab1fec","type":"comment","z":"6857e430.f6d30c","name":"Device 1","info":"","x":610,"y":290,"wires":[]},{"id":"65d21d42.ec82dc","type":"comment","z":"6857e430.f6d30c","name":"Device 2","info":"","x":600,"y":460,"wires":[]},{"id":"d502fb8e.fda35","type":"change","z":"6857e430.f6d30c","name":"Device 1","rules":[{"t":"set","p":"who","pt":"msg","to":"D1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":370,"wires":[["d453244e.b62dd","193d798f.7f3b4e"]]},{"id":"ce734aa1.a7f74","type":"change","z":"6857e430.f6d30c","name":"Device 2","rules":[{"t":"set","p":"who","pt":"msg","to":"D2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":890,"y":530,"wires":[["193d798f.7f3b4e"]]},{"id":"d453244e.b62dd","type":"debug","z":"6857e430.f6d30c","name":"Device","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1060,"y":370,"wires":[]},{"id":"53ee0b9d.14f434","type":"debug","z":"6857e430.f6d30c","name":"Second device command","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1180,"y":1620,"wires":[]},{"id":"66838455.4cc644","type":"switch","z":"6857e430.f6d30c","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"REQUEST","vt":"str"},{"t":"eq","v":"DETECTED","vt":"str"},{"t":"eq","v":"FULL","vt":"str"},{"t":"eq","v":"DISCONNECTED","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1120,"y":1560,"wires":[["9dd94554.e23d78"],[],["9dd94554.e23d78"],["9dd94554.e23d78"]],"outputLabels":["Request","Detected","Full",null]},{"id":"837be04d.5b27d8","type":"switch","z":"6857e430.f6d30c","name":"","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"REQUEST","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1690,"y":1620,"wires":[["81646caa.4ec6c8"],["869ded41.a6b4a"]]},{"id":"e76c88f2.bf249","type":"debug","z":"6857e430.f6d30c","name":"NOT WANTED JUST NOW","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":1070,"y":740,"wires":[]},{"id":"4bf9c507.98507c","type":"switch","z":"6857e430.f6d30c","name":"","property":"who","propertyType":"msg","rules":[{"t":"eq","v":"who","vt":"flow"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":820,"y":690,"wires":[["2d220ce9.1e5e0c","3b1394d7.247a9c"],["e76c88f2.bf249","92ae0f15.ae5538"]]},{"id":"86b4b2a7.c7d048","type":"link in","z":"6857e430.f6d30c","name":"1","links":["b6e0bfdb.2735d8"],"x":2235,"y":1380,"wires":[["31003b18.17b7dc"]]},{"id":"b6e0bfdb.2735d8","type":"link out","z":"6857e430.f6d30c","name":"1","links":["86b4b2a7.c7d048"],"x":2065,"y":1460,"wires":[]},{"id":"da8dd26e.fac8f8","type":"link in","z":"6857e430.f6d30c","name":"2","links":["ffebdde0.50d2b8"],"x":2240,"y":1430,"wires":[["3c22093c.92e6be"]]},{"id":"ffebdde0.50d2b8","type":"link out","z":"6857e430.f6d30c","name":"2","links":["da8dd26e.fac8f8"],"x":2065,"y":1500,"wires":[]},{"id":"edb90bc8.878af","type":"link in","z":"6857e430.f6d30c","name":"3","links":["1be502b8.358505"],"x":2240,"y":1470,"wires":[["206c0b8b.3719b4"]]},{"id":"1be502b8.358505","type":"link out","z":"6857e430.f6d30c","name":"3","links":["edb90bc8.878af"],"x":2065,"y":1640,"wires":[]},{"id":"155bc08e.f525af","type":"link in","z":"6857e430.f6d30c","name":"4","links":["321c9abb.e8ef26"],"x":2240,"y":1510,"wires":[["5d306c6.6120094"]]},{"id":"856ba16c.85746","type":"switch","z":"6857e430.f6d30c","name":"","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"REQUEST","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1690,"y":1480,"wires":[["14716174.df7537"],["9ca75b64.aba1a8"]]},{"id":"321c9abb.e8ef26","type":"link out","z":"6857e430.f6d30c","name":"4","links":["155bc08e.f525af"],"x":2065,"y":1600,"wires":[]},{"id":"233abc9b.3e5484","type":"inject","z":"6857e430.f6d30c","name":"","topic":"","payload":"STOP","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1620,"y":1080,"wires":[["f8fc3bcd.05547"]]},{"id":"1e41a236.47de5e","type":"debug","z":"6857e430.f6d30c","name":"Wiipe message","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1880,"y":1080,"wires":[]},{"id":"4653f4d9.f1e2dc","type":"debug","z":"6857e430.f6d30c","name":"command sent to relay control (1) (ON)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1780,"y":1370,"wires":[]},{"id":"14716174.df7537","type":"change","z":"6857e430.f6d30c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1910,"y":1460,"wires":[["b6e0bfdb.2735d8","e7cc289.5f744d8","4653f4d9.f1e2dc"]]},{"id":"6b593624.570948","type":"link in","z":"6857e430.f6d30c","name":"","links":["e7cc289.5f744d8"],"x":2185,"y":1090,"wires":[["9ea98a30.320348"]]},{"id":"e7cc289.5f744d8","type":"link out","z":"6857e430.f6d30c","name":"","links":["6b593624.570948"],"x":2025,"y":1430,"wires":[]},{"id":"b25b6766.9550f","type":"link in","z":"6857e430.f6d30c","name":"","links":["685fdb26.af089c"],"x":2185,"y":1190,"wires":[["ca2e53a2.5d4408"]]},{"id":"685fdb26.af089c","type":"link out","z":"6857e430.f6d30c","name":"","links":["b25b6766.9550f"],"x":2025,"y":1560,"wires":[]},{"id":"81646caa.4ec6c8","type":"change","z":"6857e430.f6d30c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"TWO","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1900,"y":1600,"wires":[["685fdb26.af089c","321c9abb.e8ef26"]]},{"id":"869ded41.a6b4a","type":"change","z":"6857e430.f6d30c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"ONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1900,"y":1640,"wires":[["1be502b8.358505","685fdb26.af089c"]]},{"id":"9ca75b64.aba1a8","type":"change","z":"6857e430.f6d30c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"TWO","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1910,"y":1500,"wires":[["ffebdde0.50d2b8","e7cc289.5f744d8","2bab8f18.b6ae"]]},{"id":"2bab8f18.b6ae","type":"debug","z":"6857e430.f6d30c","name":"command sent to relay control (1) (OFF)","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":1780,"y":1420,"wires":[]},{"id":"74d013e8.8cffe4","type":"comment","z":"6857e430.f6d30c","name":"This is the first device to be identified","info":"","x":1090,"y":1190,"wires":[]},{"id":"b3dfffd6.307b68","type":"link out","z":"6857e430.f6d30c","name":"","links":["34869bee.17f97c"],"x":1595,"y":900,"wires":[]},{"id":"34869bee.17f97c","type":"link in","z":"6857e430.f6d30c","name":"","links":["b3dfffd6.307b68"],"x":1705,"y":760,"wires":[["dba72950.12bf4"]]},{"id":"8ead79e1.cc549","type":"link out","z":"6857e430.f6d30c","name":"","links":["4268e4f4.8b3c6c"],"x":1465,"y":760,"wires":[]},{"id":"4268e4f4.8b3c6c","type":"link in","z":"6857e430.f6d30c","name":"","links":["8ead79e1.cc549"],"x":1465,"y":830,"wires":[["7253689c.d9051"]]},{"id":"8a2e80be.f7c928","type":"mqtt-broker","z":"","name":"MQTT host","broker":"192.168.0.99","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"ARDUINO_STATUS","birthQos":"2","birthPayload":"connected","willTopic":"ARDUINO_STATUS","willQos":"0","willPayload":"disconnected"},{"id":"873ae8e8.aa8f2","type":"ui_group","z":"","name":"Status","tab":"9adcea11.9c774","order":2,"disp":true,"width":"6","collapse":false},{"id":"695293e8.77b0a4","type":"ui_group","z":"","name":"Buttons","tab":"9adcea11.9c774","order":1,"disp":true,"width":"6","collapse":false},{"id":"9adcea11.9c774","type":"ui_tab","z":"","name":"Phone Charger","icon":"dashboard","order":31,"disabled":false,"hidden":false}]

@Trying_to_learn could you format your flow (not that this will help you as we cannot replicate your setup, we need context) and fix the title.

Ok, context.

No flow.who set. Virgin invocation.

Press either of the request buttons. (Device 1 or 2)
That will activate the two LEDs flashing/alternating between 1 green and 2 red; 1 red and 2 green.

At some stage press the Detected button for that device.

This will stop the LEDs oscillating.
But more so, it will then assign that device to that LED.

Press the FULL button and all will go back to the off condition.

Repeat if you want to get the idea of how it is supposed to work.
There is no guarantee that it will work the second time.

Delete the flow.who variable just to re-establish the first time.

Press the REQUEST button for either device then the DETECTED button to get back to where it is as working with one device.

If/when the second REQUEST button is pressed, the red LED will then turn green.
That indicates both outputs are active.
The idea is that then if the FULL (or UNPLUGGED) button is pressed for the second LED that LED should then go back to being RED.

Rather than that, I think both LEDs go off.

This is because the FULL/UNPLUGGED message gets wrongly switched.

There is a whole story behind the names used.

Now the flow variable is called flow.who where are originally it was flow.who_1.
But that was problematic with matching in the switch node.

Does that help?