Capture snapshot data for UI table

I have been struggling with this UI table for a while

I have a sensor running. I would like to create a snapshot of the data (time and temperature) when a certain event is happening so I can store it in my UI table for later use.

I can press the button once and receive the data of one moment. But I need to add a different row per click instead of overwriting the previous data collection.

Could someone help me with adding new rows with new data everytime I hit a button?

image

[{"id":"547d6e73f83a51b5","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"64b4d7283483e209","type":"function","z":"547d6e73f83a51b5","name":"update or add to table","func":"\nvar temperature = msg.temperature;\nvar id = Number(msg.id);\nvar time = msg.time\n\nmsg.payload={\n    command:\"updateOrAddData\",\n    arguments: [\n        [\n            {\n            \"id\": id,\n            \"temperature\": temperature,\n            \"time\": msg.time \n            }\n        ]\n    ],\n    returnPromise: true\n}\n\n\n\n\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1380,"y":1160,"wires":[["5ca6d5339f79fea9"]]},{"id":"5ca6d5339f79fea9","type":"ui_table","z":"547d6e73f83a51b5","group":"519d07fc52813146","name":"","order":1,"width":"0","height":"0","columns":[{"field":"id","title":"Fraction","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"temperature","title":"Temperature ℃","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"time","title":"Time","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":1590,"y":1160,"wires":[["4d58a5ca6b17999c"]]},{"id":"fca94b0ed091a778","type":"change","z":"547d6e73f83a51b5","name":"Change node","rules":[{"t":"set","p":"temperature","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"id","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":1160,"wires":[["61758af6e2ec595d"]]},{"id":"342761b3b6e758d3","type":"change","z":"547d6e73f83a51b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1920,"y":1160,"wires":[[]]},{"id":"4d58a5ca6b17999c","type":"switch","z":"547d6e73f83a51b5","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"id","vt":"str"},{"t":"eq","v":"temperature","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1730,"y":1160,"wires":[["342761b3b6e758d3"],["342761b3b6e758d3"]]},{"id":"2a35ee1ff4528f5d","type":"sensor-ds18b20","z":"547d6e73f83a51b5","name":"Temperature sensor","topic":"","sensorid":"28-00000003f09c","timer":"1","repeat":false,"x":360,"y":1160,"wires":[["fca94b0ed091a778"]]},{"id":"d724c08838cc9435","type":"inject","z":"547d6e73f83a51b5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":140,"y":1140,"wires":[["2a35ee1ff4528f5d"]]},{"id":"aba6362d429af909","type":"debug","z":"547d6e73f83a51b5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2190,"y":600,"wires":[]},{"id":"26298d72780fc2c2","type":"string","z":"547d6e73f83a51b5","name":"","methods":[{"name":"toInteger","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2110,"y":1160,"wires":[[]]},{"id":"61758af6e2ec595d","type":"moment","z":"547d6e73f83a51b5","name":"Add time and date","topic":"","input":"","inputType":"date","inTz":"ETC/GMT","adjAmount":"2","adjType":"hours","adjDir":"add","format":"","locale":"nl_NL","output":"time","outputType":"msg","outTz":"Europe/Amsterdam","x":770,"y":1160,"wires":[["d2f7a7bdef458d4f"]]},{"id":"d2f7a7bdef458d4f","type":"function","z":"547d6e73f83a51b5","name":"add time and temperature to payload object","func":"msg.payload = {\n \"temperature\": Number(msg.payload),\n \"time\": msg.time \n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1070,"y":1160,"wires":[["64b4d7283483e209"]]},{"id":"e9a8b2eaf9ca9133","type":"ui_button","z":"547d6e73f83a51b5","name":"Data snapshot","group":"519d07fc52813146","order":29,"width":0,"height":0,"passthru":false,"label":"Data snapshot","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":190,"y":1240,"wires":[["2a35ee1ff4528f5d"]]},{"id":"519d07fc52813146","type":"ui_group","name":"Reageerbuis","tab":"8b21002.03afe","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"8b21002.03afe","type":"ui_tab","name":"Autosampler","icon":"dashboard","disabled":false,"hidden":false}]

Perhaps you can get some insights how the row index works in this post and the complete thread

I’m traveling so I can’t look into your flow soon. So you might provide a incremental index in your case (a timestamp for example) and declare this column as index. You can even hide this column if it isn’t useful to display

1 Like

Thank-You for your reply

How?

Additional data:

"Add time and date" function node:
image

msg.payload = {
 "temperature": Number(msg.payload),
 "time": msg.time 
};

return msg;

"update or add to table" function node:

image


var temperature = msg.temperature;
var id = Number(msg.id);
var time = msg.time

msg.payload={
    command:"updateOrAddData",
    arguments: [
        [
            {
            "id": id,
            "temperature": temperature,
            "time": msg.time 
            }
        ]
    ],
    returnPromise: true
}

return msg;

I got it! It worked!

Thank you so much for the solution!

Every click gives a new row with updated data (the snapshot)

[{"id":"547d6e73f83a51b5","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"aba6362d429af909","type":"debug","z":"547d6e73f83a51b5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":2190,"y":600,"wires":[]},{"id":"26298d72780fc2c2","type":"string","z":"547d6e73f83a51b5","name":"","methods":[{"name":"toInteger","params":[]}],"prop":"payload","propout":"payload","object":"msg","objectout":"msg","x":2110,"y":1160,"wires":[[]]},{"id":"583f6ec5db50e77b","type":"function","z":"547d6e73f83a51b5","name":"update or add to table","func":"\nvar temperature = msg.temperature;\nvar id = Number(msg.id);\nvar time = msg.time\n\nmsg.payload={\n    command:\"updateOrAddData\",\n    arguments: [\n        [\n            {\n            \"id\": id,\n            \"temperature\": temperature,\n            \"time\": msg.time \n            }\n        ]\n    ],\n    returnPromise: true\n}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1340,"y":880,"wires":[["9daf0e8a85fc6d47"]]},{"id":"9daf0e8a85fc6d47","type":"ui_table","z":"547d6e73f83a51b5","group":"519d07fc52813146","name":"","order":1,"width":"0","height":"0","columns":[{"field":"id","title":"Fraction","width":"","align":"left","formatter":"rownum","formatterParams":{"target":"_blank"}},{"field":"temperature","title":"Temperature ℃","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}},{"field":"time","title":"Time","width":"","align":"left","formatter":"plaintext","formatterParams":{"target":"_blank"}}],"outputs":1,"cts":true,"x":1550,"y":880,"wires":[["c273fd389cfbac56"]]},{"id":"6594d49db96f7393","type":"change","z":"547d6e73f83a51b5","name":"Change node","rules":[{"t":"set","p":"temperature","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":520,"y":880,"wires":[["cdf6bd88fa16f2cb"]]},{"id":"73637215f28cd63d","type":"change","z":"547d6e73f83a51b5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.temperature","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1880,"y":880,"wires":[[]]},{"id":"c273fd389cfbac56","type":"switch","z":"547d6e73f83a51b5","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"id","vt":"str"},{"t":"eq","v":"temperature","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1690,"y":880,"wires":[["73637215f28cd63d"],["73637215f28cd63d"]]},{"id":"238041217d8b935b","type":"sensor-ds18b20","z":"547d6e73f83a51b5","name":"Temperature sensor","topic":"","sensorid":"28-00000003f09c","timer":"1","repeat":false,"x":320,"y":880,"wires":[["6594d49db96f7393"]]},{"id":"85730631555de577","type":"inject","z":"547d6e73f83a51b5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":120,"y":860,"wires":[["238041217d8b935b"]]},{"id":"cdf6bd88fa16f2cb","type":"moment","z":"547d6e73f83a51b5","name":"Add time and date","topic":"","input":"","inputType":"date","inTz":"ETC/GMT","adjAmount":"2","adjType":"hours","adjDir":"add","format":"","locale":"nl_NL","output":"time","outputType":"msg","outTz":"Europe/Amsterdam","x":730,"y":880,"wires":[["699698564b877d19"]]},{"id":"699698564b877d19","type":"function","z":"547d6e73f83a51b5","name":"add time and temperature to payload object","func":"msg.payload = {\n \"temperature\": Number(msg.payload),\n \"time\": msg.time \n};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1030,"y":880,"wires":[["583f6ec5db50e77b"]]},{"id":"ab4a342a10320cdb","type":"ui_button","z":"547d6e73f83a51b5","name":"Data snapshot","group":"519d07fc52813146","order":29,"width":0,"height":0,"passthru":false,"label":"Data snapshot","tooltip":"","color":"","bgcolor":"","className":"","icon":"","payload":"","payloadType":"str","topic":"topic","topicType":"msg","x":100,"y":900,"wires":[["238041217d8b935b"]]},{"id":"519d07fc52813146","type":"ui_group","name":"Reageerbuis","tab":"8b21002.03afe","order":1,"disp":true,"width":"12","collapse":false,"className":""},{"id":"8b21002.03afe","type":"ui_tab","name":"Autosampler","icon":"dashboard","disabled":false,"hidden":false}]
1 Like

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