How to setup log

Hi everyone, is there a way to setup a log to monitor past data from an input? I'm still rather confused on how to set one after reading through some forums.

What I have in mind was to set the log to store up to 10 data or to display top 10 latest information for people to read.

Thanks in advance

Do you want that data logged in Node-RED or in the browser? Both are possible.

Ehhh I wanted to log the past few things registered through Node-RED and have the history of it displayed on the dashboard. Although, I've found a way to work on it, but the ui doesn't seem nice since I'm using the ui_table to display the log. Any other suggestion on which node should I use?

Here is a scrolling message table on the dashboard as well as writing to a log file on disk

One of the other members on here gave me the basic code for this a LONG time ago (sorry can't remember who) - i have not looked at it in more than a year or so - but should do what you want

[{"id":"75fcc40f.e3167c","type":"debug","z":"10b98a0a.175376","name":"Raw MQTT from the Pump Relay","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","x":480,"y":760,"wires":[]},{"id":"e965bc13.3213a","type":"mqtt in","z":"10b98a0a.175376","name":"Incoming MQTT from Tank Pump","topic":"stat/Tank_Top_Up_Pump/POWER","qos":"2","datatype":"auto","broker":"ee495ae9.36c048","x":190,"y":680,"wires":[["75fcc40f.e3167c","12741692.106189"]]},{"id":"7e84a9c8.9bf858","type":"function","z":"10b98a0a.175376","name":"Build Message for LogFile","func":"var topic = msg.topic;\nif (msg.payload === \"ON\") {\n    var p = \"On\";\n    } \nelse if (msg.payload === \"OFF\") { \n    var p = \"Off\";\n    }\nelse var p = \"Unknown\";\n\nvar d = flow.get(\"MyDateTime\") || \"0\";\n//var myCount = flow.get(\"count\", storeName);\n\n//create message to write to the log file\nvar payload1 = (d + \" Tank Pump is \" + p + \" Topic is: \" + msg.topic);\n//Store message so it can be output on output 1\nvar msg1 = { payload:payload1 };\n\n//Create 2nd message for screen writing on scrolling table\nvar payload2 = (d + \" Tank Pump is \" + p);\n//Store message so it can be output on output 2\nvar msg2 = { payload:payload2 };\n\nif (p == \"On\") {\nvar msg3 = { payload:'<i class=\"fa fa-refresh fa-spin fa-3x fa-fw\"></i>' };\n}\n\nif (p == \"Off\") {\nvar msg3 = { payload:'<i class=\"fa fa-stop-circle-o fa-3x fa-fw\"></i>' };\n}\n\n//End Function and return two messages on two outputs\nreturn [msg1, msg2, msg3,];\n\n","outputs":3,"noerr":0,"x":490,"y":680,"wires":[["f7fbd013.0037b","96d8b63f.b83e08"],["7c1b9286.bb8fdc"],["df59820b.7cf47"]]},{"id":"f7fbd013.0037b","type":"debug","z":"10b98a0a.175376","name":"Message for Logfile","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":790,"y":640,"wires":[]},{"id":"96d8b63f.b83e08","type":"file","z":"10b98a0a.175376","name":"Log info to the file","filename":"/home/pi/logs/Tank_Pump_Run_Stats","appendNewline":true,"createDir":true,"overwriteFile":"false","x":790,"y":680,"wires":[[]]},{"id":"65ccc534.c0a94c","type":"ui_template","z":"10b98a0a.175376","group":"c4fb7801.2972a8","name":"Water Tank Pump Status","order":0,"width":"10","height":"5","format":"<style>\n\n    #tex1 {\n        font-weight:bolder;\n        font-size: 12;\n        letter-spacing: 4px;\n        fill: white;\n    }\n    \n</style>\n\n\n<svg height=\"300\" width=\"400\" >\n\n<text id=\"tex1\" x=\"10\" y=\"30\" > {{msg.payload[0]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"50\" > {{msg.payload[1]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"70\" > {{msg.payload[2]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"90\" > {{msg.payload[3]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"110\" > {{msg.payload[4]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"130\" > {{msg.payload[5]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"150\" > {{msg.payload[6]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"170\" > {{msg.payload[7]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"190\" > {{msg.payload[8]}} </text>\n<text id=\"tex1\" x=\"10\" y=\"210\" > {{msg.payload[9]}} </text>\n</svg>\n\n","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":1070,"y":720,"wires":[[]]},{"id":"7c1b9286.bb8fdc","type":"function","z":"10b98a0a.175376","name":"Add word to scrolling table","func":"let pay = msg.payload;\n\n// Read scrolling table from context\nlet sctab = flow.get(\"sctab\");\n\n// Modify scrolling table by adding msg.payload as first element\nlet size = sctab.unshift(pay);\n\n// Remove last element from scrolling table\nif (size >9) sctab.pop();\n\n// Update context for scrolling text\nflow.set(\"sctab\",sctab);\n\n// Shalow copy updated scrolling table to msg.payload\nmsg.payload = [...sctab];\n\nreturn msg;","outputs":1,"noerr":0,"x":820,"y":720,"wires":[["65ccc534.c0a94c"]]},{"id":"df59820b.7cf47","type":"ui_text","z":"10b98a0a.175376","group":"c4fb7801.2972a8","order":1,"width":"1","height":"1","name":"Water Tank Pump Running Status","label":"","format":"{{msg.payload}}","layout":"row-center","x":840,"y":780,"wires":[]},{"id":"12741692.106189","type":"rbe","z":"10b98a0a.175376","name":"Filter out Minute Status updates from Tasmota","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":520,"y":620,"wires":[["7e84a9c8.9bf858"]]},{"id":"ee495ae9.36c048","type":"mqtt-broker","z":"","name":"New-HA-Live","broker":"172.16.100.31","port":"1883","clientid":"Live-VM","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"c4fb7801.2972a8","type":"ui_group","z":"","name":"Status Messages","tab":"7ded32a1.cf8ccc","order":2,"disp":true,"width":"10","collapse":false},{"id":"7ded32a1.cf8ccc","type":"ui_tab","z":"","name":"Water Tank","icon":"","order":2}]

Craig

Hi Craig, is there a reason why the text's white?

Nope not at all - probably because i use the dark theme?

Craig

Ah, makes sense. Think that solved my issue on making the log, thank you so much!!

No worries - i note there are a couple of trivial errors thrown in the Function node in the javascript code - you could probably clean it up and get rid of them with a little bit of playing.

Craig

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