Mercedes Me Component

Great, will this on short term be pushed to HACS as well, or would you advice me to install this manually on HA?

You can click on “Update information” in HACS and then you should get a notification few seconds later about the new version.
image

1 Like

Hallo Rene,

thanks for the update.
Thanks for the quick fix. works again (german user).

There is an early support for default value handling for sensors. (…) get in touch with me whenever you want to test this)

Can I test this?

Hi Thomas,

I will send you a private message with some instructions over the weekend.

BR
Rene

1 Like

There are also geo-coordinates offered in the API. Is it planned to also transmit them to home assistant?

Hi @ssonder,

Welcome in this community and the MB thread.

The coordinates are published via the device tracker since several years already. Please check your available device trackers.

First check if the location data is available in your MB mobile app. If not check the purchased licenses.

On December 15th, my Mercedes Me (mbapi2020) all of a sudden stopped working: There is no error message in the integration or the device, but all entities are ‘unavailable’.
I don’t find error messages when I enable debug loggin on the intergation. Just these messages:

2023-12-20 11:01:12.885 DEBUG (MainThread) [custom_components.mbapi2020.websocket] Got notification: assigned_vehicles
2023-12-20 11:01:12.894 DEBUG (MainThread) [custom_components.mbapi2020.websocket] Got notification: apptwin_pending_command_request
2023-12-20 11:01:27.883 DEBUG (MainThread) [custom_components.mbapi2020.websocket] Got notification: assigned_vehicles
2023-12-20 11:01:27.892 DEBUG (MainThread) [custom_components.mbapi2020.websocket] Got notification: apptwin_pending_command_request

Can someone tell me how I should try to find and correct this issue?
Thanks in advance

Hi @WimG ,

In the 15th MB changed their API endpoints and a few hours later a new version of this component was released.

Check the postings in this thread and make sure you installed the latest version

BR
Rene

Hi Rene,
thanks for the reply.
One of the actions I did to try to solve the issue, was indeed to upgrade to the latest version. Both home-assistant and the MercedesMe2020 code.
I tried and tried again re-configuring the integration and never got it working. I did notice that the integration saw no problems but no entities were active.
In home-assistant.log (now already replaced by a new version), I noticed that the Mercedes cloud api reported no cars found, with the data sent to it.
In the end I deleted the configuration and the .mercedesme-token-cache and reconfigured everything. Than it worked and the car’s details all came back correctly, with the same name as before.
I don’t know what was at the root of all of this and I’m afraid the data to find out are already gone.
But I’m a happy user again.
Happy holidays,
Wim

1 Like

I have published a new minor release v0.9.9 to keep up with some changes in HA 2024.01.

Notable changes:

  • Sensor “Charging Power” gets created even if the API does not provide values at HA startup.

Fixes:
Removal of a couple of deprecation warnings that otherwise would appear in Home Assistant 2024.1.0

Notes:
The sensor “charging power” is created for all vehicles, even if the vehicle has no charging options. Please ignore or hide the sensor if needed. Thanks to @Thomas01 and @Markus76 for testing.

3 Likes

Thank you very much.
Thats incidentially the next step in clobbering together the data I need for a proper implementation of live data for A Better Routeplanner (ABRP - https://abetterrouteplanner.com/).

For the minimum set (according to ABRP) I still need the following things:

  • Vehicle speed
  • Power output (during driving)

Rene, does the Mercedes API supply these values in any way?

I can share what I have done so far to enable live data for ABRP using Home Assistant with Rene’s integration.

Thanks, and have a nice NYE.

Thomas

Thanks for the update!
I can confirm the sensor “charging power” now works all the time. But I noticed the sensor has a value of -1 kW when not connected to a wallbox. The value is 0 kW when the car is connected but not charging and the value when charging is spot on with the value depicted in the Me-app.
Is that negative value when not charging and not being connected to a charger intended the be like that?

Hi @Thomas01 ,

current actual values are not available via the API but you can use the avarage values.

Power output since since start is the attribute “electricconsumptionstart” of the rangeelectric sensor. The average speed is available via the sensor “ID_average_speed_start”.
BR
Rene

Hi @M31Galaxy15287 ,

this is correct, whenever the API does not provide values, I use -1 as the initial default value for the charging power sensor. I decided to set this value to have a chance to react later on. Is this value a problem?

1 Like

Yes, if using an utility meter to count the used energy… I would prefer to be 0

1 Like

With the next release the default value is 0. The change is done in the master branch on github already, in case someone would like to test it.

And, can someone test if the missing unit at startup causing problems with the statistics? Background: I always use the reported unit from the API and as the API does not provide a value, I also don’t know the unit.

A Better Routeplanner with Home Assistant

Goal:
Supply (realtime) data to A Better Routeplanner (ABRP).

This task is has two big steps, which are

  1. Setup ABRP Live Data
  2. Push Data from HA to ABRP

In Detail, these are:
1.1. Get (user) Token for your car from ABRP
1.2. Obtain API key for ABR

2.1. Setup Automation to send a REST URL in regular intervals to ABRP
2.2. Construct the REST URL
2.3. Set up various sensor data for the REST URL

1.1/1.2 Get Token and API key from ABRP.
To get the user token for the car in ABRP, select the car, click on “Live data”, then on “Link Generic”. Note the Token.
To get the API key, send an email to [email protected] and request a “Telemetry-Only API key”. See also the API documentation under Iternio Telemetry API (via https://www.iternio.com/api “Telemetry API”).

For the HA stuff, we start from the end and move to the beginning.
Note: I have an EQS, hence a lot of my examples are named EQS. Feel free to substitute your own names. Also, I redacted my licence plate number in all the component names in HA, set all instances of "XXX" to your car.

2.3. Set up Sensor Data
ABRP interprets negative power as charging the car, and positive power for driving. As the MercedesME API does not provide driving power, and only charging power in positive value, we need first to invert the charging power. Also ABRP expects status information (car is parked, car is charging, car is fast charging) as either 1 or 0, so we have to mangle these also.

sensor:
- platform: template
  sensors:
    eqs_power_abrp:
      friendly_name: EQS Power for ABRP
      icon_template: mdi:flash
      value_template: >
        {% if states('sensor.XXX_charging_power')|float(0) > 0 %}
          {{states('sensor.XXX_charging_power')|float(0)*(-1)}}
        {% else %}
          0
        {% endif %}

- platform: template
  sensors:
    eqs_is_charging:
      friendly_name: EQS is charging
      value_template: >
        {% if state_attr('sensor.XXX_range_electric', 'chargingstatus') in ["0", "5", "6", "9", "10", "11"] %}
          1
        {% else %}
          0
        {% endif %}

- platform: template
  sensors:
    eqs_is_dc_charging:
      friendly_name: EQS is DC charging
      value_template: >
        {% if state_attr('sensor.XXX_range_electric', 'chargingstatus') in ["6", "11"] %}
          1
        {% else %}
          0
        {% endif %}

- platform: template
  sensors:
    eqs_is_parking:
      friendly_name: EQS is parking
      icon_template: mdi:car-brake-parking
      value_template: >
        {% if is_state('binary_sensor.XXX_park_brake_status', "off") %}
          0
        {% else %}
          1
        {% endif %}

2.2. Construct the REST URL
Put your own token and API key in.
As we do not have the driving power available, I removed the power (and speed) parameter if the car is not charging. Under “car_model”, I do supply the car model again (don’t know if its necessary, as the token was already generated for a specific car in your ABRP account). To get the description of the car, send an API request of https://api.iternio.com/1/tlm/get_carmodels_list (no key or token required). You may also skip supplying the car model.
You could also check the proper construction of the url in HA under “Developer Tools” → “TEMPLATE”.
Copy everything in the url part (from "{% set token" to and including "https://api.iternio.com/1/tlm..."), paste it into the template editor, copy the result and paste it into your browser. Check the response, and if OK, check the ABRP website.

rest_command:
  abrp:
    url: >
      {% set token = "TOKEN" %}
      {% set api_key = "APIKEY" %}
      {% set power = "" %}
      {% if is_state('sensor.eqs_is_charging', "1") %}
        {% set power = ", \"speed\":0, \"power\":"~states('sensor.eqs_power_abrp') %}
      {% endif %}
      https://api.iternio.com/1/tlm/send?token={{token}}&api_key={{api_key}}&tlm={"utc":{{utcnow().strftime("%s")}}, "soc":{{states('sensor.XXX_state_of_charge')}}{{power}}, "lat":{{state_attr('device_tracker.XXX_device_tracker','latitude')}}, "lon":{{state_attr('device_tracker.XXX_device_tracker','longitude')}}, "is_charging":{{states('sensor.eqs_is_charging')}}, "is_dcfc":{{states('sensor.eqs_is_dc_charging')}}, "is_parked":{{states('sensor.eqs_is_parking')}}, "heading":{{state_attr('device_tracker.XXX_device_tracker', 'positionHeading')}}, "odometer":{{states('sensor.XXX_odometer')}}, "est_battery_range":{{states('sensor.XXX_range_electric')}}, "car_model":"mercedes:eqs:22:108:rwd"}
    method: POST
    headers:
      content_type: "charset=utf-8; application/x-www-form-urlencoded"

2.1. Setup Automation
Now that the REST command has been constructed, use an Automation to push regular updates of your car to ABRP.
Goal here:
If driving or charging, update ABRP every 5 seconds (as recommended by ABRP). Also continue updating every 5s up to 30s after parking (to accurately get the parked position and state). Start the 5s update shortly before driving (ie when the doors are unlocked).
And finally, if parked, update only every hour.
Some of these conditions may be redundant, haven’t cleaned them up yet, works fine for me.

alias: ABRP upload
description: Uploads EQS data to A Better Routeplanner
trigger:
  - platform: time_pattern
    seconds: /5
condition:
  - condition: or
    conditions:
      - condition: template
        value_template: "{{ now().minute == 27 and (28 < now().second < 33) }}"
      - condition: numeric_state
        entity_id: sensor.eqs_is_charging
        above: "0"
      - condition: numeric_state
        entity_id: sensor.eqs_is_parking
        below: "1"
      - condition: not
        conditions:
          - condition: state
            entity_id: sensor.eqs_is_parking
            state: "1"
            for:
              hours: 0
              minutes: 0
              seconds: 30
      - condition: numeric_state
        entity_id: sensor.XXX_lock
        above: "0"
        attribute: doorLockStatusOverall
action:
  - service: rest_command.abrp
    data: {}
mode: single

And that should take care of an automated update of ABRP from HA.
Many thanks to Rene for the MercedesMe 2020 integration, that makes this all possible.

2 Likes

The integration stopped working this morning. It’s asking me to reconfigure. I delete the Cache file and when I enter my email address for the PIN it never gets sent. I tried it a few times. Any ideas?

Hi, what is your region? Are you on version 0.9.8 at minimum? What is the output of debug log? And did you startet the mobile app and checked the app?

Region: Europe (Ireland)
Version: 0.9.9
Mobile app is working fine

Let me check log