Export Data to file

Hi,

I don’t know if this is the right category, but I’ll try. I’m new to HA. I would like to write the min/max temperature data to a file once a day so that I can further process this data with Excel or other programs. Find but with the “-platform: file” not the right approach. Can someone from the community help me here?

Greetings from Hamburg

Hi, the following is my automation that writes daily and monthly electricity usage to a CSV file, I think you should be able to adapt this to do what you require:

- id: '1630175809373'
  alias: Daily Energy Usage
  description: ''
  trigger:
  - platform: time
    at: 00:01:00
  condition: []
  action:
  - service: notify.energy_log
    data:
      message: '{{ states(''sensor.date_time'') }};Daily;{{ state_attr(''sensor.energy_usage_day_std'',
        ''last_period'') }};{{ states(''sensor.energy_cost_last_day_std'') }};{{ state_attr(''sensor.energy_usage_day_offpeak'',
        ''last_period'') }};{{ states(''sensor.energy_cost_last_day_offpeak'') }}'
  - condition: template
    value_template: '{{ now().day == 1 }}'
  - service: notify.energy_log
    data:
      message: '{{ states(''sensor.date_time'') }};Monthly;{{ state_attr(''sensor.energy_usage_month_std'',
        ''last_period'') }};{{ states(''sensor.energy_cost_last_month_std'') }};{{
        state_attr(''sensor.energy_usage_month_offpeak'', ''last_period'') }};{{ states(''sensor.energy_cost_last_month_offpeak'')
        }}'
  mode: single

The following is the associated notifier code from notify.yaml:

- name: energy_log
  platform: file
  filename: /config/www/csv_logs/energy_log.csv
  timestamp: false
1 Like

Hi Jonah1970,

Thank you, I will test and report tonight.

Regards Frank

Hi Jonah1970,

Due to lack of time it took me longer to implement it, but now it works. Many thanks for the help.

Greetings from Hamburg

For some reason it is not working like that for me.

I don’t have a separate file that is called notify.yaml, but I added the code in the configuration.yaml under the point notify:, which should be the same.

It works if I use - service: notify.filenotify but not if I name it different like in the example above - service: notify.energy_log.

In more detail:

What works:
In the configuration.yaml:

notify:
  - platform: file
    name: filenotify
    filename: /config/temp_hum.csv
    timestamp: false

Automation:

trigger:
  - platform: time_pattern
    minutes: /10
action:
  - service: notify.filenotify
    data_template:
      message: >-
        ...

What not works:
In the configuration.yaml:

notify:
  - name: energy_log
    platform: file
    filename: /energy_log.csv
    timestamp: false

Automation:

trigger:
  - platform: time_pattern
    minutes: /10
condition: []
action:
  - service: notify.energy_log
    data:
      message: >-
        ...

What also not works:
In the configuration.yaml:

notify:
  - platform: file
    name: energy_log_2
    filename: /config/energy_log2.csv
    timestamp: false

Automation:

trigger:
  - platform: time_pattern
    minutes: /10
condition: []
action:
  - service: notify.energy_log_2
    data:
      message: >-
        ...

Edit:
I did the newest HomeAssistant Update, and now it seems to work perfectly. I don’t know if the upgrade was helping. I did always a real reastart of the system before, but well. Now it works!^^

So you can use the code above for different ways for ideas how to get the same results working :wink:

Hello… I am trying to do something similar but don’t know how…

I want to daily generate a file with the reading of the moment state of some sensors… How I do that?