You should be able to add a ng-if
ng-if="msg.payload == 'ON'"
Example flow
[{"id":"505eb4fc9626326a","type":"ui_switch","z":"b9860b4b9de8c8da","name":"","label":"switch","tooltip":"","group":"8b5cde76.edd58","order":2,"width":0,"height":0,"passthru":true,"decouple":"false","topic":"topic","topicType":"msg","style":"","onvalue":"ON","onvalueType":"str","onicon":"","oncolor":"","offvalue":"OFF","offvalueType":"str","officon":"","offcolor":"","animate":false,"className":"","x":330,"y":160,"wires":[["3e4127463aba586b"]]},{"id":"3e4127463aba586b","type":"ui_template","z":"b9860b4b9de8c8da","group":"8b5cde76.edd58","name":"","order":2,"width":0,"height":0,"format":"<button ng-if=\"msg.payload == 'ON'\" ng-mousedown=\"send({payload: 'true'})\" ng-mouseup=\"send({payload: 'false'})\"\n class=\"vibrate filled bigfont\" ng-style=\"{background: !msg.payload ? '#C1CDCD' : '#00FF00' }\"> Cool <br/button>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":true,"templateScope":"local","className":"","x":480,"y":240,"wires":[["1c06d852935dd4fe"]]},{"id":"1c06d852935dd4fe","type":"debug","z":"b9860b4b9de8c8da","name":"debug 338","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":220,"wires":[]},{"id":"8b5cde76.edd58","type":"ui_group","name":"default","tab":"8f03e639.85956","order":1,"disp":false,"width":"12","collapse":false},{"id":"8f03e639.85956","type":"ui_tab","name":"Home","icon":"dashboard","order":3,"disabled":false,"hidden":false}]