Mercedes Me Component

Thanks man! I think that’s the W204… Told ya, it’s hard to find lol.

Hi,

I had eveything working but changed platform, I did a full restore of my backup and all sensors for my MB came in but as invalid. I guess it have todo with Oauth so I removed the integration and reinstalled it to start the Oauth process but it do not happen.

Sugestion on how to solve this?


Logger: homeassistant.config_entries
Source: custom_components/mbapi2020/oauth.py:130
First occurred: 21:42:50 (1 occurrences) 
Last logged: 21:42:50

Error setting up entry mbapi2020 for mbapi2020

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/config_entries.py", line 248, in async_setup
    result = await component.async_setup_entry(hass, self)  # type: ignore
  File "/config/custom_components/mbapi2020/__init__.py", line 96, in async_setup_entry
    token_info = await mercedes.client.oauth.async_get_cached_token()
  File "/config/custom_components/mbapi2020/oauth.py", line 130, in async_get_cached_token
    token_info = json.loads(token_info_string)
  File "/usr/local/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "/usr/local/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/local/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

So @ReneNulschDE thanks for the suggestion. After disabling the capabilities check I’m now able to lock/unlock doors and start/stop the engine. The sunroof and windows however still yield a status code 403 with details “User has no activated services for this vehicle function.” I wonder however if this is a US-based limitation as you can’t even open the windows or sunroof in the official MB app.

Hi @Jef,

please remove the integration. rename the .mercedesme-token-cache file in your config folder. Make sure you are running the latest version and add the integration again.

Based on the error, it looks like you token file is empty. did you have some problems with the restore?

I can confirm this function doesn’t exist for me. It seemed plausible seeing how I don’t have it in the MB app.

Hi,

Not any problems I noticed except for this, the token file were indeed empty.

Deleted it and reinstalled integration and now it works. Thanks for quick response!

I have a similar problem since it’s pulling a second device with a different VIN, and attributing the lock to it. How do you exclude at installation? I can only exclude after, which makes the second device unavailable but doesn’t help with the lock.

hi @kzaoaai ,

the right VIN is the one without your lic-plate.

Background:

  • The load process connects to the webapi first and get some personal and car details (and the first VIN).
  • Then we connect to the car data system. In the US, we get a different VIN now. However this VIN is the ID that need to use for all the commands.

If you send me the two vins via a private message, I could try to merge the two vins into one car.

Your post reminded me that I had the same problem.

My lock.lic## didn’t/doesn’t work. The device is generated but it doesn’t activate the lock. Then I remembered that Rene added in a feature check. I assumed this was for non-US vehicles as I don’t have some of the other features (like window open, etc.)

If you comment out line 37 in lock.py the lock.vin#_lock should be generated.

 # if value[5] is None or getattr(car.features, value[5], False) is not False:

Hi,

the code change is not needed anymore. There is a setting in the integration options available to disable the feature check.

Rene,

Even with the feature check disabled the lock.vin doesn’t generate. Once I comment out line 37 it creates the lock.

The extra VIN I have is not a variation of my vehicle’s VIN, it looks like a legit VIN for some other vehicle. (I don’t have License plate saved anyways)
I excluded the other VIN, but I can message you if you want to look into it.
EDIT: it is a variation:
CORRECT VIN -----------> " *** 0G5DB1L******"
WRONG VIN --------------> " *** 2539531 *******"

The “Disable capabilities check” allows for the service lock to work, but the component still wouldn’t generate a lock entity. Disabling line 37 and restarting HA fixes that and a lock is created.

1 Like

That’s consistent with my experience. I wonder if there’s a syntax error in line 37. I’ll check it later.

1 Like

You’re right! The real problem is in const.py line 484. This should be None. I’ll prepare a fix.

Thanks for reporting!

BR
Rene

1 Like

Hey guys,
Waiting for my GLE 350de.
Will it be possible to start stop charging via this integration or even via the API?
Using Tibber with hourly based electricity tarif and want to automate so that the car charges while price is low.

No. The charging schedule has to be set via the wall box or other external system.

Hi guys,

I’m out of this thread for the time being as for the first time in 12 years my next new car isn’t a Mercedes :slight_smile:

Thanks to @ReneNulschDE for all his help over the last few years with this excellent component!

Cheers

mb

1 Like

Just wanted to say thanks to @ReneNulschDE and all the contributors here. This component is a model for how HA should work. Can we buy you a coffee Rene? My family loves your custom component!

3 Likes

That’s really good. Can you share the code for these 4 cards?

1 Like

Sure. Everything for the car and climate activation can be found here: Mercedes Me Component - #861 by RhinoRich

Updated lovelace YAML for the LHS grid card (requires mini-graph-card):

type: grid
cards:
  - type: picture-elements
    elements:
      - entity: sensor.car_status_update
        style:
          transform: 'translate(-50%, -50%) scale(0.8, 0.8)'
          color: lightgrey
          left: 15%
          top: 92%
        type: state-label
      - entity: sensor.car_status_message
        style:
          transform: 'translate(-50%, -50%) scale(0.8, 0.8)'
          color: lightgrey
          left: 15%
          top: 96.5%
        type: state-label
      - type: state-icon
        entity: lock.wd70kwf_lock
        tap-action:
          action: toggle
        icon: 'mdi:car-door'
        name: Door locks
        style:
          transform: 'translate(-50%, -50%) scale(1.3, 1.3)'
          color: lightgrey
          left: 67%
          top: 60%
      - entity: sensor.chargestatus
        style:
          transform: 'translate(-50%, -50%) scale(0.9, 0.9)'
          color: lightgrey
          left: 57.5%
          top: 18%
        type: state-label
      - entity: sensor.car_soc
        prefix: ''
        suffix: '%'
        style:
          transform: 'translate(-50%, -50%) scale(1.3, 1.3)'
          color: lightgrey
          left: 15%
          top: 17%
        type: state-label
      - entity: sensor.rangeinmiles
        prefix: ' '
        suffix: ' miles'
        style:
          transform: 'translate(-50%, -50%) scale(1.3, 1.3)'
          color: lightgrey
          left: 39%
          top: 17%
        type: state-label
      - entity: binary_sensor.wd70kwf_tire_warning
        prefix: ''
        style:
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          color: '#FFFFFF'
          left: 66.5%
          top: 17.5%
        type: state-icon
      - entity: binary_sensor.wd70kwf_low_brake_fluid_warning
        prefix: ''
        style:
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          color: '#FFFFFF'
          left: 76%
          top: 17.5%
        type: state-icon
      - entity: binary_sensor.wd70kwf_low_wash_water_warning
        prefix: ''
        style:
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          color: '#FFFFFF'
          left: 95%
          top: 17.5%
        type: state-icon
      - entity: sensor.car_tire_pressure_front_right
        style:
          transform: 'translate(-50%, -50%) scale(0.8, 0.8)'
          color: lightgrey
          left: 38%
          top: 32%
        type: state-label
      - entity: sensor.car_tire_pressure_rear_right
        style:
          transform: 'translate(-50%, -50%) scale(0.8, 0.8)'
          color: lightgrey
          left: 84%
          top: 32%
        type: state-label
      - entity: sensor.car_tire_pressure_front_left
        style:
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          color: lightgrey
          left: 38%
          top: 90%
        type: state-label
      - entity: sensor.car_tire_pressure_rear_left
        style:
          transform: 'translate(-50%, -50%) scale(0.8, 0.8)'
          color: lightgrey
          left: 84%
          top: 90%
        type: state-label
      - entity: sensor.car_lock_front_right
        style:
          '--paper-item-icon-color': white
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 61%
          top: 38%
        type: state-icon
      - entity: sensor.car_lock_rear_right
        style:
          '--paper-item-icon-color': white
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 68%
          top: 38%
        type: state-icon
      - entity: sensor.car_lock_front_left
        style:
          '--paper-item-icon-color': white
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 61%
          top: 83%
        type: state-icon
      - entity: sensor.car_lock_rear_left
        style:
          '--paper-item-icon-color': white
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 68%
          top: 83%
        type: state-icon
      - entity: sensor.car_lock_trunk
        style:
          '--paper-item-icon-color': white
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 95%
          top: 60%
        type: state-icon
      - entity: sensor.car_window_front_right
        style:
          '--paper-item-icon-color': lightgrey
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 56%
          top: 31%
        type: state-icon
      - entity: sensor.car_window_rear_right
        style:
          '--paper-item-icon-color': lightgrey
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 73%
          top: 31%
        type: state-icon
      - entity: sensor.car_window_front_left
        style:
          '--paper-item-icon-color': lightgrey
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 56%
          top: 90%
        type: state-icon
      - entity: sensor.car_window_rear_left
        style:
          '--paper-item-icon-color': lightgrey
          transform: 'translate(-50%, -50%) scale(0.7, 0.7)'
          left: 73%
          top: 90%
        type: state-icon
      - entity: binary_sensor.wd70kwf_park_brake_status
        prefix: ''
        style:
          transform: 'translate(-50%, -50%) scale(0.6, 0.6)'
          color: '#FFFFFF'
          left: 11%
          top: 42%
        type: state-icon
      - entity: binary_sensor.wd70kwf_windows_closed
        prefix: ''
        style:
          transform: 'translate(-50%, -50%) scale(0.6, 0.6)'
          color: '#777777'
          left: 11%
          top: 52%
        state_color: false
        type: state-icon
        icon: null
      - entity: sensor.car_lock_status
        prefix: ''
        style:
          color: '#FFFFFF'
          left: 13%
          top: 64%
        type: state-label
      - entity: device_tracker.wd70kwf_device_tracker
        prefix: ''
        style:
          color: lightgrey
          left: 12%
          top: 77%
        type: state-label
    image: /local/mercnew4.png
  - type: picture-elements
    elements:
      - type: service-button
        title: Deactivate
        service: mbapi2020.preheat_stop
        service_data:
          vin: yourvinnumber
        target: {}
        icon: 'hass:radiator-off'
        style:
          top: 80%
          left: 80%
      - type: service-button
        title: Activate
        service: mbapi2020.preheat_start
        service_data:
          vin: yourvinnumber
        target: {}
        icon: 'hass:radiator'
        style:
          top: 20%
          left: 20%
    image: /local/climate.PNG
  - type: 'custom:mini-graph-card'
    icon: 'hass:battery-charging'
    entities:
      - entity: sensor.car_soc
        name: Battery Charge
        unit: '%'
    hours_to_show: 72
    points_per_hour: 4
style: |
  ha-card {
  background-color: var(--primary-background-color);
  border-radius: 10px;
  margin: 15px;
  box-shadow:
    -4px -4px 8px rgba(255, 255, 255, .5), 5px 5px 8px rgba(0, 0, 0, .03);
  }
columns: 1
square: false

Map card:

type: map
entities:
  - device_tracker.wd70kwf_device_tracker
default_zoom: 16
dark_mode: true
aspect_ratio: '1.224'
hours_to_show: 72
title: Car Tracker
1 Like