ksheumaker / homeassistant-apsystems_ecur

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

ECU-C sometimes restart triggers, but never turns back on #250

Open gratjetost opened 2 months ago

gratjetost commented 2 months ago

Im running 1.4.2 on a ECU-C with firmware 1.2.11 Sometimes a restart is triggered and the whole ECU-C breaks down. (no IP address, no access to dashboard) Only option is to go there and turn it off and on again. There is no reason why the restart triggers. In this example it just restarted in the middle of the day. Running in LAN cable, WIFI not enabled at all.

image image image

HAEdwin commented 2 months ago

Please provide some info from the home-assistant.log. How often is the cache being used and what are the current integration settings (query interval, number of configured retries)? A restart is only initialized after the specified number of retries. If a good query occured the counter is being reset.

gratjetost commented 2 months ago
`2024-04-20 12:11:11.755 WARNING (SyncWorker_33) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Exception error: 'NoneType' object does not support item assignment
2024-04-20 12:16:28.766 WARNING (SyncWorker_63) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Exception error: 'NoneType' object does not support item assignment
2024-04-20 12:21:44.775 WARNING (SyncWorker_38) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Exception error: 'NoneType' object does not support item assignment
2024-04-20 12:26:59.755 WARNING (SyncWorker_39) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Exception error: 'NoneType' object does not support item assignment
2024-04-20 12:32:14.757 WARNING (SyncWorker_40) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Exception error: 'NoneType' object does not support item assignment
2024-04-20 12:32:14.758 WARNING (SyncWorker_40) [custom_components.apsystems_ecur] Communication with the ECU failed after 5 repeated attempts.
2024-04-20 12:42:29.813 WARNING (SyncWorker_62) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Invalid data error: [Errno 113] Host is unreachable
2024-04-20 12:47:32.821 WARNING (SyncWorker_32) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Invalid data error: [Errno 113] Host is unreachable
2024-04-20 12:52:35.829 WARNING (SyncWorker_57) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Invalid data error: [Errno 113] Host is unreachable
2024-04-20 12:57:38.805 WARNING (SyncWorker_2) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Invalid data error: [Errno 113] Host is unreachable
2024-04-20 13:02:41.813 WARNING (SyncWorker_13) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Invalid data error: [Errno 113] Host is unreachable
2024-04-20 13:05:23.695 ERROR (MainThread) [homeassistant.components.homewizard.coordinator] Error fetching homewizard data: Timeout occurred while connecting to the HomeWizard Energy device
2024-04-20 13:07:44.821 WARNING (SyncWorker_32) [custom_components.apsystems_ecur] Using cached data from last successful communication from ECU. Invalid data error: [Errno 113] Host is unreachable
2024-04-20 13:07:48.895 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 452, in _handle_request
    resp = await request_handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_app.py", line 543, in _handle
    resp = await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_middlewares.py", line 114, in impl
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 92, in security_filter_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 83, in forwarded_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 26, in request_context_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 88, in ban_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 236, in auth_middleware
    return await handler(request)
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/http/headers.py", line 32, in headers_middleware
    response = await handler(request)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/http.py", line 73, in handle
    result = await handler(request, **request.match_info)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/components/diagnostics/__init__.py", line 274, in get
    data = await info.device_diagnostics(hass, config_entry, device)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/apsystems_ecur/diagnostics.py", line 28, in async_get_device_diagnostics
    diag_data = {"entry": async_redact_data(ecu.ecu.dump_data(), TO_REDACT)}
                                            ^^^^^^^^^^^^^^^^^
AttributeError: 'APSystemsSocket' object has no attribute 'dump_data'
2024-04-20 13:43:57.562 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.12/site-packages/aiohttp/web_protocol.py", line 350, in data_received
    messages, upgraded, tail = self._request_parser.feed_data(data)
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "aiohttp/_http_parser.pyx", line 557, in aiohttp._http_parser.HttpParser.feed_data
aiohttp.http_exceptions.BadStatusLine: 400, message:
  Invalid method encountered:

    b'\x16\x03\x01'
      ^`

      `entity_id,state,last_changed

binary_sensor.ecu_using_cached_data,off,2024-04-13T06:18:24.388Z binary_sensor.ecu_using_cached_data,on,2024-04-14T08:12:57.767Z binary_sensor.ecu_using_cached_data,off,2024-04-14T08:18:12.769Z binary_sensor.ecu_using_cached_data,on,2024-04-14T09:26:36.761Z binary_sensor.ecu_using_cached_data,off,2024-04-14T09:31:52.762Z binary_sensor.ecu_using_cached_data,on,2024-04-14T09:37:02.767Z binary_sensor.ecu_using_cached_data,off,2024-04-14T09:42:17.766Z binary_sensor.ecu_using_cached_data,on,2024-04-14T17:50:57.760Z binary_sensor.ecu_using_cached_data,off,2024-04-16T16:55:12.769Z binary_sensor.ecu_using_cached_data,on,2024-04-16T19:32:42.760Z binary_sensor.ecu_using_cached_data,off,2024-04-16T19:37:57.767Z binary_sensor.ecu_using_cached_data,on,2024-04-19T14:50:32.767Z binary_sensor.ecu_using_cached_data,off,2024-04-19T14:55:47.765Z binary_sensor.ecu_using_cached_data,on,2024-04-19T15:16:43.766Z binary_sensor.ecu_using_cached_data,off,2024-04-19T15:21:58.767Z binary_sensor.ecu_using_cached_data,on,2024-04-20T10:11:11.766Z binary_sensor.ecu_using_cached_data,off,2024-04-20T11:12:59.764Z binary_sensor.ecu_using_cached_data,on,2024-04-20T21:59:27.773Z binary_sensor.ecu_using_cached_data,off,2024-04-20T22:04:43.855Z binary_sensor.ecu_using_cached_data,on,2024-04-21T10:46:17.768Z binary_sensor.ecu_using_cached_data,off,2024-04-21T10:51:34.901Z `

image

Hope this is enough. The LAN connection itself is stable. The only thing I maybe missed. at the configuration you have to specify a SSID and password. Not able to leave it blank. Should I fill in the LWA settings? But I dont have the ECU-C connected to wifi.

HAEdwin commented 2 months ago

Sorry for the late response,.. you can specify random parameters for SSID and Password if connected by ethernet. Have you allready tried to reboot the ECU? It would be strange if the ECU does not receive an IP-Address from you DHCP server. Is it a fixed IP-Address (assigned IP-address based on MAC address from the ECU)?

gratjetost commented 2 months ago

Its is a fixed IP address. MAC address is linked to the DHCP table on my router. Yes I did reboot the ECU. because when it goes into that restart mode the only option I have is turn off the power and reboot the ECU. When it is in that restart "loop". there is also no IP address assigned at all. So I also can't connect to the local webpage of the ECU.

HAEdwin commented 2 months ago

Does the ECU-C have an option to switch between WiFi and Ethernet? Could it be that you are able to connect using the WiFi connection after restart (when correct SSID and Password are applied) although ethernet is connected? It would mean that the ECU switched to WiFi operation and that somehow must be avoided. I'm hoping someone else owning an ECU-C can help out here...

gratjetost commented 2 months ago

the ECU-C can run LAN and WLAN simultaneously But when a restart is triggered it completely dies out. No WAN and no LAN IP address. Its completely gone from the local dashboard. And I just checked its also gone in the APS website.

HAEdwin commented 2 months ago

It would be weird if neither a WLAN nor a LAN IP-address is assigned to the ECU. Have you looked at the DHCP table to see if the ECU received another IP-Address somehow? Are the MAC addresses still the same for both WLAN and LAN interface on the ECU?

HAEdwin commented 2 months ago

If you encounter the issue of the cache being used very often, try to reposition the ECU or externa antennas if possible. Sometimes bringing them too close to WiFi AP's causes interference because 2.4Ghz WiFi and Zigbee share the same 2.4Ghz band. Last option would be to change the "215" value on line 87 of init.py into a random value like "111" to prevent the integration from rebooting the ECU. You could then use a smartplug to reboot the ECU using a HA automation. I hope other ECU-C owners can share their experiences with the reboot method.

gratjetost commented 1 month ago

It would be weird if neither a WLAN nor a LAN IP-address is assigned to the ECU. Have you looked at the DHCP table to see if the ECU received another IP-Address somehow? Are the MAC addresses still the same for both WLAN and LAN interface on the ECU?

It is really gone, No DHCP issues. MAC addresses are linked in the DHCP table for Wifi and LAN connection. There is no option it will receive a different IP address. Zigbee is 868 MHz. so it cannot interfere with the Wifi. the ECU-C is hard-wired to the 3 phases. not really an option to add a smart switch between that. I'll try to change the value in init.py and give it a go.

gratjetost commented 1 month ago

Update from my site: edited the init.py file line 87 from 215 to 115. This night it went offline again. But only on HA. the local dashboard was still up and running. Errors from the HA logging: image image

After a reboot of HA, the ECU goes unavailable. with a warning in the logging: image

Doing a power cycle of the ECU-C and it works again. The cache is messing something up I can't put my finger on.

gratjetost commented 1 week ago

What is the manual command for a restart? Because I went through the init.py code. But still can't figure out how I can manually trigger a restart. I think it sends a wrong command to the ECU-C that locks it up completely.

HAEdwin commented 1 week ago

It's in init.py If it does not work for the ECU-C you can bypass it there. It is compatible with the ECU-R pro and I think someone with an ECU-C also had positive results but might have changed because of a firmware update.

gratjetost commented 1 week ago

I checked that file. but cant find the real "website" it goes to to trigger the restart. Already tried to change the value 215 on line 87 like you mentioned here https://github.com/ksheumaker/homeassistant-apsystems_ecur/issues/250#issuecomment-2093678070 That also still completely locked up the ECU-C. I'm searching for the website it triggers the restart. line 88 says /index.php/management/set_wlan_ap But I can't figure out what that has to do with the restart. Also when going to /index.php/configuration/ or the regular /index.php/management/ itself on a browser there is no button at all to restart the ECU-C.

PS. there is no reboot function at all in the EMA App at all for the ECU-C.

HAEdwin commented 1 week ago

There is no reboot function indeed. Some users noticed that, when you change the WiFi settings, the ECU will automatically initiate a reboot, this is the trick used. So what happens if you change the WiFi settings on the ECU-C, will it lock up? Does it initiate a restart? What is the URL being posted to the ECU-C?

The 215 to 115 change you made earlier prevents calling this method so the ECU-C will not lock up anymore. Only thing to do now is to start the integration again at let's say 04:00 by switching ECU Query Device back on and see if the ECU will accept queries again. But a possible alternative to this integration is almost available. If you are also running Pi-Hole, AdGuard or others ways to rewrite DNS traffic you can test that new integration. As with the current integration it was written with only the ECU-R in hand, same goes for the new solution. If we had all ECUs in our possession, it would be easier to test compatibility or adjust the integration so that all models can be supported.

gratjetost commented 4 days ago

I'll give the 215 to 115 change another go. Also notice my ECU-C got an firmware update to C1.2.13 no idea what changed. Cant find a changelog. I'm running pihole combined with unbound., I'm happy to help test some things if needed.

ddaddy commented 1 day ago

My ECU-C also went off last night and never came back on. The HA logs show several comms issues, so I don't think the ECU-C was to blame. It even shows that the attempt to restart it failed

Attempt to restart ECU failed with error: HTTPConnectionPool(host='192.168.2.15', port=80): Max retries exceeded with url: /index.php/management/set_wlan_ap (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f4d958740>: Failed to establish a new connection: [Errno 113] Host is unreachable')). Querying is stopped automatically.

The strange thing is that it was very difficult to get it to reconnect to my network.

I switched it off and on many times, but it either wouldn't connect or my router wouldn't give it an IP. Pressing the AP button did nothing also, I could not connect to it locally. The only thing that got it working again, was pressing the reset button, which eventually brought up the local access wifi and I connected and reset the wifi connection.

ddaddy commented 1 day ago

Just looking through the code to reboot the device. I see you set channel to 0 but the web interface only offers 1-13. I wonder if setting channel to 0 is causing the re-connection issues?

Also, the web interface also sends the ip param with a default of 172.30.1.1 but you don't send this parameter.

HAEdwin commented 12 hours ago

Sorry I do not own an ECU-C so I'm unable to test. You can try and alter it in the code or just try a post to the ECU with the possibly correct parameters like so: http://[ip-adress]/index.php/management/set_wlan_ap?SSID: [my ssid], 'channel': [my channel], 'method': 2, 'psk_wep': '', 'psk_wpa': [my wifi password]

ddaddy commented 8 hours ago

I'm not sure why I even looked into the reboot code as my first post clearly shows it couldn't reboot the ECU due to a comms issue. So the issues must lie within the ECU.

HAEdwin commented 7 hours ago

I don't know if it is a problem with the ECU. Perhaps something has changed in the web interface with the latest firmware version. Can you try to find out what happens when you change the WiFi SSID or password via the user interface of the ECU? Will the ECU then reboot? If so, it would be interesting to find out with which URL and parameters this happens. Then I may be able to adjust the integration.

ddaddy commented 7 hours ago

I can see from the html Form elements that it sends a valid number between 1-13 for the channel (Default 6) and the ip parameter with default of 172.30.1.1. I'm not sure if they are actually required in the POST, but they are there to be sent in the HTML so no harm in adding them in.

This was the first time in a long time my ECU went down, so i'll monitor it and get more logs if it happens again. I do just think that something happened with either my router, ecu or RPi that made several things unreachable. When it all came back online, the ECU just wouldn't connect to my network. So the reboot command was pointless as the IP was unreachable.

gratjetost commented 1 hour ago

Today I found out that there is a reboot function in the ECU-C. When you switch the WLAN from WLAN to LWA modus you get a popup: image I don't know how I can trigger it manually. but its there. At the moment I switched the 215 to 115 in the init.py file. It happened once now that there was a "unavailable" in HACS. It went into cache mode. but never came online in the morning. But at least I still could connect to the local dashboard. When I switched from WLAN to LWA the ECU-C rebooted. I restarted HACS, and it was back in working order.

Maybe this part helps from the web page source:


 // 设置Hotspot
  $("#button_set_hotspot").click(function(){
    $.ajax({
        url : "http://192.168.1.206/index.php/management/set_wlan_ap",
        type : "post",
      dataType : "json",
        data: "SSID=" + $("#inputdata1").val()
          + "&channel=" + $("#inputdata2").val()
          + "&method=" + $("#inputdata3").val()
          + "&psk_wep=" + $("#inputdata4").val()
          + "&psk_wpa=" + $("#inputdata5").val(),
        success : function(Results) {
        if(Results.value == 0) {
          $('#ecu_reboot').modal('toggle');
          setInterval('doProgress()', 500);
          setTimeout('window.location.reload()', 55000); 
        }
        },
        error : function() { alert("Error"); }
    })
  });