Export sensor data to text file

Probably because of the time zone you’re in. Home Assistant uses UTC internally. So, you might want to compensate for that.

I use a HA 0.115.4 installation on RasPi 4 and I am new at Home Assistant.

For later use in MS-Excel I do an export of sensor data to csv-File. To do this, I configured file notification and automation as described in this thread. My continuous export with an interval of 10 minutes works fine.

My problem is, that all data is written into one file I configured with file notification:

notify:
- platform: file
    name: filenotify
    filename: temp.csv

I better would do the export on a daily base. That means, I would like to have one file per day.
How could I achieve this? Can I use current date in combination with filename? So the file notification service would create a new file at every new day. Something like:
filename: {{now().strftime("%Y%m%d")_temp.csv

Hi
2 questions if I may.

  1. did you find a solution regarding the new file each day?
  2. did you notice any misbehavior to HA (eg slower) if the automation is running all the time?

Hi,
I am using this automation too, and I have the same problem with time (it is off 3 hours)
The time zone in home assistant is correct (configuration-general). Is there a way to fix this or I just should “know” and correct it in the excel file?

Hi Makis,

Your questions:
1.
No, I did not find a solution for a new file every new day. I am a newbie on home assistant and the HA documentation was not very helpful.
Currently I use a workaround by help of an Excel Makro. It reads the csv-file from a samba share and extracts the data of the day I need. My csv-file is not growing very rapidly (~300kB/week), but of cause I will have to shrink it manually from time to time.
2.
I do not see any side effects or a slow down of HA on my RasPi 4.
Screenshot
3.
Time Stamps are correct in my csv-file. Don’t ask me why, I did not configure anything for it!

1 Like

configuration.yamal file .no mistake on chek but no any records in file.csv

Any help what is wrong ??

notify:

  • platform: file
    name: filenotify
    filename: /config/history/file.csv
    #timestamp: true
    automation:
    • alias: sensor_values_to_file
      initial_state: ‘on’
      trigger:
      • platform: time
        minutes: ‘/1’
        seconds: 00
        action:
      • service: notify.filenotify
        data_template:
        message: “{{states.sensor.dnevna_proizvodnja.state}}”

Hallo nutrabaits,

I cannot tell you whats wrong in your configuration data for csv export.
Did you split it in two parts, one for the configuration.yamal file, and the other for the automations.yamal file?
And the notation is important. You have to pay attention to exact spacing and indentation.

I will give you my configuration details here, which work fine for me. Maybe it can help you. Find differences and just try them out.

There are two config parts (one in configuration.yamal file, the other in automations.yamal file).

my part one in configuration.yamal:

# Trend Daten in Datei
notify:
  - name: filenotify
    platform: file
    filename: csvexport.txt
#    timestamp: true

It is similar to your config but I have the dash in front of name:.

my part two from automations.yamal

- id: '1601208243990'
  alias: sensor_values_to_file
  description: ''
  trigger:
  - platform: time_pattern
    minutes: /5
  condition: []
  action:
  - service: notify.filenotify
    data_template:
      message: '{{now().strftime("%d.%m.%Y")}};{{now().strftime("%H:%M:%S")}};{{ states.sensor.weather_temperature.state}}'
  mode: single

it is similar again. I have no dash in front of alias:.
Good luck,
Werner

5 Likes

Thanks Werner on your time .I setup and finally work

regards Zlatko

Werner when i opened csv file all data from sensors are written in date format? any solution to have them in number format for easy implementation in the calculation.

Snimka zaslona (47)

thanks

Are you talking about these dates?
image

no columne C ,D and E is a kwh but writing them in date format .

That is a original line from csv before i open them in excel.

14.02.2021;23:59:00;12.66;24.19;29.8

insted 29.8 number i have in columne E date format 29.kol

Right click the column header in Excel, select Format Options, and select the format you want.

image

That is no solution.Thanks .Look like HA write in date format in csv .file .

In Excell insted 29.8 write data 28.kol and when i convert to number i have 44437

What is your file notifier message?

message: <what is here?>

message: ‘{{now().strftime("%d.%m.%Y")}};{{now().strftime("%H:%M:%S")}};{{ states.sensor.daily_energy_consumption_niska_tarifa.state}};{{
states.sensor.daily_energy_consumption_visoka_tarifa.state}};{{ states.sensor.pv_production_today.state}}’

Can you copy this and paste it in your template editor, then copy the results and paste the results back here?

{{ states.sensor.daily_energy_consumption_niska_tarifa.state }}
{{ states.sensor.daily_energy_consumption_visoka_tarifa.state }}
{{ states.sensor.pv_production_today.state }}

Jason first thanks on your time .i put only your lines in message:

I need to see what the states of those entities are to see what is getting written to the file before excel formats it so I need to see the results from your template editor.

Alternatively, you can open the file in a text editor like notepad or something and just paste the last couple lines here.

The results will be where the red arrow points.

  message: '{{now().strftime("%d.%m.%Y")}};{{now().strftime("%H:%M:%S")}};{{ states.sensor.daily_energy_consumption_niska_tarifa.state}};{{
    states.sensor.daily_energy_consumption_visoka_tarifa.state}};{{ states.sensor.pv_production_today.state}}'

if i understand you only problem is double space on the end of word state? sorry i am rooke.