Save information to file out with date/time for each information

Hello I have a problem I would like some help for.
I have made a flow where when I click on a button it saves the information which my payload gets in a file out. It works perfect except I want it to show date/time for each saved value which in this case is numbers.

example. I click on the button and it saves the number 75. Then instead of just showing 75 in my .txt file I would like it to show 75 08:15 27-09-2019. Just an example. Anyone have any idea how to do that?

I use the node-red-contrib-simpletime for stuff like this to access date info

There are many ways of then adding it in - this is one of the simplest using a template node

[{"id":"4ca03207.2a6e3c","type":"simpletime","z":"4baaf825.5aebd8","name":"","x":440,"y":220,"wires":[["5a62895e.c67b68"]]},{"id":"c444ee44.5e003","type":"inject","z":"4baaf825.5aebd8","name":"","topic":"","payload":"75","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":292,"y":220,"wires":[["4ca03207.2a6e3c"]]},{"id":"5a62895e.c67b68","type":"template","z":"4baaf825.5aebd8","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"{{payload}} {{mydate}}","output":"str","x":588,"y":220,"wires":[["2ac473f.63ada8c"]]},{"id":"2ac473f.63ada8c","type":"debug","z":"4baaf825.5aebd8","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":752,"y":220,"wires":[]}]

image

image

1 Like

As always, NR gives you lots of ways to do things. Possibly the most simple, using only core nodes, would be something like this.

[{"id":"c4310b2a.540fb8","type":"inject","z":"bef81aa8.c22888","name":"","topic":"","payload":"75","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":120,"wires":[["e656e38f.c43398"]]},{"id":"e656e38f.c43398","type":"change","z":"bef81aa8.c22888","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload & ' ' & $now()","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":120,"wires":[["43cb85be.b7a08c"]]},{"id":"43cb85be.b7a08c","type":"debug","z":"bef81aa8.c22888","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":470,"y":120,"wires":[]}]

If you are not happy with the date format given by the JSONata $now function, you will have to do a bit more work.

I daresay it sounds like you are moving toward generating either entries in a spreadsheet, or better yet records in a database. The possibilities of post-processing and querying the data later will be much better with either of these persistence tools, as compared to a text file.

If you are interested in learning about either of those solutions, there are lots posts on the forum with examples -- and if you get stuck, lots of members in this community that can help. Have fun!