Button with 2 functions

Hello,

I'm trying to use one same button on 2 different ways.
My payload from the button is usually 0, it is for moving to my first tab with the ui_control. So when the button is pressed the user moves to tab 0.

Now I have added a template wich returns me msg.payload:"true" and I want the same button to go now to tab 5. It means when template sends me msg.payload true, then go on press to tab 5, else go to tab 0.

Is there a way to make this with switch nodes, or do I have to write a function for it? And can someone give me a hint for the function?

No need for function nodes. It is just one variable to define in context (I used global context but the flow context is same as good) and you then need to change the value of that variable when needed. The event of that variable changing is also sent to the change node before button which then figures out the label for button. Button itself sends out the variable form context.

[{"id":"3a4c8a92.66dd36","type":"ui_button","z":"9f4fbba4.68ceb8","name":"","group":"152dfbc2.b2a224","order":1,"width":0,"height":0,"passthru":false,"label":"{{payload}}","tooltip":"","color":"","bgcolor":"","icon":"","payload":"tabToGo","payloadType":"global","topic":"topic","topicType":"msg","x":410,"y":700,"wires":[["e9aee8c5.98eec8"]]},{"id":"3cc0e2a9.fe0d9e","type":"change","z":"9f4fbba4.68ceb8","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"'Go to tab '&$globalContext(\"tabToGo\")\t","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":190,"y":700,"wires":[["3a4c8a92.66dd36","f67a7e56.3ba28"]]},{"id":"16f79dbf.361cf2","type":"inject","z":"9f4fbba4.68ceb8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":170,"y":800,"wires":[["e862682e.8e6318"]]},{"id":"e9aee8c5.98eec8","type":"debug","z":"9f4fbba4.68ceb8","name":"BTN OUTPUT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":610,"y":700,"wires":[]},{"id":"e862682e.8e6318","type":"change","z":"9f4fbba4.68ceb8","name":"","rules":[{"t":"set","p":"tabToGo","pt":"global","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":820,"wires":[["3cc0e2a9.fe0d9e"]]},{"id":"e758fc6.8f758","type":"inject","z":"9f4fbba4.68ceb8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"5","payloadType":"num","x":170,"y":840,"wires":[["e862682e.8e6318"]]},{"id":"f67a7e56.3ba28","type":"debug","z":"9f4fbba4.68ceb8","name":"BTN INPUT","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":430,"y":640,"wires":[]},{"id":"b28a92f7.4ea9c","type":"comment","z":"9f4fbba4.68ceb8","name":"Change button label ","info":"","x":200,"y":660,"wires":[]},{"id":"3cae34d6.cca44c","type":"comment","z":"9f4fbba4.68ceb8","name":"Change button target","info":"","x":380,"y":860,"wires":[]},{"id":"152dfbc2.b2a224","type":"ui_group","name":"IO","tab":"a0c30cd6.33919","order":3,"disp":true,"width":"7","collapse":false},{"id":"a0c30cd6.33919","type":"ui_tab","name":"Movement","icon":"dashboard","order":5,"disabled":false,"hidden":false}]

very nice thank you!

I was thinking about to set the value 0 and 5 into flow context, but I didtn realise that I can use flow context as payload inside the button.

working for 2 weeks straight with node red, and still noob :frowning:

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