Send msg.color to Button without Triggering Button

I have a button that starts a feed sequence for a digestion tank. I would like the color of that button to change based on the weight of the tank. For example, 0-50 lbs. Green, 51-90 lbs. Yellow, >90 lbs. Red. I tried reading in from the load cell getting those weights, setting the ranges in a switch node and then using a change node to make their respective colors and sent as msg.color. This causes the button to click every time it is read...

Is there a way around this? I have attached a portion of my flow which has the feed cycle. I think you can get the gist of it from this. [{"id":"110ab083.8ccb0f","type":"OpcUa-Item","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","item":"ns=4;i=112","datatype":"Boolean","value":"","name":"FEED REQ","x":770,"y":260,"wires":[["a337bd9d.19f87"]]},{"id":"d52d1d92.c3649","type":"ui_button","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","group":"33cf01a0.05bede","order":6,"width":"4","height":"1","passthru":true,"label":"FEED","tooltip":"","color":"","bgcolor":"{{msg.color}}","icon":"fa-cutlery","payload":"true","payloadType":"bool","topic":"show","topicType":"str","x":130,"y":320,"wires":[["59f76669.15bde8"]]},{"id":"59f76669.15bde8","type":"ui_template","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","group":"75179463.18a3fc","name":"PINPAD1","order":2,"width":"0","height":"0","format":"<div ng-init=\"init()\" id=\"pin_insert\" class=\"dialog\">\n \n <div class=\"dialog_content\">\n \n <div class=\"dialog_header\">\n <span ng-click=\"closeDialog()\" class=\"close\">&times;</span>\n <h2 style=\"margin:10px\">Insert PIN</h2>\n <div onmousedown=\"return false\"></div>\n </div>\n \n <div class=\"dialog_body\">\n\n <div layout=\"row\" layout-align=\"center\">\n <div class=\"number_placeholder\">\n {{passcode.substring(0, 1)}}\n </div>\n <div class=\"number_placeholder\">\n {{passcode.substring(1, 2)}}\n </div>\n <div class=\"number_placeholder\">\n {{passcode.substring(2, 3)}}\n </div>\n <div class=\"number_placeholder\">\n {{passcode.substring(3, 4)}}\n </div>\n </div>\n \n <div layout=\"column\" layout-align=\"center\" style=\"margin-top: 10px\">\n <div layout=\"row\" layout-align=\"center\">\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(1)\">1</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(2)\">2</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(3)\">3</md-button>\n </div>\n </div>\n <div layout=\"row\" layout-align=\"center\">\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(4)\">4</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(5)\">5</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(6)\">6</md-button>\n </div>\n </div>\n <div layout=\"row\" layout-align=\"center\">\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(7)\">7</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(8)\">8</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(9)\">9</md-button>\n </div>\n </div>\n <div layout=\"row\" layout-align=\"center\">\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"confirm()\">\n <ng-md-icon icon=\"done\" style=\"color:#fff;\"></ng-md-icon>\n </md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"add(0)\">0</md-button>\n </div>\n <div class=\"number_box\">\n <md-button class=\"pin\" ng-click=\"delete()\">\n <ng-md-icon icon=\"arrow_back\" style=\"color:#fff;\"></ng-md-icon>\n </md-button>\n </div>\n </div>\n </div> \n \n </div> <!--dialog_body-->\n </div> <!--dialog_content-->\n</div> <!--dialog-->\n\n<style>\n\n/* The Dialog (background) */\n.dialog {\n display: none; /* Hidden by default */\n position: fixed; /* Stay in place */\n z-index: 9999; /* Sit on top */\n left: 0;\n top: 0;\n width: 100%; /* Full width */\n height: 100%; /* Full height */\n overflow: auto; /* Enable scroll if needed */\n background-color: rgb(0,0,0); /* Fallback color */\n background-color: rgba(0,0,0,0.4); /* Black w/ opacity */\n -webkit-transform: translateZ(0px);\n -webkit-transform: translate3d(0,0,0);\n -webkit-perspective: 1000;\n}\n\n.dialog_content {\n position: absolute;\n background-color: #fff;\n left: calc(50% - 170px);\n top: 30px;\n border-radius: 10px;\n padding: 0;\n width: 340px;\n box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);\n -webkit-animation-name: animatetop;\n animation-name: animatetop;\n animation-duration: 0.4s;\n}\n\n/* Media query for smartphones (to Fix?) */\n@media only screen and (min-device-width : 375px) and (max-device-width : 667px) { \n .dialog_content {\n margin-top: 5%;\n margin-left: 5%;\n}\n}\n\n/* Add Animation */\n@-webkit-keyframes animatetop {\n from {top: -300px; opacity: 0} \n to {top: 0; opacity: 1}\n}\n\n@keyframes animatetop {\n from {top: -300px; opacity: 0}\n to {top: 0; opacity: 1}\n}\n\n/* Dialog Header */\n.dialog_header {\n padding: 2px 16px;\n background-color: #76990F;\n border-radius: 10px 10px 0 0;\n color: white;\n}\n\n/* Dialog Body */\n.dialog_body {padding: 5px;}\n\n/* The Close Button */\n.close {\n color: #fff;\n float: right;\n font-size: 28px;\n font-weight: bold;\n cursor: pointer;\n}\n\n.close:hover,\n.close:focus {\n color: #76990F;\n text-decoration: none;\n cursor: pointer;\n}\n\n/* __ */\n.number_placeholder{\n width: 50px;\n height: 34px;\n margin: 10px;\n font-size: 20pt;\n text-align: center;\n border-bottom: 1px solid black;\n}\n\n/* Number container */\n.number_box{\n margin: 5px;\n}\n\n/* Buttons style */\n.pin {\n min-height: 50px;\n min-width: 50px;\n font-weight: bold;\n margin: 0px 10px 10px 0px;\n box-shadow: 4px 4px 6px 0 #dadada;\n background-color: #76990F;\n color: #fff;\n}\n\n.pin:not([disabled]):hover {\n background-color: #76990F;\n}\n\n.btn1 {\n color : rgb(49, 46, 46);\n background-color: rgba(255, 222, 121, 0.96);\n border-radius: 10px 0 0 10px;\n font-size: 16px;\n}\n\n.btn1:not([disabled]):hover {\n background-color: rgba(107, 103, 91, 0.96);\n color: white;\n}\n\n.btn1[disabled] {\n color : rgb(187, 187, 187);\n background-color: rgba(230, 230, 229, 0.96);\n}\n\n</style>\n\n<script>\n\n/**\n * pin_dialog.js\n * Node-Red UI template for Node-Red Dashboard. \n * Custom dialog that asks for a PIN to allow actions\n * Enjoy it :). \n * -- Daniel\n *\n *\n * @license The Unlicense, http://unlicense.org/\n * @version 0.2\n * @author Daniel Lando, https://github.com/robertsLando\n * @updated 2019-03-18\n * @link ----\n *\n *\n */\n\nvar dialog;\n\n/* ==== */\n(function(scope) {\n \n scope.passcode = \"\";\n scope.payload = \"\";\n scope.inited = false;\n \n scope.init = function() {\n scope.passcode = \"\";\n //Hide the md-panel\n $('#pin_insert').parent().parent().css(\"display\", \"none\");\n //This trick make it works on smartphones too :)\n dialog = $('#pin_insert').detach();\n //remove any previously added pin dialog\n $('.dialog').remove();\n }\n \n scope.showDialog = function() {\n dialog.appendTo(document.body);\n dialog.css(\"display\", \"block\");\n }\n \n scope.closeDialog = function(){\n dialog.css(\"display\", \"none\");\n }\n \n scope.add = function(value) {\n if(scope.passcode.length < 4) {\n scope.passcode = scope.passcode + value;\n if(scope.passcode.length == 4) {\n console.log(\"The four digit code was entered\");\n \n }\n }\n }\n \n scope.delete = function() {\n if(scope.passcode.length > 0) {\n scope.passcode = scope.passcode.substring(0, scope.passcode.length - 1);\n }\n }\n \n scope.confirm = function() {\n if(scope.passcode.length == 4) {\n scope.send({passcode: scope.passcode, payload : scope.payload});\n scope.closeDialog();\n scope.passcode = \"\";\n scope.payload = \"\";\n }\n }\n\n scope.$watch('msg', function(data) {\n if(data && data.topic){\n switch(data.topic){\n case \"show\":\n if(scope.inited){\n scope.payload = data.payload;\n scope.showDialog();\n }\n else\n scope.inited = true;\n break;\n case \"close\": \n scope.closeDialog(); \n break;\n }\n }\n });\n})(scope);\n\n</script>\n","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":280,"y":320,"wires":[["2b51977b.f91e3"]]},{"id":"2b51977b.f91e3","type":"function","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"VERIFY","func":"var pins = [\"3651\",\"3652\",\"3653\"];\nvar verified = false;\n\nfor(var i=0;i<pins.length;i++){\n if(msg.passcode == pins[i]){\n verified = true;\n break;\n }\n}\n\nmsg.verified = verified;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":320,"wires":[["d215c99.a64df38","27c80b58.9ae064"]]},{"id":"d215c99.a64df38","type":"switch","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"check","property":"verified","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"false","repair":false,"outputs":2,"x":555,"y":320,"wires":[["26c87743.4fc608","3b2dee41.1bdd7a"],["2be8a816.96f8e8"]],"l":false},{"id":"26c87743.4fc608","type":"function","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"RIGHT","func":"var msg2 = {};\nmsg2.topic = \"Pin successfully verified!\";\nmsg2.payload = \"timestamp\";\n \nreturn [msg, msg2];","outputs":1,"noerr":0,"initialize":"","finalize":"","x":670,"y":300,"wires":[["1b677ded.a09b92"]]},{"id":"2be8a816.96f8e8","type":"function","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"WRONG","func":" msg.topic = \"Invalid PIN\";\n msg.payload = \" \";\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":680,"y":340,"wires":[["e4757694.ba64e"]]},{"id":"e4757694.ba64e","type":"ui_toast","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","position":"dialog","displayTime":"5","highlight":"","sendall":true,"outputs":1,"ok":"OK","cancel":"","raw":true,"topic":"","name":"FAIL","x":830,"y":340,"wires":[[]]},{"id":"a337bd9d.19f87","type":"link out","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"FEED OUT","links":["b939f700.fcb","877d46c3.389c18"],"x":875,"y":260,"wires":[]},{"id":"b0419d50.0b4338","type":"function","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"to name","func":"const USERS = {\n 3651:\"PAUL\",\n 3652:\"IAN\",\n 3653:\"ZACK\",\n \n}\nmsg.payload = USERS[msg.payload]\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":100,"wires":[["83367d00.987a18"]]},{"id":"83367d00.987a18","type":"switch","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"check","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"PAUL","vt":"str"},{"t":"eq","v":"IAN","vt":"str"},{"t":"eq","v":"ZACK","vt":"str"}],"checkall":"false","repair":false,"outputs":3,"x":715,"y":100,"wires":[["2ab45b6e.3607e4","39adc2cb.8620ae"],["2ab45b6e.3607e4","39adc2cb.8620ae"],["2ab45b6e.3607e4","39adc2cb.8620ae"]],"l":false},{"id":"2ab45b6e.3607e4","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"Dept","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":795,"y":100,"wires":[["beee61f1.2e765"]],"l":false},{"id":"27c80b58.9ae064","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"change","p":"payload","pt":"msg","from":"true","fromt":"bool","to":"passcode","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":495,"y":100,"wires":[["b0419d50.0b4338"]],"l":false},{"id":"beee61f1.2e765","type":"link out","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"FEED WEIGHT OUT","links":["7de9fc5f.52ca24","4f9e5769.ccd49","428bd7cc.f317f"],"x":875,"y":100,"wires":[]},{"id":"1b677ded.a09b92","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"15m","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":775,"y":300,"wires":[[]],"l":false},{"id":"e298c9ae.acc27","type":"ui_ui_control","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","events":"all","x":635,"y":200,"wires":[[]],"l":false},{"id":"3b2dee41.1bdd7a","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"FOOD PICKER","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":575,"y":200,"wires":[["e298c9ae.acc27"]],"l":false},{"id":"637bb309.c51bbc","type":"link in","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"CATEGORY SELECT IN","links":["2652b434.3766a4"],"x":745,"y":200,"wires":[["187359f1.89ca16"]]},{"id":"f76f2c88.f790c8","type":"ui_ui_control","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","events":"all","x":875,"y":200,"wires":[[]],"l":false},{"id":"187359f1.89ca16","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"HOME","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":815,"y":200,"wires":[["f76f2c88.f790c8"]],"l":false},{"id":"e3286ffb.7df6d8","type":"link in","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","links":["2652b434.3766a4"],"x":655,"y":260,"wires":[["110ab083.8ccb0f"]]},{"id":"e892f833.ed53b","type":"comment","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"HOME PAGE FEED BUTTON","info":"","x":320,"y":200,"wires":[]},{"id":"bca619ff.d45c8","type":"inject","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"0.3","topic":"","payload":"true","payloadType":"bool","x":75,"y":260,"wires":[["d52d1d92.c3649"]],"l":false},{"id":"b2b19a8b.69fd1","type":"link out","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"FEED WEIGHT OUT","links":["7de9fc5f.52ca24","4f9e5769.ccd49"],"x":875,"y":160,"wires":[]},{"id":"b2d67a47.8a14c","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"UserNumber","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":795,"y":160,"wires":[["887cc6ef.c11e9","b2b19a8b.69fd1"]],"l":false},{"id":"1f70655b.eb683b","type":"link in","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"WEIGHTS FOR FEED IN","links":["2ef057f9.0b45a8"],"x":105,"y":500,"wires":[[]]},{"id":"56c9b364.05b2ac","type":"switch","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","property":"payload","propertyType":"msg","rules":[{"t":"btwn","v":"0","vt":"num","v2":"50","v2t":"num"},{"t":"btwn","v":"50.1","vt":"num","v2":"90","v2t":"num"},{"t":"gt","v":"90","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":210,"y":500,"wires":[["3096925e.500c9e"],["8138f75b.a4763"],["c6e7fb34.466898"]]},{"id":"3096925e.500c9e","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"color","pt":"msg","to":"76990F","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":460,"wires":[["d52d1d92.c3649"]]},{"id":"8138f75b.a4763","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"color","pt":"msg","to":"#fefb62","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":500,"wires":[["d52d1d92.c3649"]]},{"id":"c6e7fb34.466898","type":"change","z":"74bafb44.7e72dc","g":"8bc5b0a4.2a1c08","name":"","rules":[{"t":"set","p":"color","pt":"msg","to":"#f94141","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":540,"wires":[["d52d1d92.c3649"]]},{"id":"33cf01a0.05bede","type":"ui_group","name":"ACTIONS","tab":"f4ecfc88.3bc9","order":1,"disp":false,"width":"4","collapse":false},{"id":"75179463.18a3fc","type":"ui_group","name":"TEMPLATE","tab":"f4ecfc88.3bc9","order":6,"disp":false,"width":"1","collapse":false},{"id":"f4ecfc88.3bc9","type":"ui_tab","name":"HOME","icon":"fa-home","order":1,"disabled":false,"hidden":false}]

Oh wow, that was simple. Haha thank you very much!

1 Like

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