ReneNulschDE / mbapi2020

Custom Component to integrate MercedesME devices into Home-Assistant
Other
172 stars 33 forks source link

remote websocket connection closed: Cannot write to closing transport #279

Closed el-Presi closed 15 hours ago

el-Presi commented 1 week ago

The problem

Since a few days now (and I noticed a slightly design change within the Mercedes ME app also in that time), I cannot send commands to the car anymore (remote websocket connection closed: Cannot write to closing transport). When I perform a restart of the integration, it works again

What version of MBAPI2020 do use?

v0.19.1

What was the last working version of MBAPI2020?

No response

What type of installation are you running?

Home Assistant OS

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Dieser Fehler stammt von einer benutzerdefinierten Integration

Logger: custom_components.mbapi2020.websocket
Quelle: custom_components/mbapi2020/websocket.py:229
Integration: MercedesME 2020 (Dokumentation, Probleme)
Erstmals aufgetreten: 17. November 2024 um 21:15:27 (1 Vorkommnisse)
Zuletzt protokolliert: 17. November 2024 um 21:15:27

Other error 429, message='Invalid response status', url='wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws'

- - - - - - - - - - - - - - - - -

Dieser Fehler stammt von einer benutzerdefinierten Integration

Logger: custom_components.mbapi2020.client
Quelle: custom_components/mbapi2020/client.py:263
Integration: MercedesME 2020 (Dokumentation, Probleme)
Erstmals aufgetreten: 17. November 2024 um 21:15:27 (1 Vorkommnisse)
Zuletzt protokolliert: 17. November 2024 um 21:15:27

Error with the websocket connection (retry counter: 0):

- - - - - - - - - - - - - -

Dieser Fehler stammt von einer benutzerdefinierten Integration

Logger: custom_components.mbapi2020.websocket
Quelle: custom_components/mbapi2020/websocket.py:179
Integration: MercedesME 2020 (Dokumentation, Probleme)
Erstmals aufgetreten: 10:37:30 (4 Vorkommnisse)
Zuletzt protokolliert: 10:42:39

remote websocket connection closed: Cannot write to closing transport

Additional information

No response

ReneNulschDE commented 1 week ago

I see this error since last Tuesday. MB has changed some settings in their backend and closing the sessions more often. (every 15min now) and http429 is a "Too many requests block" - have not found a solution yet.

Could you enable the debug logging, wait for the error and share the complete log (via email to mbdev.i279@nulsch.de)?

dennzs commented 6 days ago

The MB app was down for a few hours last night so I wonder if perhaps they broke something and then reverted a change because of that.

ethemcemozkan commented 6 days ago

I started experienced the same error today as well. Perhaps they reverted their revert? :) When I have debug logs I will share with you Edit: this may be a MB issue. Me app also is not working atm and reload also failed

iHaveAstream commented 5 days ago

Hi, just fyi: the issue is still present. Got the very same error also this morning when the integration tried to enable the auxheater via HA automation.

el-Presi commented 5 days ago

Just FYI: I am still waiting for the error to happen again, then I will be able to post some logs :)

AlirezaT commented 5 days ago

It's a few days that after restarting HA the integration doesn't work: 2024-11-20 21:07:33.423 ERROR (MainThread) [custom_components.mbapi2020.websocket] Other error 429, message='Invalid response status', url='wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws' 2024-11-20 21:07:33.423 ERROR (MainThread) [custom_components.mbapi2020.client] Error with the websocket connection (retry counter: 0): 2024-11-20 21:08:03.904 ERROR (MainThread) [homeassistant.config_entries] Error setting up entry xxxxx@gmail.com (Region: Europe) for mbapi2020 Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/config_entries.py", line 635, in __async_setup_with_context result = await component.async_setup_entry(hass, self) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/config/custom_components/mbapi2020/__init__.py", line 207, in async_setup_entry raise HomeAssistantError( homeassistant.exceptions.HomeAssistantError: No car information registered for this account. Check the MB website with the same account. Giving up...

dennzs commented 5 days ago

Mine also stopped working again after a few days but the app is also acting up and unable to synchronize. Not just the integration to HA.

AlirezaT commented 5 days ago

Indeed, I just checked the app and it's not syncing. However, I can log in to the website!

iHaveAstream commented 5 days ago

I can control the car via the app. And with the integration it works when I reload the integration. However, I think tomorrow morning it would not work anymore before reloading the integration.

UDicke commented 5 days ago

I just reloaded 2 hubs and they delivered data again. I will report when working stops again...

paludi commented 4 days ago

I can confirm that it works again for me as well. I added my new car yesterday which failed with the same errors. (even in the Me app) Since today morning HA integration and Me app seem to be working again.

iHaveAstream commented 4 days ago

Hi, also in my case it's working at the moment and the integration was able to activate the auxheater via automation this morning, as usual. Looks promising.

ReneNulschDE commented 4 days ago

It is not solved my dev and test environment stopped again. I'm still collecting information.

For further answers, please include how many accounts you have integrated and the count of devices that each account is using. (Example: 1 Account, used in two HA-Env and 1 Phone, 2 Pads, 1 Watch)

dannyfiorot commented 4 days ago

Same error, but try this:

Enter in the MERCEDES ME INTEGRATION, re-add your car using the email that you use to log-in in the Mercedes ME Application.

The error in my Home Assistant confuguration is created by using the VIN and PIN information in the setup steps. If you install the MERCEDES ME integration using only the email, all work fine.

iHaveAstream commented 4 days ago

Same error, but try this:

Enter in the MERCEDES ME INTEGRATION, re-add your car using the email that you use to log-in in the Mercedes ME Application.

The error in my Home Assistant confuguration is created by using the VIN and PIN information in the setup steps. If you install the MERCEDES ME integration using only the email, all work fine.

Doesn't seem to work for me. In the web portal (https://mercedes.me) I use my mobile number to access it. Same applies to Mercedes Me app. However, the integration seems not to recognise my mobile number, even though I entered it correctly incl. leading country code (+49).

When I try instead with my registered e-mail address, I get:

Logger: homeassistant.config_entries
Source: config_entries.py:635
First occurred: 21:46:01 (1 occurrences)
Last logged: 21:46:01

Error setting up entry **********@gmail.com (Region: Europe) for mbapi2020
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 635, in __async_setup_with_context
    result = await component.async_setup_entry(hass, self)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/config/custom_components/mbapi2020/__init__.py", line 207, in async_setup_entry
    raise HomeAssistantError(
homeassistant.exceptions.HomeAssistantError: No car information registered for this account. Check the MB website with the same account. Giving up...
weesteev commented 4 days ago

Having the same issue today, have removed integration and re-added but just fails now. Also noticed the app seems to be showing incorrect data and still thinks my car is charging when it was last plugged in about 10 hours ago. Think this is definitely a back end issue with Mercedes. Image below of my error log from HA.

Screenshot 2024-11-21 222035

silashansen commented 3 days ago

Having the same issue today, have removed integration and re-added but just fails now. Also noticed the app seems to be showing incorrect data and still thinks my car is charging when it was last plugged in about 10 hours ago. Think this is definitely a back end issue with Mercedes. Image below of my error log from HA.

Screenshot 2024-11-21 222035

I've experienced it a few times as well, but reloading the integration has been fixing it every time. I think you just ran into trying to re-auth while the issue was ongoing. It will probably work if you try it again now.

Regarding the issue: It's fair that the Mercedes backend is failing or returning 429 from time to time, but we should just handle this more gracefully, to avoid leaving the integration in a permanently failed state after the error occurs. I'm sure it would be trivial for @ReneNulschDE to wrap this in some more graceful error handling. I'd love to do this, but I barely have a dev environment up and running for this integration at this point (will work on getting setup).

iHaveAstream commented 3 days ago

Thanks for the hint @silashansen! I was able to re-auth the integration just this moment (via mobile number).

ReneNulschDE commented 3 days ago

Regarding the issue: It's fair that the Mercedes backend is failing or returning 429 from time to time, but we should just handle this more gracefully, to avoid leaving the integration in a permanently failed state after the error occurs. I'm sure it would be trivial

I just do not know how long we have to wait. in my tests 60min was too short and 4 hours too long. I'm still testing... - I made another change to force a reconnect from the client side after 12 min (the server breaks the connection after 15 min) to act more like a phone user. (I tested it with a reconnect every 30sec for 24h without a http429)

For further answers, please include how many accounts you have integrated and the count of devices that each account is using. (Example: 1 Account, used in two HA-Env and 1 Phone, 2 Pads, 1 Watch)

ReneNulschDE commented 3 days ago

Would be great if someone can test this beta release: https://github.com/ReneNulschDE/mbapi2020/releases/tag/v0.19.2-beta.1

ReneNulschDE commented 3 days ago

This will not solve it - just got a 429 again...

iHaveAstream commented 3 days ago

Just fyi: for me, it still works ever since. At least it seems like. And this since 12 hours now.

dannyfiorot commented 3 days ago

Situation gone bad... Nothing working.... Integration cancelled and reinstalled....

dcigir commented 3 days ago

It doesn't work for me either. Even the Mercedes app is not showing info from the car :( Mercedes is taking the same path as Volkswagen :) (1 Account, used in one HA-Env and 1 Phone, 1 Watch)

dannyfiorot commented 3 days ago

In 2025 all the car with 3g Module don't work either.... I'm disappointed.....

willembuys commented 3 days ago

I currently cannot use the app (1 phone, app has old data) or the integration (429 error) with my account (2 cars), but when I use the app on my partner's phone (with my partner's account, same 2 cars) while not on Wi-Fi, I can use the app. So is it linked to how many connections are made with an account? And does it then also block the IP address?

ReneNulschDE commented 3 days ago

It's per account and not per IP based on my tests.

After 3-6 hours it will come back

For further answers, please include how many accounts you have integrated and the count of devices that each account is using. (Example: 1 Account, used in two HA-Env and 1 Phone, 2 Pads, 1 Watch)

ReneNulschDE commented 2 days ago

I have published a new beta release. This version contains a new reconnect logic with an increasing wait time.

In my test field, the accounts were blocked at different times (5 p.m., 8 p.m.) and access worked again from 0 a.m. (GMT) the following day.

StefanHesse commented 2 days ago

I just installed the v0.19.2-beta.2 and have the automation running that i will be informed whenever the 429 error is appearing. I will give feedback as soon as the error appears. 1 Account, used in 1 HA, 1 iPAD, 1 Android phone

ReneNulschDE commented 2 days ago

I have deleted the beta-2 - and will republish a new version later today.

StefanHesse commented 2 days ago

OK, do you recommend me to go back to another version until then? Or is it save to stay on beta2?

willembuys commented 2 days ago

Do you have an idea how much requests are allowed and how to limit the number of requests?

ReneNulschDE commented 2 days ago

I assume that it is not related to requests. Currently I suspect its related to active app-ids per account/day. A new app-id is created on restart of HA, reload of the integration or connection problems.

I can't reuse the app-id with the current architecture of the component as the MB-Servers will not deliver a full-update and I create the sensors based on this first full-update.

dennzs commented 2 days ago

@ReneNulschDE when you say account do you mean a user or a car? Would it make sense to create a second (well third) account for our family and use that only with HA and keep the original for the MB app?

I’ll check if my wife’s account works in the app the next time mine dies.

ReneNulschDE commented 2 days ago

Currently I suspect it is per user. So yes, it could be an idea to create a second account and invite them to your car.

Some features, like geofencing is not possible with a secondary account.

ReneNulschDE commented 2 days ago

I have released v0.19.2-beta.3 with an additional fix of the app-id handling.

paludi commented 2 days ago

@ReneNulschDE thanks a lot for your work and quick response! I updated to beta3 and now communication with the Me servers work again. Before it was broken after upgrading to beta2 and reverting to 0.19.1.

I have 1 account with 1 HA instance and 1 android phone.

ethemcemozkan commented 2 days ago

If it matters, I started noticing frequent logouts from all MB apps(me, finance, eco...). My setup: 2 accounts, one purely using the MB me app, the other one used for MB me, HA, and other companion apps

firstcolle commented 2 days ago

Beta 1 was fine for me. Installed beta 3 and I cant see my entityes. The integration inizialises fine. I noticed also that the data in the mb app is not updated, but is uodated in the web site

ReneNulschDE commented 1 day ago

I cant see my entityes. The integration inizialises fine.

In beta 3, I only addressed the reconnection. When you restart HA and the account is blocked then the sensor get not initialized and connection restore on midnight will not initialize the sensors again. So you need to reload manually.

I'm working on beta 4, here I'll try to implement a reload of the component after the account got unblocked at midnight.

The successful reconnect can reviewed in the log:

  1. Last error before midnight (GMT)

    2024-11-24 00:33:54.216 INFO (MainThread) [custom_components.mbapi2020.websocket] Connecting to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws
    2024-11-24 00:33:54.344 ERROR (MainThread) [custom_components.mbapi2020.websocket] Other error 429, message='Invalid response status', url='wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws'
    2024-11-24 00:33:54.346 ERROR (MainThread) [custom_components.mbapi2020.client] Error with the websocket connection (retry counter: 12): 
    2024-11-24 00:33:54.348 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 12
    2024-11-24 00:33:54.348 DEBUG (MainThread) [custom_components.mbapi2020.client] Websocket reconnect handler loop - round 13 - waiting 2535 sec
  2. Successful reconnect after Midnight (GMT)

2024-11-24 01:16:09.349 DEBUG (MainThread) [custom_components.mbapi2020.websocket] _start_websocket_handler: be467fcb9fda5f1eb703df8ad37dae0d
2024-11-24 01:16:09.350 INFO (MainThread) [custom_components.mbapi2020.websocket] Connecting to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws
2024-11-24 01:16:09.458 INFO (MainThread) [custom_components.mbapi2020.websocket] Connected to mercedes websocket at wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws
2024-11-24 01:16:09.458 DEBUG (MainThread) [custom_components.mbapi2020.websocket] Watchdog trigger
Hooshee commented 1 day ago

Maybe this helps a bit: 2024-11-22 21:00:45.772 INFO (MainThread) [custom_components.mbapi2020.websocket] Connecting to wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws 2024-11-22 21:00:45.870 ERROR (MainThread) [custom_components.mbapi2020.websocket] Other error 429, message='Invalid response status', url='wss://websocket.emea-prod.mobilesdk.mercedes-benz.com/v2/ws' 2024-11-22 21:00:45.871 ERROR (MainThread) [custom_components.mbapi2020.client] Error with the websocket connection (retry counter: 0): 2024-11-22 21:00:45.871 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:01:00.872 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:01:15.873 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:01:30.875 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:01:45.876 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:02:00.877 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:02:15.878 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:02:30.879 INFO (MainThread) [custom_components.mbapi2020.client] Client WS Handler loop - loop end round 1 2024-11-22 21:02:42.110 DEBUG (MainThread) [custom_components.mbapi2020] starting lock 2024-11-22 21:02:42.110 INFO (MainThread) [custom_components.mbapi2020.client] Start Doors_lock for vin WDD21XXXXXXXX0706 2024-11-22 21:02:42.111 ERROR (MainThread) [custom_components.mbapi2020.websocket] remote websocket connection closed: Cannot write to closing transport

So, I arrived home, the location was changed to home, and then after 10 minutes the automation would close the car, if I leave it open. And since then it's not working, so the issue may start when you want to control something, not just read.

ReneNulschDE commented 1 day ago

Here is a link to the current release notes of the upcoming version. I just need to wait until blocking and unblocking happens this night to check if my test accounts work as expected...

dennzs commented 15 hours ago

I may be daft here but how does one change the account used for the integration? Delete? Rerun the config somehow?

ReneNulschDE commented 15 hours ago

Click on the Configure link on the integration page. There is an option to delete the auth information.

ReneNulschDE commented 15 hours ago

v0.20.0 is published.