Pushbutton flow

Although buttons are nice, sometimes you simply want a TOGGLE button.

This flow allows for that.

Read the COMMENT node at the top for all the variables used/needed.

I have NOT allowed for any null entries. You must fill them all in. Except for the topic file. That has a kind of built in "if nothing entered" bit.

There is a button node which is set up ready for use. All you need to do is set the size and on which dashboard it lives.

The main set up is in the SETUP function node. There, there is a list of what is needed to be set up.

Examples are in there now.

[{"id":"11b5c675.c3f1ba","type":"function","z":"df652827.d02c3","name":"Push Button","func":"var state = context.get(\"STATE\")||0;\n\n//  Look for a !X message to get values.\nif (msg.payload != \"X\")     //Do this if the message is NOT \"X\"\n{\n    //\n    //  Background colours first.\n    //\n    context.set(\"ABGC\", msg.colourA);\n    context.set(\"BBGC\", msg.colourB);\n    //\n    //  Now do text.\n    //\n    context.set(\"Atxt\", msg.txtA);\n    context.set(\"Btxt\", msg.txtB);\n    //\n    //  Font colours.\n    //\n    context.set(\"AFC\",msg.txtclrA);\n    context.set(\"BFC\",msg.txtclrB);\n    //\n    //  Payloads.\n    //\n    context.set(\"PayloadA\", msg.payloadA);\n    context.set(\"PayloadB\", msg.payloadB);\n    //\n    //  Topic.\n    //\n    if (msg.topicSET !== null)\n    {\n        context.set(\"Topic\",msg.topicSET);\n    } else\n    {\n        context.set(\"Topic\",\"~\");\n    }\n    return;\n}\n//      Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n    state = (state + 1)% 2;\n    //node.warn(state);\n    context.set(\"STATE\",state);\n}\nif (state === 0)\n{\n    //  Condition A\n    msg.payload = context.get(\"PayloadA\");\n    msg.colour = context.get(\"ABGC\");\n    msg.txt = context.get(\"Atxt\");\n    msg.fontclr = context.get(\"AFC\");\n} else\n{\n    //  Condition B\n    msg.payload = context.get(\"PayloadB\");\n    msg.colour = context.get(\"BBGC\");\n    msg.txt = context.get(\"Btxt\");\n    msg.fontclr = context.get(\"BFC\");\n}\nif (context.get(\"Topic\") == \"~\")\n{\n    msg.topic = \"\";\n} else\n{\n    msg.topic = context.get(\"Topic\");\n}\nreturn msg;\n","outputs":1,"noerr":0,"x":540,"y":300,"wires":[["3c7dc256.8e3e46"]]},{"id":"3c7dc256.8e3e46","type":"ui_button","z":"df652827.d02c3","name":"RBE Button","group":"396240c9.2d409","order":5,"width":"1","height":"1","passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"","x":540,"y":250,"wires":[["11b5c675.c3f1ba"]]},{"id":"839b0fab.0972e8","type":"inject","z":"df652827.d02c3","name":"Setup","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"3","x":520,"y":160,"wires":[["c3514fad.809d8"]]},{"id":"80d7b072.b72b88","type":"comment","z":"df652827.d02c3","name":"Push Button Flow","info":"This has two states:\nA and B.\nAll future refrence is to these two state names.\n\nREQUIRED:\nInputs:\nButton background colour for state A.  msg.colurA\nButton background colour for state B.  msg.colourB\nButton text for state A.               msg.txtA\nButton text for state B.               msg.txtB\nFont colour for state A.               msg.txtclrA\nFont colour for state B.               msg.txtclrB\nPayload for state A.                   msg.payloadA\nPayload for state B.                   msg.payloadB\nTopic.                                 msg.topicSET\n\nOutputs:\nmsg.payload - this is used to control what ever you need.\nmsg.topic - this is if it is needed for control of the next node.\nmsg.colour - this sets the colour of the button.\nmsg.txt - this is the text to be displayed in the button.\nmsg.fontclr - this is the colour of the text on the button.\n","x":520,"y":110,"wires":[]},{"id":"c3514fad.809d8","type":"function","z":"df652827.d02c3","name":"Setup","func":"msg = {\n    \"colourA\": \"yellow\",\n    \"colourB\": \"blue\",\n    \"txtA\": \"SOM\",\n    \"txtB\": \"SOM-EOM\",\n    \"txtclrA\": \"black\",\n    \"txtclrB\": \"white\",\n    \"payloadA\": \"GO\",\n    \"payloadB\": \"STOP\",\n    \"topicSET\": \"CONTROL\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":520,"y":210,"wires":[["11b5c675.c3f1ba"]]},{"id":"396240c9.2d409","type":"ui_group","z":"","name":"WAP","tab":"d54cd82e.537658","order":3,"disp":true,"width":"4","collapse":false},{"id":"d54cd82e.537658","type":"ui_tab","z":"","name":"Logging","icon":"dashboard","order":3,"disabled":false,"hidden":false}]

Flow Info

Created 5 years, 3 months ago
Rating: not yet rated

Actions

Rate:

Node Types

Core
  • comment (x1)
  • function (x2)
  • inject (x1)
Other
  • ui_button (x1)
  • ui_group (x1)
  • ui_tab (x1)

Tags

  • Push_button
  • button
  • toggle
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option