ksheumaker / homeassistant-apsystems_ecur

Home Assistant custom component for local querying of APSystems ECU-R Solar System
Apache License 2.0
173 stars 43 forks source link

Integration broke Home Assistant 2021.8.0 #16

Closed adriaanh closed 2 years ago

adriaanh commented 3 years ago

I installed this integration via HACS and rebooted the system. After reboot, I added the following to my configuration.yaml. I have the ecu-r connected through wifi as per instruction and the secret has the ip address of the wifi connected ECU-r.

apsystems_ecur: 
  host: !secret apsystems_ecur_host

After rebooting, home assistant wouldn't start. I had to go back to a previous snapshot in order to get HA working again. No issues in the logs. Is this an issue with compatibility of home assistant?

I have the ECU-r with QS1 inverters, and connected both via WiFi and ethernet.

Thanks!

hofvanta commented 2 years ago

@adriaanh Ik heb dezelfde. Welke software versie draai je en hoe heb je hem gekoppeld (Wifi?LAN). Bij is de ECU na ongeveer 72 uur niet meer via Wifi als LAN op poort 8899 uitvraagbaar. De webinterface blijft wel gewoon werken. Ben benieuwd naar jou ervaring. Ik heb de LAN poort ingebruik, want Wifi deed voor elke update naar APS portal (5minuten) een DHCP request en na aantal keer accepteerde de DHCPOFFER niet meer, terwijl de router deze wel netjes uitstuurde herhaaldelijk omdat de ECU DHCPREQ bleef uitsturen. Ik heb hier met de APS servicedesk contact gehad, deze had het doorgestuurd intern, maar over de status kan je niet communiceren.

HAEdwin commented 2 years ago

Wow, nice finding. I've tried to solve this failing DORA once with AVM (FritzBox) for leases that were kept in memory. All they did was add a button which did not flush it after all. I gave up on that because their product is not suited for large amounts of changing DHCP clients. This could be a similar issue and does binding an IP-adress to the ECU's wireless MAC not solve the problem? The fact that it keeps on sending DHCPreq could be the issue that the router is not able to Acknowledge. So it's more likely a DHCP server issue (or router issue if that's your DHCP server). DOR is going allright, A fails. Make shure the WiFi assigned IP-address is not allready being used in your network if it is bound to the WiFi MAC.

hofvanta commented 2 years ago

I had a static DHCP binding, and ECU didnt accept to offer after a while. Static Wifi IP is not possible, only for the LAN interface on a ECU-R. The router (dhcp server) was for sure not the problem (tested with spoofing the Wifi MAC address with old Wifi dongle). SO the ECU-R now is connected by LAN, but spontaneous loose connection after 72 hours. Reason not found yet. Can be that the socket is in use and not cleared by the HA ECU integration. You cannot verify it, because Arago account is not known (Arago is the OS op en ECU-R and able to telnet to it)

HAEdwin commented 2 years ago

The sync query contains socket close and can be used to try when you modify __init__.py Replace data = await self.ecu.async_query_ecu() with data = self.ecu.query_ecu() around line 73

HAEdwin commented 2 years ago

I discovered that this function reuses the same socket to send multiple commands, so that has to be rewritten...

ksheumaker commented 2 years ago

Didn't mean to close this, but I created a new version which will add a 1 second sleep between socket close and opens to try and prevent the ECU from being overloaded when using the ECU_R_PRO. Hopefully this will help, we can try increasing the sleep time as well to see if that helps at all.

hofvanta commented 2 years ago

Cool, tx, I have it run. Will monitor from now on with ECU_R_PRO if it keeps working. Fingers crossed!

renini commented 2 years ago

@adriaanh I have the same one, from the gui this seems only like sunspec via modbus over the extra rs485 port. For me the drop down "Address" has the options for address assignments between 1-255. I think this is related to how modbus works. Can't find any modbus over tcp option in the gui, so only rs485 for now i guess. So probably the tcp/8899 is the way to go to read this locally for the time being, unless the sunspec rest option gets implemented someday...

@HAEdwin does your older ECU-R, also have an RS485 port. next to the ethernet port?

hofvanta commented 2 years ago

I can try. Then I need to buy a USB-RS485 adapter, like: https://nl.banggood.com/USB-To-RS485-Converter-Module-USB-To-TTL-or-RS485-Dual-Function-Dual-Protection-p-1311986.html?imageAb=1&akmClientCountry=America&channel=bg_affiliate&utm_source=bg_affiliate&utm_medium=aff&utm_campaign=giz1205_m_product_prdshare_copy&utm_content=CX08197269762201611W_10192&_branch_match_id=800497510816475964&akmClientCountry=NL&akmClientCountry=NL&cur_warehouse=CN And with standard HA integration, it should be possible I think https://www.home-assistant.io/integrations/modbus/

ksheumaker commented 2 years ago

Multiple changes were done in 1.1.2 to hopefully increase stability with ECU-C and ECU_R_PRO devices. Please update to the latest version and if you still have issues please open a new github issue.

dewi-ny-je commented 2 years ago

@hofvanta

I can try. Then I need to buy a USB-RS485 adapter, like: https://nl.banggood.com/USB-To-RS485-Converter-Module-USB-To-TTL-or-RS485-Dual-Function-Dual-Protection-p-1311986.html?imageAb=1&akmClientCountry=America&channel=bg_affiliate&utm_source=bg_affiliate&utm_medium=aff&utm_campaign=giz1205_m_product_prdshare_copy&utm_content=CX08197269762201611W_10192&_branch_match_id=800497510816475964&akmClientCountry=NL&akmClientCountry=NL&cur_warehouse=CN And with standard HA integration, it should be possible I think https://www.home-assistant.io/integrations/modbus/

Any success? For info, I have a good experience with EW-11 as RS485 to Wifi bridge. http://www.hi-flying.com/elfin-ew1x-rs232-rs485-to-wi-fi But before I order another one, I'd like to know about your results with the RS485 port.

hofvanta commented 2 years ago

I didnt try it yet because of RS485 delivery delays. Should be nice if you can experience with the EW-11 is possible in combination with APS ECU_R_PRO.

dewi-ny-je commented 2 years ago

I didnt try it yet because of RS485 delivery delays. Should be nice if you can experience with the EW-11 is possible in combination with APS ECU_R_PRO.

It's used all the time, I cannot repurpose it. I have another RS232-RS485 module which I could use with R-Pi or ESP8266, but I have little time recently so given the time it would take to setup everything I may simply set the module multiscrape to parse the local web page.

tv3 commented 2 years ago

For the scraper part, you can check my repo.

https://github.com/tv3/homeassistant-apsystems_ecur

It's a fork from this repo where I worked on getting rid of the whole tcp communications.

With Kyle I wanted it to integrate into his integration, but it has been silent for some time. So I might work on a separate integration for any ecu with the internal web interface (I have an Ecu_r_pro).

dewi-ny-je commented 2 years ago

For the scraper part, you can check my repo.

https://github.com/tv3/homeassistant-apsystems_ecur

It's a fork from this repo where I worked on getting rid of the whole tcp communications.

With Kyle I wanted it to integrate into his integration, but it has been silent for some time. So I might work on a separate integration for any ecu with the internal web interface (I have an Ecu_r_pro).

Yes I was thinking about your module too. Why haven't you refactored it based on the latest version of Kyle's module? Especially since he has been silent.

dewi-ny-je commented 2 years ago

For the scraper part, you can check my repo.

https://github.com/tv3/homeassistant-apsystems_ecur

It's a fork from this repo where I worked on getting rid of the whole tcp communications.

With Kyle I wanted it to integrate into his integration, but it has been silent for some time. So I might work on a separate integration for any ecu with the internal web interface (I have an Ecu_r_pro).

BTW you didn't enable the Issues page on your repo. Also, your integration works just fine with the Ethernet address, the Wifi is not required.

tv3 commented 2 years ago

I know it works on both Ethernet and WiFi. Been running it for weeks. As for issues etc. There wasn't any plan yet to create a separate integration. If I do, I will first need to find some time to clean it up. For now it is still a copy of Kyle's repo with hacks from my side.

dewi-ny-je commented 2 years ago

I know it works on both Ethernet and WiFi. Been running it for weeks. As for issues etc. There wasn't any plan yet to create a separate integration. If I do, I will first need to find some time to clean it up. For now it is still a copy of Kyle's repo with hacks from my side.

Anyway I just installed it and it works just fine. I set 305 seconds as interval because setting the same as the source data worries me that sometimes I'll get the old data again. Maybe a check could be done, and if identical (given the timestamp), repeat the polling 5 seconds later. Hopefully the 300 s would then start from the latest measurement, not from the planned one which proved to be too early.

tv3 commented 2 years ago

Iirc there is a check on wether new data has arrived (time stamp check). Also disable integration on sundown.

dewi-ny-je commented 2 years ago

Iirc there is a check on wether new data has arrived (time stamp check). Also disable integration on sundown.

Has you integration stopped working for you too in the last few days? Maybe after the latest update from HA 2022.4.x?

I get

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 335, in async_setup
    result = await component.async_setup_entry(hass, self)
  File "/config/custom_components/apsystems_ecur/__init__.py", line 195, in async_setup_entry
    inverters = coordinator.data.get("inverters", {})
AttributeError: 'NoneType' object has no attribute 'get'

And

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 190, in _async_refresh
    self.data = await self._async_update_data()
  File "/usr/src/homeassistant/homeassistant/helpers/update_coordinator.py", line 150, in _async_update_data
    return await self.update_method()
  File "/config/custom_components/apsystems_ecur/__init__.py", line 109, in update
    raise Exception(f"Somehow data doesn't contain a valid ecu_id")
Exception: Somehow data doesn't contain a valid ecu_id

The Web gui works as usual.

hofvanta commented 2 years ago

Same here.

dewi-ny-je commented 2 years ago

I restarted the ECU and now it works. @tv3 have you experienced anything similar recently? I find strange that the Web guide from the browser works but your integration, scraping the Web interface, doesn't, even after multiple restarts of HA.

dewi-ny-je commented 2 years ago

I just checked your repo and I see some test webpages. For info, my ECU-R-PRO does not offer the following ones anymore:

old_energy_graph_monthly old_energy_graph_weekly old_energy_graph_yearly old_power_graph-daytime old_power_graph-dusk

You are not using them, but for information...

The bare ones:

old_energy_graph old_power_graph

are still working providing a text only summary. So I don't understand why your integration stopped working.

tv3 commented 2 years ago

@dewi-ny-je the monthly/weekly etc are not real URL's.

you need to POST on http:///index.php/realtimedata/old_energy_graph and supply additional data eg: period=weekly (orperiod=yearly etcetera)

dewi-ny-je commented 2 years ago

@dewi-ny-je the monthly/weekly etc are not real URL's.

you need to POST on http:///index.php/realtimedata/old_energy_graph and supply additional data eg: period=weekly (orperiod=yearly etcetera)

Thanks. Any feedback on the issue @hofvanta and I had? the web gui working but the integration not? If it happens again I'll provide further feedback, for now it's working after restarting the ECU

dewi-ny-je commented 2 years ago

Today:

Using cached data from last successful communication from ECU. Error: index out of range

@tv3 It's not holding whole week before I need to restart the ecu in order to get again data.

tv3 commented 2 years ago

You're probably using the socket implementation, instead of the http version of the query ecu function.

dewi-ny-je commented 2 years ago

You're probably using the socket implementation, instead of the http version of the query ecu function

I thought your version was only http, I have to check where's the setting for that. Thanks.