Mercedes Me Component

@LanceSantaMonica ,

could you please open a new issue on github. Share your system infos, logs and detailed description. I don’t understand what you mean with “Security pin” in this context. I’ll follow up after I have seen your issue on github. Thx

before to install the beta version I should remove the current integration, correct?
How? Just removing the folder mbapi2020 ?

No need to delete the old one. Just select the beta version in HACS. and restart.

1 Like

done, it works!

1 Like

v0.10.0 - Multi-user support, better diagnostics

I have to push a bigger release without beta versions to be in line with required changes related to the HA release 2024.02. The original plan was to release this version before the new HA release but the PIN request issue took a lot of time.

What’s new:

  • Multi-user support: You can now add multiple MB accounts.
  • Better diagnostics: The diagnostic download now has more information in a better format

What changed:

  • The user tokens are now stored in the .storage directory and the HA configuration database. The existing token gets migrated on first start after the update. Please use the “Delete token function” in the configuration dialog in case you want to delete the token…
  • Hundreds of other code changes to be in line with the actual HA code base

Breaking changes:

  • I had to change the way how units are handled. The HA-change was added very late to HA and I have not tested all the different countries and options. You will have to fix some statistics. Please go to /developer-tools/statistics and fix the open issues. So please expect some other open topics.
  • the version 0.9.9 created sensors for functionality that a car not has. This releases will fix this but you have to delete the sensors manually or wait 30 days then HA will delete the sensors.

Notes:

  • When you add additional accounts please make sure that the same car is not added multiple times (secondary drivers). The system will handle this case but some errors will reported in the error log. There is no standard functionality in HA for this use-case and I have to find a way to handle it.
  • Please try always to register the cars with your primary car account. Future functionality may not work with secondary accounts.
3 Likes

one of the best intergrations that I am using as it is very useful !

2 Likes

resolved ! thanks

1 Like

v0.10.1 - Fix Services, Units, Multi-User Migration

Thanks for the fast upgrade to v0.10.0 and your feedback. Here is a bugfix release that addresses most of the reported issues

Fixes:

  • Migration to multi-user fails when the refresh token in the old auth-file is invalid (#192)
  • Error message in the auth process gives a better information about the failure reason on MB side now (#192)
  • Service calls are working again (#194)
  • Wrong unit KW was changed back to kW. (Please use the statistic repair function developer-tools/statistics to fix it) (#193),(#195)
  • Remove vin and dealer from diagnostic logs

Still openFixed in the master branch but not part of this release:

  • Problems with the Auxheat switch (#196),(#197)
1 Like

Thanks, works fine here.

Can we monitor (then get alerted) on the MercedesMe Collision Detection (from their ‘Theft notification and parking damage detection’ feature).

We can, but I have never seen a car with this option enabled. Whenever you have this in your car let me know that we can collect some data and create the sensor.

I have it enabled and should be able to trigger the collision with the use of a rattle gun to remove and tighten the wheel nuts. Let me know what and how you would like to collect the data
Thanks

Ok, here the procedure:

  1. Activate the check box “DEBUG ONLY: …” in options/configure dialog of the component
  2. Use the rattle gun :slight_smile:
  3. Deactivate the checkbox “Debug only…”
  4. Send all files of the folder custom_components/mbapi2020/messages via email to [email protected]

Thx

Hey @ReneNulschDE I am currently thinking to implement the feature for evcc.io to get the soc und range Electric of the car. Could you point me to the api calls that could give these informations and also tell me the parameters I need to send and how the auth could be done? Also pointing me to the lines in your integration would help. Best Dirk

Hi Dirk,

good idea to implement this for the evcc community as the workaround via HA, IOBroker or Openhab is then not needed anymore. Unfortunately, it is not that easy as there is no Rest-Api available to get Soc and Range. Before I give an high level overview a short but important warning: This is an unofficial way, you can’t ask MB and MB can close this anytime if they like. The component simulates the behavior of the official MB mercedesme app based on public code knowledge with all the consequences. You have to monitor app releases. The code base is not always the same all over the world. And last but not least: it includes a potential legal risk (esp. in Germany, see the latest court decisions in the context of reverse proxy usage)

Important:

  • the http request headers are most important. Don’t ignore them, miss one, change one
  • there are different endpoints and headers per region (North America, APAC, China, Rest-of-the-world (europe)) (see const.py)
  • Some Asian countries are using the “Rest-of the world end endpoints” (India, Thailand)
  • The code base is 3-4 years old and has grown over the time, means ugly code at multiple places.
  • In case you like javascript more then python, take a look at the IoBroker implementation, TA2k has done a great job. Also OpenHab has Java implementation, but I’m not sure if the source code is available. Esp. the Openhab one is a newly created one, so this should be clean and clear

Authentication flow:

  • You use the email/mobilePhone-MB-Account info to request a Pin (there is a nonce - this just a guid) (see: oauth.py - request_pin) (There is a preflight request, don’t ignore this one - otherwise you will never get a Pin)
  • You use the received Pin to request the token information. (see request_access_token) this is straight forward… nonce+pin
  • The response has a access_token, refresh_token an lifetime info.
  • You have to manage the lifetime of the token (see all the other methods in oauth.py)

Car Masterdata

  • This is the easy part - check the webapi.py esp. get_user_info
  • For some car brands like Smart you do not get results, but you will get infos about these cars later via websocket…

Soc and Range

  • This is the tricky part as all the communication happens via websockets and protobuf encoded messages.
  • If you never have used protobuf before, take your time and read the google protobuf docs.
  • You have to generate your Go code for the protobuf interface based on the protobuf files. You can find them here - yes, they are four years old - but still valid for your use case.
  • Generall flow:
  1. You’re websocket client connects to the MB endpoint (see websocket.py)
  2. You will receive messages from the MBserver and you have to handle them.
  3. You have to ack all messages
  4. For you’re use-case the message “vep_updates” is the most important, this contains information about the status of all the different sensor including Soc and Range
  5. You have to manage the lifetime of the websocket connection. It can be closed from server side at anytime and you have recreate the connection.
  6. Again, don’t forget to ack
  • You can receive multiple messages per second, check if special queuing is needed

In case you need more details, send me an email: [email protected]

Hope you have fun creating it…

Hopefully, we will get a public, managed API with a full feature set from MB in the future… OK, I’m waiting since 2018 for it…

Best
Rene

Thanks for all your details. To be honest: that sounds so horrible if you have expected a simple api :joy:

Hi Dirk, I took a look on the vehicle structure in evcc and at least a simple integration is not that hard. Let me try to build one. I will contact you via DM when something is ready to test… Offtopic for this thread here…

1 Like

Hi all. Can I ask how to re-authenticate this component? I am seeing authentication errors in the logs. I do not get the Repairs prompt, just a ‘failed to setup’ error.
Thanks

Hi Matt,

To have a clean state, I would propose that you

  1. delete the integration from HA (Deletion from HACS is not required).
  2. delete the “.mercedesme-token-cache”-file in /config if present, delete the “.mercedesme-token-cache-…”-files in /config/.storage if present
  3. restart HA
  4. Add the integration again.

Hi. Thanks. Is there a way to reauthenticate without wiping the slate clean? I’ve entities tied to automations, dashboards, etc. Would prefer not to have to install from scratch.

No worries if not :slight_smile:
Matt