# CSV Date Filename and Daily Email

**URL:** <https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498>\
**Category:** General\
**Created:** [1 February 2019 21:49 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498 "2019-02-01T21:49:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![randolfwenhold](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@randolfwenhold](https://discourse.nodered.org/u/randolfwenhold)\
**Post date:** [1 February 2019 21:49 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/1 "2019-02-01T21:49:13Z")

</div>

LHi there,

I would like to create a new CSV every day with logged data from a Modbus enabled Energy meter. The Meter is being read via Modbus in a simple Python script that I am running with the exec node. I would like the CSV filename to be fashioned as the Date YYYYMMDD.  
Another post explained a method to do this in Windows, but I am running Nodered on a Raspberry Pi and have not completely wrapped my head around the filename concepts.  
At the end of the day, or the next morning I would like the CSV emailed to me.

My flow also makes use of the Dashboard with 5 Gauges that I have created by splitting my payload from my Python data.

My flow is currently looking like this: `[{"id":"4512a63.38d6058","type":"tab","label":"AVO","disabled":false,"info":""},{"id":"ba7f860b.9a95a8","type":"inject","z":"4512a63.38d6058","name":"","topic":"","payload":"","payloadType":"date","repeat":"1.5","crontab":"","once":false,"x":150,"y":131,"wires":[["cf7280e1.6d75c"]]},{"id":"cf7280e1.6d75c","type":"exec","z":"4512a63.38d6058","command":"sudo python /home/pi/AVPS.py","addpay":true,"append":"","useSpawn":"true","timer":"2","oldrc":false,"name":"Run AVPS","x":318,"y":142.5,"wires":[["957e04fb.d7e0c8"],[],[]]},{"id":"957e04fb.d7e0c8","type":"function","z":"4512a63.38d6058","name":"","func":" msg.payload = msg.payload.split(\",\");\n msg.volts = parseFloat(msg.payload[15]).toFixed(2);\n msg.amps = parseFloat(msg.payload[2]).toFixed(2);\n [msg.ws](http://msg.ws/) = parseFloat(msg.payload[30]).toFixed(2);\n msg.vas = parseFloat(msg.payload[35]).toFixed(2);\n msg.zmag = parseFloat(msg.volts/msg.amps).toFixed(2);\n return msg;","outputs":2,"noerr":0,"x":322.5,"y":275,"wires":[["4cecbac5.973ce4","2626f3cc.123f7c","7af5a54c.a547ac","50b3ca17.aaf164","c19599ee.aa04e8","785014d9.2ca04c"],[]]},{"id":"c19599ee.aa04e8","type":"ui_gauge","z":"4512a63.38d6058","name":"Voltage","group":"b010d8d2.a37aa8","order":1,"width":"3","height":"3","gtype":"gage","title":"Voltage","label":"Volts","format":"{{msg.volts}}","min":"210","max":"260","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":751.5,"y":184,"wires":[]},{"id":"4cecbac5.973ce4","type":"ui_gauge","z":"4512a63.38d6058","name":"Current","group":"b010d8d2.a37aa8","order":2,"width":"3","height":"3","gtype":"gage","title":"Current","label":"Amps","format":"{{msg.amps}}","min":"0","max":"63","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":753,"y":241,"wires":[]},{"id":"2626f3cc.123f7c","type":"ui_gauge","z":"4512a63.38d6058","name":"Active Power","group":"b010d8d2.a37aa8","order":3,"width":"3","height":"3","gtype":"gage","title":"Active Power","label":"kW","format":"{{[msg.ws](http://msg.ws/)}}","min":"0","max":"15","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":747,"y":284,"wires":[]},{"id":"7af5a54c.a547ac","type":"ui_gauge","z":"4512a63.38d6058","name":"Apparent Power","group":"b010d8d2.a37aa8","order":4,"width":"3","height":"3","gtype":"gage","title":"Apparent Power","label":"kVA","format":"{{msg.vas}}","min":"0","max":"15","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":753,"y":348,"wires":[]},{"id":"50b3ca17.aaf164","type":"ui_gauge","z":"4512a63.38d6058","name":"Magnitude of Impedance","group":"b010d8d2.a37aa8","order":4,"width":"3","height":"3","gtype":"gage","title":"Mag. of Impedance","label":"Ohm","format":"{{msg.zmag}}","min":"0","max":"1000","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":783.0234375,"y":404.0390625,"wires":[]},{"id":"785014d9.2ca04c","type":"csv","z":"4512a63.38d6058","name":"","sep":",","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"","skip":"0","x":480,"y":460,"wires":[["ba24c63f.85c618"]]},{"id":"ba24c63f.85c618","type":"file","z":"4512a63.38d6058","name":"","filename":"/home/pi/logfile.csv","appendNewline":false,"createDir":true,"overwriteFile":"false","x":680,"y":480,"wires":[["43b98db3.b12884"]]},{"id":"43b98db3.b12884","type":"e-mail","z":"4512a63.38d6058","server":"[smtp.gmail.com](http://smtp.gmail.com/)","port":"465","secure":true,"name":"[xxxxxxxxx@gmail.com](mailto:xxxxxxxxx@gmail.com)","dname":"","x":830,"y":540,"wires":[]},{"id":"b010d8d2.a37aa8","type":"ui_group","z":"","name":"Wenhold Huis","tab":"4641da8d.b22a64","disp":true,"width":"15","collapse":false},{"id":"4641da8d.b22a64","type":"ui_tab","z":"","name":"Wenhold Huis Dashboard","icon":"dashboard"}]`

I have removed my password from the email node.  
At the moment it is sending me an email with the string every time the csv is appended.  
I would like the Data to be collected into a CSV with the Date as a filename and then emailed to me at the end of the day.  
On the next day a new CSV needs to be created.

I will really appreciate any assistance.

Kind Regards  
Randolf Wenhold

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [2 February 2019 08:31 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/2 "2019-02-02T08:31:36Z")

</div>

so which bit are you stuck on?

Writing the file with the days date?  
Or sending it once a day?

The file-out node can take a filename (msg.filename) and as part of the message so you can easily write the data to the correct file.

Then in a separate flow just after midnight you can select the previous days file and attach that to an email (instructions in the Email nodes info panel)

---

<div class="post-metadata">

**Author:** ![randolfwenhold](https://avatars.discourse-cdn.com/v4/letter/r/7bcc69/32.png) [@randolfwenhold](https://discourse.nodered.org/u/randolfwenhold)\
**Post date:** [2 February 2019 16:49 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/3 "2019-02-02T16:49:35Z")

</div>

Thanks a million ukmoose, you guided me into the right direction with the filename.  
I have managed to get the file created with the date as the filename and have tested it by temporarily setting the filename as the hour/minute and have found that it creates a new file every time the minute or hour has passed.

What I am now stuck on is getting my flow to email me the finished CSV once a new one is created.  
I believe it can be done by performing a function that checks if the next CSV has been created yet and then subtracting one from the date, selecting the file and attaching that to an email.

You mention "in a seperate flow just after midnight you can select the previous days file"  
Can you please assist in guiding me how I can go about achieving this?

Kind Regards,  
Randolf Wenhold

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [2 February 2019 17:18 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/4 "2019-02-02T17:18:56Z")

</div>

i’m on a train so the terms might not be totally right

personally I would do it in a separate flow.

If you set an inject node to repeat daily (personally at 00:05)  
have a function that works out yesterday’s date to create file name to send) as it’s yesterday the file has to be complete. From memory I think the email node accepts full paths to a file within the attachment

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [2 February 2019 17:24 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/5 "2019-02-02T17:24:15Z")

</div>

Or save the filename in context at (say 23:55) - then use it as you suggest at 00:05.

---

<div class="post-metadata">

**Author:** ![ismetbalci](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ismetbalci/32/16858_2.png) [@ismetbalci](https://discourse.nodered.org/u/ismetbalci)\
**Post date:** [8 February 2020 07:51 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/6 "2020-02-08T07:51:40Z")

</div>

Hello,  
Could you share your example ? I also need to make a new csv at the end of the day and I have to send it ftp server.

---

<div class="post-metadata">

**Author:** ![Georg25](https://avatars.discourse-cdn.com/v4/letter/g/ed8c4c/32.png) [@Georg25](https://discourse.nodered.org/u/Georg25)\
**Post date:** [23 March 2021 10:31 UTC](https://discourse.nodered.org/t/csv-date-filename-and-daily-email/7498/7 "2021-03-23T10:31:10Z")

</div>

it would be nice, if you can share your example. I have quit the same application.

Thanks 🙂
