Mercedes Me Component

I can dive deeper if you like.

  1. Activate the option “Debug only…” in the options of the component and restart HA. Wait 2min. Disable the option again. Compress all files out of the folder “HA-CONFIG/custom_components/mbapi2020/messages”
  2. Download the diagnostics report (click on the three dots in the integrations list)
  3. send the two files it to mb-dev.Mastiff (at) nulsch.de

Thanks, but actually it’s @DezeStijn who has that problem, not me. I have the maxSoc service available. But maybe you could do that, DezeStijn?

1 Like

Will have a look at this.
Also added a comment in I can't find the maximum charge level (maxSoc) · Issue #52 · ReneNulschDE/mbapi2020 · GitHub to bump it.

Hi,

since recently I get the following error (I had to restore a backup and then deleted the token file):

After entering the email address and trying to enter the pin, the following occurs:

Dieser Fehler wurde von einer benutzerdefinierten Integration verursacht

Logger: aiohttp.server
Source: custom_components/mbapi2020/oauth.py:221
Integration: MercedesME 2020 (documentation, issues)
First occurred: 08:43:56 (7 occurrences)
Last logged: 08:44:02

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 67, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 227, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 234, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/mbapi2020/config_flow.py", line 95, in async_step_pin
    result = await client.oauth.request_access_token(self.data[CONF_USERNAME], pin, nonce)
  File "/config/custom_components/mbapi2020/oauth.py", line 105, in request_access_token
    token_info = await self._async_request("post", url, data=data, headers=headers)
  File "/config/custom_components/mbapi2020/oauth.py", line 225, in _async_request
    raise err
  File "/config/custom_components/mbapi2020/oauth.py", line 221, in _async_request
    resp.raise_for_status()
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1005, in raise_for_status
    raise ClientResponseError(
aiohttp.client_exceptions.ClientResponseError: 400, message='Bad Request', url=URL('https://id.mercedes-benz.com/as/token.oauth2')

How can I solve this issue? Thanks in advance!

Hi,

I just checked this with my account and is working well. So no general problem. What is your region (EU? as I see some german content)? Do you use the latest version?

Hi - I am using the EU region and it was working before. I deleted the token even Uninstalled the integration however if I enter any 6 digit code I get an unknown error and the logs appear as shown above…

Hi Sven, Could you check that you are running the latest version of the integration? Take a look into the manifest.json in HA_Config/custom_components/mbapi2020. The version tag should show “v0.9.0”

Please try to login with this account into the MB portal too (use the TAN approach).

I have published a minor release v0.9.1

Fixes:

  • EQA/B/? - maxSoc attribute is missing (Sensor: State of charge (soc))
  • Update MB Api endpoints Region China (Thanks @gnep88 for the PR)

Changes:

  • Attribute “SelectedChargeProgram” added to Sensor “State of Charge”

Special thanks to @DezeStijn for the data to solve the maxSoc topic.

2 Likes

I have published a minor release v0.9.2.

This release changes the handling of “Maximum state of charge” for EQ-cars with charging programs. These cars will get a new sensor max_soc and the attribute max_soc is added to the Soc sensor. For other electric/hybrid cars without charge programs in place the old attribute maxSoc is still in use.

New Sensor:
Max_Soc = shows the current configured maximum charge level based on the current selected charge program (has an attribute SelectedChargeProgram too), value in %, range 50-100 step 10

Other changes:

  • MB API version number updates (for the communication with the MB endpoints, no functional change)
  • Special handling of an error in HA core in case the supervisor information are not available on startup (fixes issue #126, needed for WSL detection)
  • Soc sensor: new attribute max_soc (EQs with charge programs only)
2 Likes

@ReneNulschDE is it possible to get the “charging finished” in there? I don’t think it’s there as a sensor or other value, but in the app it looks like this. So the car’s done charging to 80 % at 19:50 tonight.

1 Like

When I install this and set it up it works fine but then later everything becomes unavavailable. The only way I can get everything back is to delete and reinstall.

Hi @dkurtjones ,

please share some more details. What means later? (hours, days, weeks?) please enable the debug logs, explain your environment. Feel free to share the debug logs and diagnostic log via private message.

BR
Rene

Hi @Mastiff ,

here an “theoretical” (not_tested) idea for a solution without code changes.

  1. Create an date time input helper and name it “charging_end” (for this example or use your naming and change the action in the next step.

  2. Create an automation that:

    • runs when the chargingstatus attribute of the rangeelectric sensor moves to 1, 2 or 3 (See here for the meaning of the values)
    • but only when the last run was > 10 seconds
    • Set the date of the inputhelper to current date

Example:

alias: Set Charging End State Date
description: ""
trigger:
  - platform: state
    entity_id:
      - sensor.XXXX_range_electric
    attribute: chargingstatus
    to: "1"
  - platform: state
    entity_id:
      - sensor.XXXX_range_electric
    attribute: chargingstatus
    to: "2"
  - platform: state
    entity_id:
      - sensor.XXXX_range_electric
    attribute: chargingstatus
    to: "3"
condition:
  - condition: template
    value_template: >-
      {{ now() - state_attr('automation.set_charging_state_date',
      'last_triggered') > timedelta(seconds=10) }}
action:
  - service: input_datetime.set_datetime
    data:
      datetime: "{{ now().strftime('%Y-%m-%d %H:%M:%S') }}"
    target:
      entity_id: input_datetime.charging_end
mode: queued
max: 10

  1. Use the information of input helper to create the needed output

Update: could be that the status 1 check is enough. esp in cases where the charging end happens and the cable is removed some minutes/hours later

image

To anyone here, I’ve spent several hours trying to find the correct method to remove old / add new MB vehicle. I am currently left with device / entities that are unavailable from my former MB and wish to delete and cleanup my HA. Currently I am reflecting in the integration my old vehicle. What is best practice
Thank you in advance
PachangaDad

Hi, there is no auto delete option available currently. I would propose that you disable the device. Go to the integration page, click on devices in the MB component box. Select the device that you want to disable and click in the upper right corner on the edit pencil. Select disable device and close the window.

Thank you for your dedicated efforts first off. I deleted the entire custom component and reacquired the integration. Fresh Start and nice an clean. If you need and testing assistance from the US, I can offer my assistance.

1 Like

Worked pretty much flawlessly on first install. Mercedes.me app connected to my MB C200 2.1t 2016 w205.

Install integration, enter email, enter pin and all ok! :ok_hand:
Now to just make some cards for it.

1 Like

I am pretty impressed on how well the integration works!

However, I am not able to get the A/C / heating actions in home assistant for my hybrid E300de. Home Assistant only shows a single switch which is remote lock / unlock.
(Pin is entered in config. Remote lock/unlock works nicely from HA!).

Based on the forum posts, it sounds like I should be looking for “preheating”. But this doesn’t appear as an entity, nor in the debug json (“messages” folder).

While skimming through the debug json file, I find tons of “precond” messages indicating that this could to be the actual heating commands?!
Especially things like “precondSeatFrontLeft” tipped me off… that is something that appears also in MercedesMe app in the (pre-)heating menu for the interior.

Did the API change or did I just miss something in the documentation?

Happy to support debugging / testing and maybe a bit of coding @ReneNulschDE!

Hi @luke_skywalker ,

there is a set of HA services that you can call to start/stop the preconditioning of your car. Take a look in the HA-Services dialog (mbapi2020.preheat_start, mbapi2020.preheat_stop,…)

There is no option to set the precond_temperature or zones yet.

The “Range Electric” Sensor has attributes to show if precond is active.

Example button to start pre_cond:

type: button
tap_action:
  action: call-service
  service: ''
entity: ''
hold_action:
  action: call-service
  service: mbapi2020.preheat_start
  target: {}
  data:
    type: '0'
    vin: WXXXXXXXXXXXXXXX

2 Likes

First of all, thank you for the great effort you put into this custom integration!

I tried preheating my EQV this way. With type 0 the SOC drops to -1% (disappears in the Mercedes ME App) and preheating does not start. With type 1 nothing happens. Preheating with APP works fine.
Any Ideas?

Best regards