Button node bug report. (Look at bottom)

There isn't a bug that I can see. The node just has to be used correctly.

(And I don't know how to. There is no "bug report" option in the bull downs.)

Try the test case that I posted, where I have the send topic set to an empty string, which is what you had in the original flow you posted. Then it should always send an empty topic, but it doesn't, it behaves as if msg.topic is specified. So your original problem was due to this bug. You can submitting a bug against the dashboard just like any other node at Issues Ā· node-red/node-red-dashboard Ā· GitHub

The new button node has a selector to select what is the topic.

As it is set to msg.topic and it receives the setup message - from the inject node it gets that topic.

Subsequent pressing of the button it keeps that topic.

Is that a bug? I'm not qualified to say if it is or not.
(Remember: I can't read)

So that I had the node set to use msg.topic (the default) and if I change it to something_else as a string then it works.

No bug.

Look in your original flow, that is not how you have configured the button.

image

So it should have sent the topic as an empty string, but it wasn't, it was sending it as if you had msg.topic set there. That is the bug.

You haven't got the latest button.

That is the OLD one.

The new one is different.

Screenshot from 2021-02-28 21-07-33

That is the default.

To fix the problem I (now) have is I just change it so the Topic is set to string and something else written there.

The OLD ones work fine.

When I updated to the new ones, the wheels fell off the wagon - because I didn't change the topic's settings.

Why do you see that as a bug?

Look at the original flow you posted, that is configured as in the image I posted, in fact the image I posted is taken from your original flow. The Button is not at the default setting.

This is the one which is the OLD way. I used to work. It doesn't any more with the new button node.

[{"id":"5dcb15fb.24d17c","type":"inject","z":"39ea4ac5.b46c1e","name":"Inject","repeat":"","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"","payloadType":"str","x":420,"y":860,"wires":[["6272e4a0.8faa44"]]},{"id":"6272e4a0.8faa44","type":"function","z":"39ea4ac5.b46c1e","name":"Setup","func":"msg = {\n    \"topic\":\"SETUP\",\n    \"disabledColour\":\"brown\",\n    \"colourA\": \"lime\",\n    \"colourB\": \"green\",\n    \"txtA\": \"Log\",\n    \"txtB\": \"Log Stop\",\n    \"txtclrA\": \"black\",\n    \"txtclrB\": \"black\",\n    \"payloadA\": \"GO\",\n    \"payloadB\": \"STOP\",\n    \"topicSET\": \"CONTROL\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":420,"y":900,"wires":[["93f710a2.69e118"]]},{"id":"a999cdd7.d7fdc","type":"ui_button","z":"39ea4ac5.b46c1e","name":"Error Logging","group":"d057989d.1f3368","order":3,"width":"2","height":"1","passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"","x":630,"y":860,"wires":[["93f710a2.69e118","763a7526.22a8f4"]]},{"id":"93f710a2.69e118","type":"function","z":"39ea4ac5.b46c1e","name":"Push Button","func":"//  working\nvar state = context.get(\"STATE\")||0;\nvar enabled = context.get(\"ENABLED\")||0;\n\n//  Look for a message with topic set to SETUP to set values.\nif (msg.topic == \"SETUP\")     //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    //  Disabled button background colour.\n    //\n    context.set(\"DISABLEDCLR\",msg.disabledColour);\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    msg.txt = msg.txtA;\n    msg.colour = msg.disabledColour;\n    msg.fontclr = msg.txtclrA;\n    return msg;\n}\n\n//      Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n    //node.warn(\"X detected\");\n    //  Insert here code to enable other stuff.\n//    if (context.get(\"ENABLED\") === 0)\n    if (enabled === 0)\n    {\n        //\n        //  Old code.\n        //\n        //node.warn(\"Setting enable\");\n//        context.set(\"ENABLED\",1);\n//        msg.txt = context.get(\"Atxt\");\n//        msg.colour = context.get(\"ABGC\");\n//        msg.fontclr = context.get(\"AFC\");\n\n        //  New code.\n        \n        //node.warn(\"State = \" + state);\n\n        if (state === 0)\n        {\n            //\n            //  Set things for state 0\n            //\n            //node.warn(\"State 0 detected\");\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        }\n        else if (state === 1)\n        {\n            //\n            //  Set things for state 1\n            //\n            //node.warn(\"State 1 detected\");\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        }\n        context.set(\"ENABLED\",1);\n        return msg;\n    }\n\n//    if (context.get(\"ENABLED\") === 1)\n    state = (state + 1)% 2;\n    //node.warn(state);\n    context.set(\"STATE\",state);\n    if (enabled === 1)\n    {\n        if (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        if (state === 1)\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        }\n    }\n    \n    if (context.get(\"Topic\") == \"~\")\n    {\n        msg.topic = \"\";\n    } else\n    {\n        msg.topic = context.get(\"Topic\");\n    }\n    return msg;\n}\nif (msg.payload == \"Z\")\n{\n    //\n    ////node.warn(\"Timed out\");\n    //\n    context.set(\"ENABLED\",0);\n    if (state === 0)\n    {\n        //\n        //  Set things for state 1\n        //\n        msg.payload = context.get(\"PayloadA\");\n        msg.colour = context.get(\"DISABLEDCLR\");\n        msg.txt = context.get(\"Atxt\");\n        msg.fontclr = context.get(\"AFC\");\n    }\n    else if (state === 1)\n    {\n        //\n        //  Set things for state 2\n        //\n        msg.payload = context.get(\"PayloadB\");\n        msg.colour = context.get(\"DISABLEDCLR\");\n        msg.txt = context.get(\"Btxt\");\n        msg.fontclr = context.get(\"BFC\");\n    }\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":620,"y":900,"wires":[["a999cdd7.d7fdc","1ddaae04.be6602"]]},{"id":"763a7526.22a8f4","type":"trigger","z":"39ea4ac5.b46c1e","name":"","op1":"","op2":"Z","op1type":"nul","op2type":"str","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","outputs":1,"x":610,"y":940,"wires":[["93f710a2.69e118"]]},{"id":"d057989d.1f3368","type":"ui_group","name":"Errors","tab":"41ad2f9a.ed0df","order":2,"disp":true,"width":"6","collapse":false},{"id":"41ad2f9a.ed0df","type":"ui_tab","name":"Logging","icon":"list","order":5,"disabled":false,"hidden":false}]

It is the default setting for the button.

This is the modified flow and the node has been changed.

[{"id":"c5ccf203.8fff9","type":"inject","z":"39ea4ac5.b46c1e","name":"Inject","repeat":"","crontab":"","once":true,"onceDelay":"3","topic":"","payload":"","payloadType":"str","x":290,"y":440,"wires":[["a95c95ac.a0ab6"]]},{"id":"a95c95ac.a0ab6","type":"function","z":"39ea4ac5.b46c1e","name":"Setup","func":"msg = {\n    \"topic\":\"SETUP\",\n    \"disabledColour\":\"brown\",\n    \"colourA\": \"lime\",\n    \"colourB\": \"green\",\n    \"txtA\": \"Display\",\n    \"txtB\": \"Display Stop\",\n    \"txtclrA\": \"black\",\n    \"txtclrB\": \"black\",\n    \"payloadA\": \"GO\",\n    \"payloadB\": \"STOP\",\n    \"topicSET\": \"CONTROL\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":290,"y":480,"wires":[["e0d476a7.3e5e7"]]},{"id":"1d77a37e.a76b95","type":"ui_button","z":"39ea4ac5.b46c1e","name":"Commands RX List","group":"1baf0833.3ae918","order":1,"width":"2","height":"1","passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"blah","topicType":"str","x":510,"y":440,"wires":[["e0d476a7.3e5e7","aa338cfc.ca1fd"]]},{"id":"e0d476a7.3e5e7","type":"function","z":"39ea4ac5.b46c1e","name":"Push Button","func":"var state = context.get(\"STATE\")||0;\nvar enabled = context.get(\"ENABLED\")||0;\n\n//  Look for a message with topic set to SETUP to set values.\nif (msg.topic == \"SETUP\")     //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    //  Disabled button background colour.\n    //\n    context.set(\"DISABLEDCLR\",msg.disabledColour);\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    msg.txt = msg.txtA;\n    msg.colour = msg.disabledColour;\n    msg.fontclr = msg.txtclrA;\n    return msg;\n}\n\n//      Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n    //node.warn(\"X detected\");\n    //  Insert here code to enable other stuff.\n//    if (context.get(\"ENABLED\") === 0)\n    if (enabled === 0)\n    {\n        //\n        //  Old code.\n        //\n        //node.warn(\"Setting enable\");\n//        context.set(\"ENABLED\",1);\n//        msg.txt = context.get(\"Atxt\");\n//        msg.colour = context.get(\"ABGC\");\n//        msg.fontclr = context.get(\"AFC\");\n\n        //  New code.\n        \n        //node.warn(\"State = \" + state);\n\n        if (state === 0)\n        {\n            //\n            //  Set things for state 0\n            //\n            //node.warn(\"State 0 detected\");\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        }\n        else if (state === 1)\n        {\n            //\n            //  Set things for state 1\n            //\n            //node.warn(\"State 1 detected\");\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        }\n        context.set(\"ENABLED\",1);\n        return msg;\n    }\n\n//    if (context.get(\"ENABLED\") === 1)\n    state = (state + 1)% 2;\n    //node.warn(state);\n    context.set(\"STATE\",state);\n    if (enabled === 1)\n    {\n        if (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        if (state === 1)\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        }\n    }\n    \n    if (context.get(\"Topic\") == \"~\")\n    {\n        msg.topic = \"\";\n    } else\n    {\n        msg.topic = context.get(\"Topic\");\n    }\n    return msg;\n}\nif (msg.payload == \"Z\")\n{\n    //\n    ////node.warn(\"Timed out\");\n    //\n    context.set(\"ENABLED\",0);\n    if (state === 0)\n    {\n        //\n        //  Set things for state 1\n        //\n        msg.payload = context.get(\"PayloadA\");\n        msg.colour = context.get(\"DISABLEDCLR\");\n        msg.txt = context.get(\"Atxt\");\n        msg.fontclr = context.get(\"AFC\");\n    }\n    else if (state === 1)\n    {\n        //\n        //  Set things for state 2\n        //\n        msg.payload = context.get(\"PayloadB\");\n        msg.colour = context.get(\"DISABLEDCLR\");\n        msg.txt = context.get(\"Btxt\");\n        msg.fontclr = context.get(\"BFC\");\n    }\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":490,"y":480,"wires":[["1d77a37e.a76b95","217a2e14.0dbb4a"]]},{"id":"aa338cfc.ca1fd","type":"trigger","z":"39ea4ac5.b46c1e","name":"","op1":"","op2":"Z","op1type":"nul","op2type":"str","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","outputs":1,"x":480,"y":520,"wires":[["e0d476a7.3e5e7"]]},{"id":"1baf0833.3ae918","type":"ui_group","name":"Cmds Received","tab":"41ad2f9a.ed0df","order":1,"disp":true,"width":"6","collapse":false},{"id":"41ad2f9a.ed0df","type":"ui_tab","name":"Logging","icon":"list","order":5,"disabled":false,"hidden":false}]

I don't know if I am getting more and more stupid as this thread continues, or what.

That code has the same problem. You just added an extra node, to achieve what?

The TOPIC from the button being pressed is not correct - by the old way.
The new way..... I don't know.
Should it Keep the previous topic and use it for ongoing messages?
(You are asking the wrong person)

Honestly: I've seen my mistake. I've edited the nodes and made them send a different topic.
Problem solved.

All the buttons now are the new ones. Kinda makes the old one's quirks irrelevant.

Answer me two questions please.
Question 1. In your original flow (as you have just re-posted) did you have the send topic configured to be an empty string.
Clue
image

Question 2. Did it send an empty string in the topic when you clicked it?
image

If the answer to question 1 is Yes and to question 2 is No then the button is not behaving as you have configured it.

The original flow had the msg.topic left as blank.

It used to work.

Updating it to the newer version this behaviour is different.

Are you able to answer the questions?
I am attempting to prove that there is a bug in the current version, which you have disputed.

@Colin You've tried to make your point with @Trying_to_learn, but he isn't seeing it. At this point, please just raise an issue yourself.

I think you are right. See bug report.

Thanks to @Trying_to_learn for finding this bug, even though it appears that he will not accept that it is a bug, and that it is the cause of the problem that this post is about, which he worked around by providing a string in the configured topic rather than leaving it empty.

1 Like

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