How to edit a BUTTON Node without triggering it

Hi all,
is there a way to edit a BUTTON Node (from the generic Dashboard) ?
I would like toggle it between ON and OFF and red color / green color if pressed.

But if I create an output from the button to a function node, adapting all settings and use the function output as input for the button, it will be triggered again ... in an endless loop, right ?

And is there a way to set the Button.Caption and Button.Color ?

BR
Gawan

A button does not have an on/off state, it sends a value when pushed.
There are many topics on this forum, here is one such How to set up a toggle button?

here are many from Search results for 'toggle button' - Node-RED Forum

Don't select If msg arrives on input, emulate a button click:
Then it should not send a message when you send one in.

thanks collin, this works well

but unfortunately the button does not react on my inputs from the function node:

[{"id":"54ba0d4afac08d15","type":"ui_button","z":"a64b091a.a1bf2","name":"","group":"1495fa22.b16436","order":2,"width":1,"height":1,"passthru":false,"label":"OFF","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"1","payloadType":"num","topic":"topic","topicType":"msg","x":630,"y":460,"wires":[["89046dec383772c6"]]},{"id":"89046dec383772c6","type":"function","z":"a64b091a.a1bf2","name":"function 1","func":"var x = 0;\nx = global.get(\"EPEX.Active\");\nif (x==0){\n    x = 1;\n    global.set(\"EPEX.Active\",1);\n    msg.background = \"red\";\n    return [msg,null];\n}\nelse if (x==1){\n    x = 0;\n    global.set(\"EPEX.Active\",0);\n    msg.background = \"green\";\n    return [null,msg];\n}\n\nreturn msg;","outputs":2,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":460,"wires":[["54ba0d4afac08d15"],["54ba0d4afac08d15"]]},{"id":"1495fa22.b16436","type":"ui_group","name":"Standard","tab":"f420fdaa.3226a8","order":1,"disp":true,"width":8,"collapse":false},{"id":"f420fdaa.3226a8","type":"ui_tab","name":"EPEX Strom","icon":"dashboard","order":12,"disabled":false,"hidden":false}]

You have a few things wrong.

Firstly you should be using let not var nowadays. Google if you want to know why. That is not the cause of your problem though.

Secondly you are not setting x to anything if you have not already written a value to the global variable. In that case x will be undefined so neither of your tests will pass and the function will just return the message it was passed in. Change the first two lines to
let x = global.get("EPEX.Active") || 0;
That will set it to 0 if it is undefined.

Thirdly change the line
else if (x==1){
to
else {
and remove the return at the end. Then, if x ever gets to an illegal value it will not cause a major malfunction.

Finally, as written in the help for the button node, if you want to pass in the background colour in msg.background then in the Background field you have to put {{background}}

You are absolutely right - the function node was in the middle of beeing developed :slight_smile:
With your help I finally managed to set the button parameters as needed ! :+1:

image
image

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