KoljaWindeler / kaco

custom integration for kaco solar inverter
15 stars 8 forks source link

Error adding entities for domain sensor with platform kaco #7

Open iliyankxyz opened 2 years ago

iliyankxyz commented 2 years ago

Version of the custom_component

I am using the latest version pulled by Home Asisstant from git i.e. version d498e4d

Configuration


sensor:
  - platform: kaco
    name: Solar Power 1
    url: 192.168.0.50

sensor:
  - platform: kaco
    name: Solar Power 2
    url: 192.168.0.51

Describe the bug

When I try to add one of my Kaco inverters I am getting success, but no sensors appear and lot's of errors are logged. This error happens only with one and the same inverter 'Solar South' Solar Power 1. Both inverters are blueplanet 5.0 TL3 SW version 5.53

Debug log


2022-02-15 15:20:41 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.kaco
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor] Config via Storage/UI
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco] initialize the date coordinator for IP 192.168.0.50
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor] KACO config: 
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor]  name: Inverter South
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor]  url: 192.168.0.50
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor]  icon: mdi:solar-power
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor] KACO config: 
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor]  name: Inverter South
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor]  url: 192.168.0.50
2022-02-15 15:20:41 DEBUG (MainThread) [custom_components.kaco.sensor]  icon: mdi:solar-power
2022-02-15 15:20:41 ERROR (MainThread) [homeassistant.components.sensor] Error adding entities for domain sensor with platform kaco
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 442, in _async_add_entity
    if entity.unique_id is not None:
  File "/config/custom_components/kaco/sensor.py", line 91, in unique_id
    return self.coordinator.data["extra"]["serialno"] + self._valueKey
TypeError: 'NoneType' object is not subscriptable
2022-02-15 15:20:41 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up kaco platform for sensor
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 257, in _async_setup_platform
    await asyncio.gather(*pending)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 442, in _async_add_entity
    if entity.unique_id is not None:
  File "/config/custom_components/kaco/sensor.py", line 91, in unique_id
    return self.coordinator.data["extra"]["serialno"] + self._valueKey
TypeError: 'NoneType' object is not subscriptable
kcinnaySte commented 2 years ago

Hey kozarev, sorry for the delay. It seams that the inverter does not answer with the serial number. Would you please send the content of the CSV-File from the Inverter.

You'll get it from: http://<ipOfYourInterter>/<Year(4 digits)><Month(2 digits)><Day (2 digits).csv> For Example: http://192.168.0.51/20220301.csv

On my blueplanet 20.0 TL3 there is still no error.

kcinnaySte commented 2 years ago

I created an new pull-request (#8 ), with better logging. Maybe it es helpful to update to this version, and repost the logs. It seems to be an error, that the initialization of the coordinator took less than one second.

KoljaWindeler commented 2 years ago

Merged

iliyankxyz commented 2 years ago

Hi,

I am sending the CSVs from both of my inverters. I can see the inverter SN in both files. I will pull the new version and repost the logs in the upcoming days.

solar1_50.csv solar1_51.csv

iliyankxyz commented 2 years ago

Hello, I am adding also home assistant logs from installation of inverter sensors. Naming and IPs are not changed.

home-assistant.zip

kcinnaySte commented 2 years ago

Hmm there are some parts that are confusing me. First: There is no carriage return inside the csv file. This may courses the error, because we split the line and select only the second, but, Second: The exception says, that you run in an timeout (10secs) from the request, and not an Error while parsing the answer.

2022-03-02 21:58:36 WARNING (MainThread) [custom_components.kaco] KACO Panel with IP 192.168.0.51 doesn't answer
2022-03-02 21:58:36 ERROR (MainThread) [custom_components.kaco] Timeout fetching kaco_192.168.0.51 data

So maybe we have an encoding problem, based on different languages (German in my case), or we have an timeout problem, maybe because your inverter is a little bit slower.

If you are familiar with python, you are possible to request and parse the values with the following snippet:

import requests

answer = requests.get("http://192.168.0.50/20220306.csv", timeout=10)
print("Encoding: ", answer.encoding)
d = answer.content.decode("ISO-8859-1")
print("Content: ", d)
ds = d.split('\r')
print("Lines: ",len(ds))
dss = ds[1].split(";")
print("Serialnumber-Line: ", dss)
print("Serialnumber: ", dss[1])

Here you have to change the date in the URL to the current date.

The alternative is to raise the timeout, directly in the plugin. Therefore change to your homeassistant config-dir and open the file: ./custom_components/kaco/__init__.py In line 112 change the timeout= to an bigger value (time is given in seconds) And in line 152 also change the timeout= to an bigger value.

The first is the Timeout to get the current power (Watts). The second Timeout is to get the device-config and the daily produced energy.

After the change, an restart of homeassistant is neccesary.

I'm sorry that I don't have more information at this point. If you solved the problem with bigger timeouts, or you have some other information, please let me know

iliyankxyz commented 2 years ago

Hi,

Sorry for the late response, busy days...

I have managed to resolved the issue by increasing the timeouts. On both places that you suggested I increased timeouts to 60 seconds - it worked from the first time. I did the update last night so for the upcoming days will observe how it works.

In general I think that timeouts were too optimistic especially the 2 seconds one. Will keep you updated.

Iliyan

jonasf21 commented 2 years ago

Hello,

i've had similar issues - i got the same error about the serialno. That was because i tried it at night (to be precise: after 00:00). Due to that there is no current .csv available on the inverter - this is only generated in the morning when it first gets some voltage on the DC side. As that i might be worth having a fallback and query the past day's data (to get the SN).

After "fixing" this (resting for the night) i stepped into the timeout issue which is solved by changing the 2s to 5s. My device is a older generation Kaco Powador 10.0TL3, which might be even slower than the newer blueplanet series.

jonasf21 commented 2 years ago

Just a heads-up for this issue: I have stopped using this addon as i was getting too many misreads from my inverter (Powador 10.0 TL3) - this is likely due to the crappy hardware/webserver on it. Also the nightly issue with unreadable csv (starting 0:01) was annoying (no offense to the author of the addon). Since then i switched to using modbus to do exactly what this plugin does (enabled modbus on the inverter via webinterface). Now i can read the values without problems (no misreads/timeouts ever) - even at night/early morning. Maybe the author of this plugin could change to modbus, too (or add a toggle to use either http or modbus) - that would be great. Here's how i read actual generated power via modbus: (the other modbus addresses for values like string voltage, current etc can be found on the kaco modbus datasheet)

modbus:

kcinnaySte commented 2 years ago

Just a heads-up for this issue: I have stopped using this addon as i was getting too many misreads from my inverter (Powador 10.0 TL3) - this is likely due to the crappy hardware/webserver on it. Also the nightly issue with unreadable csv (starting 0:01) was annoying (no offense to the author of the addon). Since then i switched to using modbus to do exactly what this plugin does (enabled modbus on the inverter via webinterface). Now i can read the values without problems (no misreads/timeouts ever) - even at night/early morning. Maybe the author of this plugin could change to modbus, too (or add a toggle to use either http or modbus) - that would be great. Here's how i read actual generated power via modbus:

(the other modbus addresses for values like string voltage, current etc can be found on the kaco modbus datasheet)

modbus:

  • name: Kaco-WR

    type: tcp

    host: 192.168.0.192

    port: 502

    close_comm_on_error: true

    retry_on_empty: true

    retries: 10

    timeout: 9

    sensors:

    - name: Kaco.Power
    
      device_class: power
    
      unit_of_measurement: W
    
      state_class: measurement
    
      address: 40144
    
      slave: 1
    
      data_type: float32

You are right, that probably would be the best. I will take a look for it, but it takes 2-3weeks, I am quiet busy actually.

kcinnaySte commented 2 years ago

@jonasf21 I checked the implementation of the modbus, that is using the "SunSpec" specification.

Here we already have an very good plugin: https://github.com/cjne/ha-sunspec

I recommend to change to this plugin. I would not implement the modbus if there is still an working solution.

ggajoch commented 2 years ago

I just had very similar issue - integration could not start, with error that value self.coordinator.data["extra"]["serialno"] is None. I've found that if integration is restarted during night (but after date change) it'll ask for CSV with actual date, but Kaco will not provide this file until some power generation happens.

When I restarted HA during day, everything worked fine.

danriedl commented 1 year ago

I have to restart a managed home-assistant instance sometimes at night, when the ISP changes the IP. As this happens always at night (~03:00:00), the Kaco integration fails to init because of this.

Somehow this line here seems relevant: https://github.com/KoljaWindeler/kaco/blob/master/custom_components/kaco/__init__.py#L166-L167

# TODO Lokal speichern da UID
values["extra"]["serialno"] = dss[1]

The TODO says: Save locally since UID

Seems like this was already planned (or thought about) by @kcinnaySte : https://github.com/KoljaWindeler/kaco/commit/5d051982539d48cc83c02ed6cd032eb26668b1c1#diff-69c9e73b9fddd2cebf261b0103207877848d34f47da73763fe33ca11fc7a5d15R152

Right now i use this automation to solve the problem temporarily:

alias: Sunrise with KACO unavailable
description: "When the sun rises and the Kaco integration can't fetch the serial number as a result of HA restart at night, we restart homeassistant core"
trigger:
  - platform: sun
    event: sunrise
    offset: 0
condition:
  - condition: state
    entity_id: sensor.solar_power_current_power
    state: unavailable
action:
  - service: homeassistant.restart
    data: {}
mode: single
kcinnaySte commented 1 year ago

Hi,

that is correct, it would be the best to save the serial number/uid. But also then, you have an problem if you want to add an new inverter before the sunrise. Also the kaco webserver has sometimes a problem, that he got an timeout.

I would recommend to activate modbus at the inverter, and use these plugin: https://github.com/cjne/ha-sunspec

It is much more stable. I only use this plugin, and therefore wouldn't change something in this repo.