Flashing buttons

This is a small flow if you like having buttons on your flow/s that offer feedback.

[{"id":"b51e2b02.46d418","type":"trigger","z":"1781e581.31721a","op1":"Down","op2":"0","op1type":"str","op2type":"str","duration":"-140","extend":false,"units":"ms","reset":"Up","bytopic":"all","name":"Repeat","x":3870,"y":680,"wires":[["36fcedb1.36a5e2"]]},{"id":"36fcedb1.36a5e2","type":"function","z":"1781e581.31721a","name":"toggle *","func":"var x = context.get(\"counter\") || 0;\nif (msg.payload == \"Up\")\n{\n    context.set(\"counter\",0);\n    msg.colour = \"black\";\n    msg.payload = \"black\";      //  May not be needed\n    return msg;\n}\n\nif (x === 0)\n{\n    msg.colour = \"lime\";\n    msg.payload = \"lime\";\n} else\nif (x === 1)\n{\n    msg.colour = \"black\";\n    msg.payload = \"black\";\n}\n\nx = (x + 1) % 2;\n\ncontext.set(\"counter\",x);\n\nreturn msg;","outputs":1,"noerr":0,"x":4030,"y":720,"wires":[["4732f533.e29164","bc5aa5c4.52161","6af38fee.edbd3"]],"info":"You can change the two `msg.payload`s to\nwhat ever you want to be sent for the two\nstates.\nThe code has \"lime\" and \"black\" only because I\nwas using the output/s to control a \n`ui_LED` node and it blinked.\nThe flow sends a \"black\" when the button is\nreleased to turn the indicator off.\nThat is done with `msg.colour`.\n"},{"id":"bc5aa5c4.52161","type":"ui_template","z":"1781e581.31721a","group":"8418af9a.bbc66","name":"V Up","order":1,"width":2,"height":"1","format":"<button ng-mousedown=\"send({payload: 'Down'})\" ng-mouseup=\"send({payload: 'Up'})\">\n    <font color = {{msg.colour}}  class=\"fa fa-bullseye fa-2x\"> </font>\n</button>","storeOutMessages":true,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"local","x":3640,"y":680,"wires":[["6b7607e4.7d79c","15a715e3.e0c4fa","b51e2b02.46d418"]]},{"id":"6b7607e4.7d79c","type":"switch","z":"1781e581.31721a","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Down","vt":"str"},{"t":"eq","v":"Up","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":3860,"y":720,"wires":[[],["36fcedb1.36a5e2"]]},{"id":"6af38fee.edbd3","type":"switch","z":"1781e581.31721a","name":"THIS IS THE OUTPUT NODE *","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":4250,"y":720,"wires":[[]],"info":"I have used this node like this.\nThe `flow` sends \"black\" and \"lime\" outputs\nalternatly.\nTo change what is sent out, edit the `function`\nnode (\"toggle\") and change the `msg.payload`\nlines.\n"},{"id":"3a4c5635.3da31a","type":"comment","z":"1781e581.31721a","name":"Read me *","info":"This is a handy little \"flow\" to use so when you press a button, it blinks.\nHandy feedback in some cases.\nOpen the other two nodes who's names end with a `*` as they contain more information in their \"description\" tabs.\n","x":4040,"y":640,"wires":[]},{"id":"8418af9a.bbc66","type":"ui_group","z":"","name":"Group 4","tab":"b128eb09.9f681","order":5,"disp":true,"width":"4","collapse":false},{"id":"b128eb09.9f681","type":"ui_tab","z":"","name":"TV_Remote_control","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

I hope I have written good enough instructions in the comment node.
No extra nodes needed.

Nodes used:
template
trigger
switch
function

1 Like

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