Mercedes Me Component

Here’s the error I’m getting in the logs:
Can’t lock car (MY VIN). VIN unknown or feature not availabe for this car.

6:45:42 PM – (WARNING) MercedesME 2020 (custom integration)

Please go to the integration option dialog and activate „ Disable capabilities check“.

That did it, thank you so much. Been a while since my original setup so I forgot a bunch of the steps.

Hi.

I note you say that your code uses the Mercedes API. In my Mercedes me app, I can change the interior led colour. It’s called the ambient lighting. Can I also do this through your add-on please.

Hi @Mtsuleman ,

currently not. But the bad weather time is starting, let me check.

BR
Rene

1 Like

Dear MB-Integration Users,

slightly Off-Topic (ok, Smart cars are part of the MB Family), but I have published a first version of a “Smart EQ Connect”-integration. The sensor set is limited like the trunk of these cars :slight_smile:

have fun
BR
Rene

1 Like

Hey dear MB hass.io community,
I’m having some issues, and can’t really come along with a proper solution.
I can’t see any entities in home-assistant. What I did was installing via HACS and configuring my account. It seems to work but I don’t get any more data…
What I can see is within “integrations” it shows mbapi2020 and Mercedes ME 2020.

Car is a GLE 2021 / W167.

I’ve attached a screenshot.

Thanks in advance!

Somehow I saw that the remote diagnosis option was deactivated within the app… It’s still activating but maybe that was the reason why?

Hi @P1Rebo ,

do you see the car data in the mobile app already? If yes, just restart HA. If nothing is visible, please enable the debug log and share it here or via a private message.

BR
Rene

Thanks @ReneNulschDE for the fast reply. It still remains in activation within the Mercedes me iOS app. As I saw this is normal and can take some time. In HA I still can’t see any entities yet. I will give an update asap.

1 Like

After installation this component works well for 3 hours in my HA configuration.
After that period of time for every 5min I get errors and component stops to work because of token error.
Do You know what can I do to solve it?
This component worked in my config for months and yesterday after deinstallation and new installation something has changed. Yesterday after 3 hours from installation it stopped to work. Today I tried and situation is the same. After few hours it stopped to work again.

2021-11-27 21:33:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/config/custom_components/mbapi2020/websocket.py”, line 123, in async_connect
headers = await self._websocket_connection_headers()
File “/config/custom_components/mbapi2020/websocket.py”, line 224, in _websocket_connection_headers
token = await self.oauth.async_get_cached_token()
File “/config/custom_components/mbapi2020/oauth.py”, line 136, in async_get_cached_token
token_info = await self.async_refresh_access_token(token_info[“refresh_token”])
KeyError: ‘refresh_token’

2021-11-27 21:38:29 ERROR (MainThread) [homeassistant] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/config/custom_components/mbapi2020/websocket.py”, line 123, in async_connect
headers = await self._websocket_connection_headers()
File “/config/custom_components/mbapi2020/websocket.py”, line 224, in _websocket_connection_headers
token = await self.oauth.async_get_cached_token()
File “/config/custom_components/mbapi2020/oauth.py”, line 136, in async_get_cached_token
token_info = await self.async_refresh_access_token(token_info[“refresh_token”])
KeyError: ‘refresh_token’

per me è la stessa cosa da ieri, dopo l’aggiornamento, ha smesso di funzionare

for me it’s the same thing since yesterday, after the update, it stopped working,
is there any solution?

Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 304, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File “/config/custom_components/mbapi2020/init.py”, line 105, in async_setup_entry
token_info = await mercedes.client.oauth.async_get_cached_token()
File “/config/custom_components/mbapi2020/oauth.py”, line 136, in async_get_cached_token
token_info = await self.async_refresh_access_token(token_info[“refresh_token”])
KeyError: ‘refresh_token’

Hi,

I see this error too since Friday. Let me check if there was a change in the MB-Auth-Backend or if I made a mistake.

BR
René

I have published a release “Release 0.5.14 - Bugfix refresh_token error”. This should fix the error:

File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 304, in async_setup
result = await component.async_setup_entry(hass, self) # type: ignore
File “/config/custom_components/mbapi2020/init.py”, line 105, in async_setup_entry
token_info = await mercedes.client.oauth.async_get_cached_token()
File “/config/custom_components/mbapi2020/oauth.py”, line 136, in async_get_cached_token
token_info = await self.async_refresh_access_token(token_info[“refresh_token”])
KeyError: ‘refresh_token’

A ReAuthentication is required - See the red box on the integration page after restart.

Background:
MB changed something in the OAuth Backend. In the past the refresh_token was always present. Now the refresh_token is missing sometimes… :roll_eyes:

@bobofruit , @dolam : May I ask you to recheck?

BR
Rene

2 Likes

Good morning Renè,
now it has authenticated and MercedesMe has communicated the code but neither the device nor the entities appear anymore

Did you reauthenticate via the integration page? There is no way without the reauthentication because the component lost the refresh_token.

Other option:

  • delete the component via the integration page
  • delete the file .Mercedes… in the HA config folder
  • restart HA
  • add the component again

Hi, @ReneNulschDE

I have uninstalled everything and installed again new version.
I can not see any problems in logs but we have to wait few hours.
Component works in Poland.

Thank You and regards

1 Like

2 = plugged in not charging. :slight_smile:

Hi @ReneNulschDE,

First of all, I’d like to thank you for your amazing work! I’m totally new on HA and your custom component was one of the reason why I’m now using HA.

FYI I’m in France, so you can add ‘FR’ on the list of the countries where your component works :slight_smile:

Thanks again and best regards

1 Like

@ReneNulschDE Great work! one of the easiest integrations I’ve dealt with so far.

My contribution to this thread, I’ve integrated a telegram bot into my system. Reason being - sometimes you’re on a train and want to do things, but not wait for an app to load to with cellular/mobile signal. So, why not ping a command across and it’ll get done when you are out of said tunnel. :wink:

I’ve got it to:

  • list car stats (I’ve created some custom sensors to tell me window states & sunroof states- ie, open, closed, partially opened, venting, moving).
  • Flash your lights (cause this was amusing - and not something the default app does)
  • lock doors
  • unlock doors (not sure this is a good idea)
  • close windows
  • close sunroof
  • turn on climate control (pre-heating for winter… assume aircon for summer!?)

Code to get you going if you wanna - and don’t forget to replace sensors with your own. (ps, just worked out the plugged in status indicator - so this is wrong currently in the code below).

Merc menu

- alias: Telegram bot Merc menu command
  id: telegram-merc-menu-cmd
  trigger:
  - event_type: telegram_callback
    platform: event
    event_data:
      data: /merc
  - event_type: telegram_command
    platform: event
    event_data:
      command: /merc
  action:
  - service: telegram_bot.send_message
    data_template:
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      message: The Merc!
      disable_notification: true
      inline_keyboard:
      - 🔋 Car stats:/mercstats, 🚘 Flash your lights:/mercshowpos
      - 🔑 Lock doors:/merclock, 🔓 Unlock doors:/mercunlock
      - 🪟 Close windows:/mercclosewindows, ☀️ Close sunroof:/mercclosesunroof
      - 🌡️ Turn on climate control:/mercclimate, 🔌 Start charging:/merccharge
      - 🔙 Back to options:/options

All the commands here:

- alias: Telegram Merc show position (flash lights)
  initial_state: 'on'
  id: telegram-Merc-flash-lights
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /mercshowpos
    platform: event
  - event_type: telegram_command
    event_data:
      command: /mercshowpos
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: '{{ [ "**click**", "Lost your car? I will flash the lights for you.", "Should I be discreet about it? ", "🎶 Coming to the light 🎶", "I will do that for you." ] | random }}        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: 🚘 Flashing your car lights. 
  - service: mbapi2020.sigpos_start
    data:
      vin: !secret merc_vin 
- alias: Telegram Merc lock doors
  initial_state: 'on'
  id: telegram-Merc-lock-doors
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /merclock
    platform: event
  - event_type: telegram_command
    event_data:
      command: /merclock
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: '{{ [ "**thwack**", "Locked.", "Beep!", "🎶 Three, four, she locked the door! 
        🎶", "Lockin good." ] | random }}
        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: 🔑 Locking the Merc
  - service: mbapi2020.doors_lock
    data:
      vin: !secret merc_vin
- alias: Telegram Merc unlock doors
  initial_state: 'on'
  id: telegram-Merc-unlock-doors
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /mercunlock
    platform: event
  - event_type: telegram_command
    event_data:
      command: /mercunlock
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: '{{ [ "**thwack**", "Locked.", "Beep!", "🎶 Three, four, she locked the door! 
        🎶", "Lockin good." ] | random }}
        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: 🔓 Unlocking the Merc
  - service: mbapi2020.doors_unlock
    data:
      vin: !secret merc_vin
- alias: Telegram Merc close sunroof
  initial_state: 'on'
  id: telegram-Merc-close-sunroof
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /mercclosesunroof
    platform: event
  - event_type: telegram_command
    event_data:
      command: /mercclosesunroof
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: '{{ [ "**click**", "Closing the sunroof.", "wwhiiirrrrthup!", "🎶 Rain rain, go away, come again another day! 
        🎶", "On it." ] | random }}

        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: 🔌 Start charging the Merc
  - service: mbapi2020.sunroof_close
    data:
      vin: !secret merc_vin #vinNumber
- alias: Telegram Merc close windows
  initial_state: 'on'
  id: telegram-Merc-close-windows
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /mercclosewindows
    platform: event
  - event_type: telegram_command
    event_data:
      command: /mercclosewindows
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: '{{ [ "**click**", "Closing the windows.", "wwhiiirrrrthup!", "🎶 Close the window, calm the light. And it will be all right. 
        🎶", "I will jump right too it" ] | random }}

        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: 🔌 Start charging the Merc
  - service: mbapi2020.windows_close
    data:
      vin: !secret merc_vin #vinNumber
- alias: Telegram Merc climate control toggle
  initial_state: 'on'
  id: telegram-Merc-climate-control-toggle
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /mercclimate
    platform: event
  - event_type: telegram_command
    event_data:
      command: /mercclimate
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: '{{ [ "**click**", "Turning it on? Turning it off? You really should
        create an on or off switch.", "Hot or cold?", "🎶 hot potato! 🎶", "No problemo."
        ] | random }}

        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: '🌡️ Turn on climate control: Toggled'
  #- service: switch.toggle
  #  entity_id: switch.carplate_auxheat #try same service as close windows?
  - service: mbapi2020.preheat_start
    data:
      vin: !secret merc_vin
- alias: Telegram Merc stats
  initial_state: 'on'
  id: telegram-merc-stats
  trigger:
  - event_type: telegram_callback
    event_data:
      data: /mercstats
    platform: event
  - event_type: telegram_command
    event_data:
      command: /mercstats
    platform: event
  action:
  - service: telegram_bot.send_message
    data_template:
      inline_keyboard:
      - 🔵 Show options:/options
      - 🔙 Back to Merc menu:/merc
      message: ' Last updated: {{state_attr("sensor.carplate_car", "last_message_received")}} 

        Locked? {{states("lock.carplate_lock")}}

        Driver window?  {{states("sensor.carplate_window_driver")}}

        Passenger window?  {{states("sensor.carplate_window_passenger")}}

        Back left window?  {{states("sensor.carplate_window_backleft")}}

        Back right window?  {{states("sensor.carplate_window_backright")}}

        Sunroof? {{states("sensor.carplate_sunroof_state")}}

        Pre-conditioning? {{states("switch.carplate_auxheat")}}

        Is it on? {% set ignitionstatus = states("sensor.carplate_ignition_state") %} {% if ignitionstatus == "0" %} Ignition lock  {% elif ignitionstatus == "1" %} Ignition off  {% elif ignitionstatus == "2" %} Ignition accessory  {% elif ignitionstatus == "3" %} 3 means something? {% elif ignitionstatus == "4" %} Ignition on  {% elif ignitionstatus == "5" %} Ignition start  {% endif %}

        Plugged in? {{ states("") }}

        Charging: {{ states("sensor.carplate_charging_power") }}

        Battery is at {{ states("sensor.carplate_state_of_charge") }} %

        Estimated range (with heating) {{ states("sensor.carplate_range_electric") }} miles.

        Where it is at: {{ states("device_tracker.carplate_device_tracker") }}.



        '
      target: '{{ trigger.event.data.user_id }}'
      callback_query_id: '{{ trigger.event.data.id }}'
      title: 🔋 Car stats for the Nissan Merc

Hope this inspires/helps folks too. :smiley:

3 Likes