DarkC35 / ha_linznetz

Custom component to import LINZ NETZ quater-hour reports into Home-Assistant.
MIT License
15 stars 0 forks source link

Error when trying to import data manually #15

Closed mills1975 closed 10 months ago

mills1975 commented 10 months ago

Configuration


import_report:
  name: Import Report
  description: Import daily QH CSV reports from LINZ NETZ.
  fields:
    entity_id:
      description: The LINZ NETZ entity.
      required: true
      selector:
        entity:
          integration: linznetz
          domain: sensor
          device_class: energy
    path:
      description: The path of the CSV file.
      required: true
      selector:
        text:

## Describe the bug
When I try to import data manually, I get the error, that the report seems to be corrupted.
But the report is fine. Sometimes, when I delete entries, so that the file only contains a few days, the import
is ok. 
Unfortunately, I cannot say, how many days are working.
E.g. 15.11.23 to 30.11.23 --> import works
        01.11.23 to 14.11.23 --> import doesn't work
        01.11.23 to 05.11.23 --> import works
        06.11.23 to 14.11.23 --> import doesn't work

So far as I can say, it's not a problem with file size or so.

## Debug log

```log

2023-12-19 19:29:33.055 DEBUG (MainThread) [custom_components.linznetz] Import Report executed with path: attachments/ATxxxxxx_QH_20231101_20231130.csv
2023-12-19 19:29:33.055 DEBUG (MainThread) [custom_components.linznetz] Entity: SmartMeter Energy; Entity_ID: sensor.smartmeter_energy; Unique_ID: ATxxxxxx_energy
2023-12-19 19:29:33.060 DEBUG (MainThread) [custom_components.linznetz] <_io.TextIOWrapper name='attachments/ATxxxx_QH_20231101_20231130.csv' mode='r' encoding='UTF-8'>
2023-12-19 19:29:33.071 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Error for call_service at pos 1: Report to import seems to be corrupted. Please ensure that there are at least 4 QH values per hour.
2023-12-19 19:29:33.073 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [1711938792] Error handling message: Report to import seems to be corrupted. Please ensure that there are at least 4 QH values per hour. (unknown_error) 
DarkC35 commented 10 months ago

So I just checked the code and this error is triggered when the number of lines in your CSV file (minus the header) is not dividable by 4.

        if len(csv_data) % 4 != 0:
            raise HomeAssistantError(
                "Report to import seems to be corrupted. Please ensure that there are at least 4 QH values per hour."
            )

Could you please check if your 06.11.23 to 14.11.23 file has exactly 865 lines including the header line (Datum von;Datum bis;...) assuming it's from 06.11.2023 00:00 to 15.11.2023 00:00 like in the screenshot below: grafik

mills1975 commented 10 months ago

Hello,

Omg... there is a line missing in the original file from LinzNetz. I don't know why, but there is no line for 06.11. between 21:15 and 21:30.

Thank you very much for your help... with your help I was able to find the problem.

many greetings Andi

DarkC35 commented 10 months ago

Glad to hear that the issue could be resolved. And thank you for your report that the LinzNetz reports are not as reliable as I thought they would be. I'm running it for over a year now and luckily never run into such a problem.