Timestamp wont update


I have a couple of watch nodes to watch an excel spreadsheet that is automatically updating every hour.This part works fine, but i am also trying to grab that time, when it updates, to populate a field on the dashboard.

I want it to it grab and displays the newly updated data, and also show 'date of last update' date and time so we know its all current. this is the part that's not working. when i click the inject node manually it updates the time and date displayed, but it is not being triggered when the watch nodes trigger every hour.

any ideas why this is not working?


Why not add a change node into the flow and have it set some thing like msg.current_time to the current timestamp. Then you can use that as the update time.

I am doing this with a few different data logging flows. The easiest way I have found to do it is to use the Date/Time Formmatter node to format the date time to the way that I want it, and to move it into msg.timestamp. You can then use it whereever you want and it's formatted the way you want it too. I also use it to display "last update" on dashboard nodes by formatting to something shorter. It accepts any format you can set up in moment.


Thanks for your reply. I am very new to node-red, trying to adapt / fix work done by a colleague.
i can't get your idea to work, can you explain further?

how to assign the current time stamp to another variable?
how to format the output to read well, at the moment its just outputting a string of numbers.

Thanks for your reply. I am very new to node-red, trying to adapt / fix work done by a colleague.
i can't get your idea to work, can you explain further?

how to move it to msg.timestamp and display?

Since you are new to Node-RED, I suggest you spend an hour wathching the Node-RED Essentials YouTube videos put out by the developers, It will be worth the time to get familiar with Node-RED.

Once you have watched them, if you still have problems let me know,

Good point.

I've watched a bit so far, trying to do the simple example but the 'cost' is not joining on at the end, but its showing in the debug output if you connect it after the function node. why!? my flow below.

[{"id":"42deaea0.1a83d","type":"inject","z":"fcad3fcc.66506","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":230,"y":400,"wires":[["54755ead.d6145"]]},{"id":"54755ead.d6145","type":"template","z":"fcad3fcc.66506","name":"csv data","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Date,Quantity,Item\n2019-12-01,1,Apple\n2019-12-02,2,Orange\n2019-12-02,1,Pear\n2019-12-03,3,Banana\n2019-12-03,2,Apple\n2019-12-04,1,Pear","output":"str","x":430,"y":400,"wires":[["b6037b09.1fb758"]]},{"id":"b6037b09.1fb758","type":"csv","z":"fcad3fcc.66506","name":"","sep":",","hdrin":true,"hdrout":"all","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":620,"y":420,"wires":[["8b5b71ec.a4113"]]},{"id":"7dde0f94.4122e","type":"function","z":"fcad3fcc.66506","name":"add cost","func":"var PRICES = {\n    \"Apple\": 10,\n    \"Orange\":20,\n    \"Pear\":50,\n    \"Banana\":30\n}\n\nmsg.payload.cost = msg.payload.Quantity * PRICES[msg.payload.Item]\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":550,"y":540,"wires":[["f86311c6.d9ffc"]]},{"id":"f86311c6.d9ffc","type":"join","z":"fcad3fcc.66506","name":"","mode":"auto","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":760,"y":560,"wires":[["5f788dff.883c34"]]},{"id":"8b5b71ec.a4113","type":"split","z":"fcad3fcc.66506","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":920,"y":440,"wires":[["7dde0f94.4122e"]]},{"id":"5f788dff.883c34","type":"csv","z":"fcad3fcc.66506","name":"","sep":",","hdrin":true,"hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":950,"y":560,"wires":[["3a4ff9fe.2893e6"]]},{"id":"3a4ff9fe.2893e6","type":"debug","z":"fcad3fcc.66506","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1130,"y":560,"wires":[]}]

Ok, lets work this thru one step at a time.

First copy your 'css data template node off to the side and edit the node so you only send it one roe - this will make looking at the debug easier.

Put a debug node (set to display the 'Complete msg object') on the output of the split, the function', the joinand thecsv` nodes.

What do you notice?

Everything works up until the csv node at the end.

the debug from the output of the 'join' node is showing an output array, containing all the items, each with the 'cost' field added in. but when it goes through the next 'csv' node it outputs without the 'cost' included....

Great you have isolated the issue! Now hat does the cvs node help say about how it works?

I just looked at the 'Help' for the CSV node and I see it isn't clear (I'll offer a PR to make the explaination clearer)

When a input is a JavaScript object it tries to build a CSV string, it uses one of two things to control what the output looks like. (1) it uses the Columns property of the node
Screen Shot 2021-02-12 at 4.48.19 AM
or it uses msg.columns of the incoming msg
Screen Shot 2021-02-12 at 4.48.57 AM

Since you haven't added 'cost' to the list of columns to create, it doesn't create them.

Add this line just before the return msg line in your function and you should see it work:

msg.columns += ",cost"

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