You are getting that because of the two inputs.
I have shown an alternative way of processing the input using payload.g
& payload.b
. It may not meet your needs, but it might give you some ideas
Why are you using scope.$applyAsync
it is causing the uiTemplate
node output to be 1 input behind? I got rid of it and the node still works. If you have to use it put the scope.onChange(scope.data.*)
inside the function.
[{"id":"739de59a292077a9","type":"ui_template","z":"d69bda8308d00eeb","group":"1e6261b74bfa30c0","name":"3 SW","order":5,"width":"5","height":"1","format":"<style>\n\n.sw md-switch.md-checked .md-thumb-container {\n transform: none !important;\n}\n\n.nr-dashboard-theme .nr-dashboard-template md-switch.md-checked:not([disabled]) .md-thumb {\n background-color: #ccc;\n}\n\n.nr-dashboard-theme .nr-dashboard-template md-switch .md-bar .myswitch{\n background-color: rgba(111, 111, 111, 0.5);\n display: none;\n}\n\n.nr-dashboard-theme .nr-dashboard-template md-switch.md-checked:not([disabled]) .md-thumb {\n background-color: #609f70;\n}\n\n.nr-dashboard-theme .nr-dashboard-template md-switch .md-bar {\n background-color: rgba(111, 111, 111, 0.5);\n display: none;\n}\n\n.sw md-switch .md-container {\n margin-right: 3px;\n width: 25px;\n}\n\n.nr-dashboard-theme .nr-dashboard-template md-switch .md-thumb {\n background-color: red;\n}\n\nmd-switch {\n align-items: center;\n height: 30px;\n line-height: 18px;\n margin: 0px;\n margin-left: inherit;\n margin-right: 16px;\n}\n\n.sw md-switch .md-label {\n font-size: 13px;\n color: #728faa;\n letter-spacing: 1px;\n font-weight: bold;\n}\n\nmd-switch .md-thumb .md-ripple-container {\n display: none;\n}\n\n</style>\n\n<div class=\"sw\" style=\"margin-top: 1px\" layout=\"row\">\n\n<div style=\"margin-left: 7px\" ng-cloak>\n <md-switch id=\"B\" ng-model=\"data.b\" aria-label=\"B\" ng-true-value=\"'b_on'\" ng-false-value=\"'b_off'\" ng-change=\"onChange(data.b)\">B</md-switch>\n</div>\n<div style=\"margin-left: 5px\" ng-cloak>\n <md-switch id=\"G\" ng-model=\"data.g\" aria-label=\"G\" ng-true-value=\"'g_on'\" ng-false-value=\"'g_off'\" ng-change=\"onChange(data.g)\">G</md-switch>\n</div>\n<div style=\"margin-left: 15px\" ng-cloak>\n <md-switch id=\"S\" ng-model=\"data.s\" aria-label=\"G\" ng-true-value=\"'s_on'\" ng-false-value=\"'s_off'\" ng-change=\"onChange(data.s)\">SIM</md-switch>\n</div>\n\n</div>\n\n<script>\n (function(scope) {\n scope.data = {\n b: 'b_on',\n g: 'g_off',\n s: 's_on'\n };\n \n scope.onChange = function(cbState) {\n scope.send({payload: cbState, topic: \"switch\" });\n };\n \n //handle arriving messages\n scope.$watch('msg', function(msg) {\n if(msg !== undefined && msg !== null){\n try{\n switch(msg.topic) {\n case \"Binance\":\n case \"Gate.io\":\n //scope.$applyAsync(function(){\n scope.data.b = msg.payload.b;\n scope.data.g = msg.payload.g;\n //});\n scope.onChange(scope.data);\n break; \n case \"s\":\n scope.$applyAsync(function(){\n scope.data.s = msg.payload;\n });\n scope.onChange(scope.data.s);\n break; \n\n default:\n break;\n }\n }catch(err){\n console.error(err);\n }\n }\n });\n })(scope);\n</script>","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":750,"y":1200,"wires":[["31f5a9de15f6c819"]]},{"id":"c1ec7bd453fa1a1c","type":"function","z":"d69bda8308d00eeb","name":"exchange","func":"let msgB = {}; let msgG = {}\n\nlet topic = msg.topic\nlet exchange = ''\n\nlet newPayload = {}\n\nif(topic === \"exchange\") {exchange = msg.payload } else {exchange = \"Binance\"}\n\nif(exchange === \"Binance\") {\n\n newPayload.b = \"b_on\"\n newPayload.g = \"g_off\"\n\n} \n\nif(exchange === \"Gate.io\") {\n\n newPayload.b = \"b_off\"\n newPayload.g = \"g_on\"\n\n} \n\nmsg.topic = exchange\nmsg.payload = newPayload\n\nreturn msg","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":560,"y":1200,"wires":[["739de59a292077a9","17259ab11c63879e"]]},{"id":"31f5a9de15f6c819","type":"debug","z":"d69bda8308d00eeb","name":"debug 33","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":900,"y":1200,"wires":[]},{"id":"9c4fd8b5d1548133","type":"inject","z":"d69bda8308d00eeb","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"exchange","payload":"Gate.io","payloadType":"str","x":340,"y":1200,"wires":[["c1ec7bd453fa1a1c"]]},{"id":"17259ab11c63879e","type":"debug","z":"d69bda8308d00eeb","name":"debug 34","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":780,"y":1140,"wires":[]},{"id":"1e6261b74bfa30c0","type":"ui_group","name":"Group 4","tab":"7e13e6107768d821","order":4,"disp":true,"width":6},{"id":"7e13e6107768d821","type":"ui_tab","name":"CRYPTO","icon":"dashboard","order":8,"disabled":false,"hidden":false}]