Pass Input to Output after Pressing Click Button

Hello Guys,

I am trying to pass the input message to output after pressing Click Button.

I have 100 Character string input and tried many ways but failed in each attempt.

Please guide me how can i do that.

Regards,
Chetan

Welcome to the forum @Chetan_001

Unfortunately your post doesn't convey enough information to be answered. What input and what output are you talking about?

Trying to guess what you mean, if you mean that you want to block messages from passing until you click the button then have a look at node-red-contrib-simple-gate which will allow that. If you want to queue messages until a button is pressed then see node-red-contrib-simple-gate. If you mean you want a fixed message to be sent when you press a dashboard button then that can be configured in the node settings.

1 Like
[{"id":"99675829.6de928","type":"tab","label":"Excel Optput","disabled":true,"info":""},{"id":"9619c854.f34248","type":"function","z":"99675829.6de928","name":"Set data","func":"var now = new Date();\n\nmsg.payload = {\n    \"Timestamp\" : now.getTime(),\n    \"Voltage\" : msg.payload[0],\n    \"Current\" : msg.payload[1],\n    \"Power Factor\" : msg.payload[2],\n    \"Frequency\" : msg.payload[3],\n    \"Wattage\" : msg.payload[4]\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":380,"wires":[["e362c33e.b527b","2204b311.b8d04c"]]},{"id":"80a9777.4ac2e88","type":"function","z":"99675829.6de928","name":"Filename generator","func":"// Get the current time and convert it to text\nvar now = new Date();\nvar yyyy = now.getFullYear();\nvar mm = now.getMonth() < 9 ? \"0\" + (now.getMonth() + 1) : (now.getMonth() + 1); // getMonth() is zero-based\nvar dd  = now.getDate() < 10 ? \"0\" + now.getDate() : now.getDate();\nvar hh = now.getHours() < 10 ? \"0\" + now.getHours() : now.getHours();\nvar mmm  = now.getMinutes() < 10 ? \"0\" + now.getMinutes() : now.getMinutes();\nvar ss  = now.getSeconds() < 10 ? \"0\" + now.getSeconds() : now.getSeconds();\n\n// Generate out file name pattern\nmsg.fname = \"Line1_\"+ yyyy + mm + dd + \".csv\";\n// Full filename with path for the file node later\nmsg.filename = \"D:/MeterCheck/\"+ msg.fname;\n\n// We save the current payload into a different place on the msg object\nmsg.filecontent = msg.payload;\n\n// We are passing the file name search pattern to fs node to tell us if the file exists or not\nmsg.payload = {\"pattern\":msg.fname};\n\nnode.status({fill:\"blue\",shape:\"ring\",text:msg.fname});\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":90,"y":900,"wires":[["24865533.cf4a7a"]]},{"id":"b191c05f.540f2","type":"debug","z":"99675829.6de928","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":450,"y":820,"wires":[]},{"id":"1773775e.b985a9","type":"switch","z":"99675829.6de928","name":"","property":"$count(msg.payload)","propertyType":"jsonata","rules":[{"t":"eq","v":"0","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":430,"y":900,"wires":[["de24c840.31f708"],["63db2bfc.e8d114"]]},{"id":"56ecbbe0.c5d264","type":"csv","z":"99675829.6de928","name":"","sep":",","hdrin":true,"hdrout":"once","multi":"mult","ret":"\\r\\n","temp":"Timestamp,Voltage,Current, Power Factor, Frequency, Wattage","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":810,"y":860,"wires":[["bdf541f9.1765f"]]},{"id":"bdf541f9.1765f","type":"file","z":"99675829.6de928","name":"","filename":"","appendNewline":false,"createDir":true,"overwriteFile":"false","encoding":"none","x":970,"y":880,"wires":[[]]},{"id":"43d9fb52.3d0fd4","type":"csv","z":"99675829.6de928","name":"","sep":",","hdrin":true,"hdrout":"once","multi":"mult","ret":"\\r\\n","temp":"Timestamp,Voltage,Current, Power Factor, Frequency, Wattage","skip":"0","strings":true,"include_empty_strings":true,"include_null_values":true,"x":830,"y":920,"wires":[["bdf541f9.1765f"]]},{"id":"de24c840.31f708","type":"change","z":"99675829.6de928","name":"Get file content","rules":[{"t":"set","p":"payload","pt":"msg","to":"filecontent","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":880,"wires":[["56ecbbe0.c5d264"]]},{"id":"63db2bfc.e8d114","type":"change","z":"99675829.6de928","name":"Get file content","rules":[{"t":"set","p":"payload","pt":"msg","to":"filecontent","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":920,"wires":[["43d9fb52.3d0fd4"]]},{"id":"24865533.cf4a7a","type":"fs-file-lister","z":"99675829.6de928","name":"","start":"D:\\MeterCheck","pattern":"","folders":"*","hidden":true,"lstype":"files","path":true,"single":true,"depth":0,"stat":true,"showWarnings":false,"x":280,"y":900,"wires":[["b191c05f.540f2","1773775e.b985a9"]]},{"id":"de978496.484018","type":"modbus-read","z":"99675829.6de928","d":true,"name":"Modbus Read","topic":"","showStatusActivities":false,"logIOActivities":false,"showErrors":false,"unitid":"1","dataType":"InputRegister","adr":"0","quantity":"34","rate":"300","rateUnit":"ms","delayOnStart":false,"startDelayTime":"","server":"248551dd.d9a0ce","useIOFile":false,"ioFile":"","useIOForPayload":false,"emptyMsgOnFail":false,"x":170,"y":340,"wires":[["efb97eca.95ebc","560f8d42.1f7174","dc2779b0.db1b58","c4d4d691.f2a278","8786a291.cc687","45888e88.3506"],["190c4851.2c48f8"]]},{"id":"efb97eca.95ebc","type":"modbus-response","z":"99675829.6de928","name":"","registerShowMax":20,"x":170,"y":280,"wires":[]},{"id":"190c4851.2c48f8","type":"modbus-response","z":"99675829.6de928","name":"","registerShowMax":20,"x":170,"y":400,"wires":[]},{"id":"560f8d42.1f7174","type":"function","z":"99675829.6de928","name":"Voltage","func":"var msg = {payload: (msg.payload[21]<<16) + (msg.payload[20])}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":80,"wires":[["626fd85b.7605d8"]]},{"id":"626fd85b.7605d8","type":"toFloat","z":"99675829.6de928","name":"Concersion","toFixed":"8","x":650,"y":80,"wires":[["661302a5.80881c","58faa37f.d1864c","49a83e22.5b9c2"]]},{"id":"661302a5.80881c","type":"debug","z":"99675829.6de928","name":"msg.payload","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":80,"wires":[]},{"id":"dc2779b0.db1b58","type":"function","z":"99675829.6de928","name":"Current","func":"var msg = {payload: (msg.payload[23]<<16) + (msg.payload[23])}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":120,"wires":[["6bb2aba3.a16884"]]},{"id":"6bb2aba3.a16884","type":"toFloat","z":"99675829.6de928","name":"Conversion","toFixed":"","x":650,"y":120,"wires":[["e7bd80a0.68554","58faa37f.d1864c","382369aa.4c9636"]]},{"id":"e7bd80a0.68554","type":"debug","z":"99675829.6de928","name":"msg.payload","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":120,"wires":[]},{"id":"c4d4d691.f2a278","type":"function","z":"99675829.6de928","d":true,"name":"Power Factor","func":"var msg = {payload: (msg.payload[25]<<16) + (msg.payload[25])}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":160,"wires":[["79c342b5.da46bc"]]},{"id":"79c342b5.da46bc","type":"toFloat","z":"99675829.6de928","name":"Conversion","toFixed":"","x":650,"y":160,"wires":[["b6ec7018.4088d","58faa37f.d1864c","c03f3fd6.d48b5"]]},{"id":"b6ec7018.4088d","type":"debug","z":"99675829.6de928","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]},{"id":"8786a291.cc687","type":"function","z":"99675829.6de928","name":"Frequency","func":"var msg = {payload: (msg.payload[27]<<16) + (msg.payload[27])}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":450,"y":200,"wires":[["c2d8d7e7.a16308"]]},{"id":"c2d8d7e7.a16308","type":"toFloat","z":"99675829.6de928","name":"Conversion","toFixed":"","x":650,"y":200,"wires":[["c4ed1d03.a1a8b","58faa37f.d1864c","cbe3a468.333898"]]},{"id":"c4ed1d03.a1a8b","type":"debug","z":"99675829.6de928","name":"msg.payload","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":870,"y":200,"wires":[]},{"id":"45888e88.3506","type":"function","z":"99675829.6de928","name":"Wattage","func":"var msg = {payload: (msg.payload[15]<<16) + (msg.payload[15])}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":440,"y":240,"wires":[["d91946b1.2011d8"]]},{"id":"d91946b1.2011d8","type":"toFloat","z":"99675829.6de928","name":"Conversion","toFixed":"","x":650,"y":240,"wires":[["58faa37f.d1864c","1ce68b0.8581d75"]]},{"id":"58faa37f.d1864c","type":"join","z":"99675829.6de928","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"5","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":870,"y":320,"wires":[["9619c854.f34248"]]},{"id":"e362c33e.b527b","type":"debug","z":"99675829.6de928","name":"msg.payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":850,"y":400,"wires":[]},{"id":"49a83e22.5b9c2","type":"ui_artlessgauge","z":"99675829.6de928","group":"985a3531.0ce638","order":1,"width":8,"height":6,"name":"","icon":"","label":"Voltage","unit":"","layout":"radial","decimals":"2","differential":false,"minmax":true,"colorTrack":"#555555","colorFromTheme":true,"property":"payload","sectors":[{"val":0,"col":"#2bff00","t":"min","dot":0},{"val":250,"col":"#2bff00","t":"max","dot":0}],"lineWidth":"11","bgcolorFromTheme":true,"diffCenter":"","x":1100,"y":80,"wires":[]},{"id":"382369aa.4c9636","type":"ui_artlessgauge","z":"99675829.6de928","group":"985a3531.0ce638","order":2,"width":8,"height":6,"name":"","icon":"","label":"Current","unit":"","layout":"radial","decimals":"4","differential":false,"minmax":true,"colorTrack":"#555555","colorFromTheme":true,"property":"payload","sectors":[{"val":0,"col":"#2bff00","t":"min","dot":0},{"val":2,"col":"#2bff00","t":"max","dot":0}],"lineWidth":"11","bgcolorFromTheme":true,"diffCenter":"","x":1100,"y":120,"wires":[]},{"id":"c03f3fd6.d48b5","type":"ui_artlessgauge","z":"99675829.6de928","group":"985a3531.0ce638","order":10,"width":8,"height":6,"name":"","icon":"","label":"Power Factor","unit":"","layout":"radial","decimals":"2","differential":false,"minmax":true,"colorTrack":"#555555","colorFromTheme":true,"property":"payload","sectors":[{"val":-1,"col":"#2bff00","t":"min","dot":0},{"val":1,"col":"#2bff00","t":"max","dot":0}],"lineWidth":"11","bgcolorFromTheme":true,"diffCenter":"","x":1100,"y":160,"wires":[]},{"id":"cbe3a468.333898","type":"ui_artlessgauge","z":"99675829.6de928","group":"985a3531.0ce638","order":9,"width":8,"height":6,"name":"","icon":"","label":"Frequency","unit":"","layout":"radial","decimals":"2","differential":false,"minmax":true,"colorTrack":"#555555","colorFromTheme":true,"property":"payload","sectors":[{"val":49,"col":"#2bff00","t":"min","dot":0},{"val":51,"col":"#2bff00","t":"max","dot":0}],"lineWidth":"11","bgcolorFromTheme":true,"diffCenter":"","x":1100,"y":200,"wires":[]},{"id":"76655afb.fd23c4","type":"ui_artlessgauge","z":"99675829.6de928","group":"985a3531.0ce638","order":8,"width":8,"height":6,"name":"","icon":"","label":"Wattage","unit":"","layout":"radial","decimals":"4","differential":false,"minmax":true,"colorTrack":"#555555","colorFromTheme":true,"property":"payload","sectors":[{"val":0,"col":"#2bff00","t":"min","dot":0},{"val":100,"col":"#2bff00","t":"max","dot":0}],"lineWidth":"11","bgcolorFromTheme":true,"diffCenter":"","x":1280,"y":240,"wires":[]},{"id":"3487f2c6.f030ae","type":"ui_template","z":"99675829.6de928","group":"d4f40bbe.af1178","name":"Clock Toolbar","order":2,"width":"0","height":"0","format":"<script id=\"titleScript\" type=\"text/javascript\">\n\n$(function() {\n    if($('.md-toolbar-tools').length != 0){\n        loadClock();\n    }else setTimeout(loadClock, 500)\n});\n\nfunction loadClock(){\n    $('#clock').remove();\n    var toolbar = $('.md-toolbar-tools');\n    \n    var div = $('<div/>');\n    var p = $('<p/ id=\"clock\">');\n    \n    div.append(p);\n    div[0].style.margin = '5px 5px 5px auto';\n    toolbar.append(div);\n\n    function displayTitle(lh) {\n        p.text(lh); \n    }\n    \n    function upTime() {\n        var d = new Date();\n        p.text(d.toLocaleString());\n    }\n\n    if(document.clockInterval){ \n            clearInterval(document.clockInterval);\n            document.clockInterval = null;\n    }\n        \n    document.clockInterval = setInterval(upTime,1000);\n}\n\n</script>","storeOutMessages":false,"fwdInMessages":false,"resendOnRefresh":false,"templateScope":"global","x":140,"y":100,"wires":[[]]},{"id":"53b9ea54.f78964","type":"ui_text_input","z":"99675829.6de928","name":"Tester Name","label":"Tester Name","tooltip":"","group":"985a3531.0ce638","order":3,"width":8,"height":2,"passthru":true,"mode":"text","delay":300,"topic":"","x":150,"y":240,"wires":[[]]},{"id":"2204b311.b8d04c","type":"trigger","z":"99675829.6de928","name":"","op1":"","op2":"","op1type":"pay","op2type":"nul","duration":"0","extend":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":140,"y":440,"wires":[["1ebf16f3.6968b9"]]},{"id":"1ebf16f3.6968b9","type":"debug","z":"99675829.6de928","name":"msg.payload","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":330,"y":440,"wires":[]},{"id":"1ce68b0.8581d75","type":"function","z":"99675829.6de928","name":"","func":"var msg = {payload: (msg.payload*1000)}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":860,"y":240,"wires":[["c0303d38.769ee","76655afb.fd23c4"]]},{"id":"c0303d38.769ee","type":"debug","z":"99675829.6de928","name":"msg.payload","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1030,"y":240,"wires":[]},{"id":"248551dd.d9a0ce","type":"modbus-client","z":"","name":"Meter USB","clienttype":"serial","bufferCommands":true,"stateLogEnabled":false,"queueLogEnabled":false,"tcpHost":"127.0.0.1","tcpPort":"502","tcpType":"DEFAULT","serialPort":"COM4","serialType":"RTU-BUFFERD","serialBaudrate":"9600","serialDatabits":"8","serialStopbits":"1","serialParity":"none","serialConnectionDelay":"100","unit_id":"1","commandDelay":"1","clientTimeout":"1000","reconnectOnTimeout":true,"reconnectTimeout":"2000","parallelUnitIdsAllowed":true},{"id":"985a3531.0ce638","type":"ui_group","z":"","name":"Voltage Gauge","tab":"dd890cfb.b56fc","order":1,"disp":false,"width":24,"collapse":false},{"id":"d4f40bbe.af1178","type":"ui_group","z":"","name":"hidden_group","tab":"dd890cfb.b56fc","order":1,"disp":false,"width":"6","collapse":false},{"id":"dd890cfb.b56fc","type":"ui_tab","z":"","name":"Samudra Electronic System Private Limited","icon":"Samudra","order":2,"disabled":false,"hidden":false}]

In attached flow i am trying to pass latest value to filename generator after button press in UI. Object i want to connect is from set data node.

Hope this will help you to guide me.

Thanks in advance.

What you provided is a disabed flow labeled 'Excel Output' which contains no button. If that is the right flow, where is the filename generaton occurring?

Trying to determine exactly what you want to do, do you mean that you have messages appearing from the set data node and when you click a ui button you want to send the last message from set data on to some more nodes?
If so then look at this from the cookbook https://cookbook.nodered.org/basic/join-streams, which shows how you can use a Join node to combine messages from two streams using the topic to identify the streams. Then you can feed the set data and ui button into it and get a message out whenever either of them changes. Test the topic coming out of the Join node and if it is the button topic then you can pass the set data message on.

Input to file name generator is from set data. I want to add ui button in between them. Only after pressing button it should send object in set data node to filename generator.

Checked the link. Nothing is mentioned to supportive to currently discussing topic.

Yes it is, that is a way to solve it, you cannot block the message the way you are suggesting. Read my last post again.

Or you can use a ui_form nodes so accept an input and press submit ?

I have input in the form of payload from existing node. How can i do that in forms? ow to read previous node payload in forms node?

In that case I don't think you can do it with a form. The Join node is a good solution.

you have my flow can you guide me how to use join node in my case

That is how to do it. Have you imported the flow in the example and tried it to understand how it works?

Join i have used in my flow too. i know its functionality. i want to add a button in mu flow after set data. set data should be send only wheni click on button. Will you be able to help?

What in my description of how to do it do you not understand?

i am not understanding how to use that in my flow. can we do a Microsoft teams meeting to resolve this.

Have you used the join node in key/value mode?

no can you guide me how can i do that to pass value only after click?

flows (5).json (14.3 KB)

Please check flow after set data.

First you say you know about the Join node, then you say you have not used it in the mode required. All I can do is say again to Import the example I linked to and experiment with it to see how it works. When you understand how it works then read my post again, which explains you to use it in your application. Try that and if it you can't get it to do what you want then ask again.