Mercedes Me Component

You can certainly download images with script or manual. The script contains the first function to get the id of the image, and the second function is to download the image using the id.

You need to add the API Key, VIN of the vehicle and the name of the folder and run the script. To run it, you can use the terminal command: python3 get-vehicle-images.py … but you need the exact path of the script.

If you have the free (trial) 360° version: Be aware that there are severe limitations:

Are you perhaps running into those?

Otherwise the images are accessed by GET request:
Get the ImageIds for the pictures.
Get the images by their ImageIds.

Thomas

Shout out to VietNgoc, who helped me offline, which was generous of him.

Great. Could you share your insights/learnings so that other users have the chance to learn too? Thx

Unfortunately, I wasn’t able to get the script to work. I have zero python experience and kept hitting errors I was unable to troubleshoot. VietNgoc downloaded the images for me.

I can write a short tutorial for the image download from the Mercedes API if there is interest.

4 Likes

Hi,

first, the mercedes integration is great.

I downloaded the script for the images, but i get ther following error:

Exception in </config/pyscript/get-vehicle-images.py> line 28: f"{base_url}/vehicles/{vehicle_id}", params=image_params, headers=headers ^ RuntimeError: Blocking calls must be done in the executor or a separate thread; Use await hass.async_add_executor_job(); at custom_components/pyscript/eval.py, line 1941: return func(*args, **kwargs) (offender: /usr/local/lib/python3.12/site-packages/urllib3/connection.py, line 219: return _HTTPConnection.putrequest(self, method, url, *args, **kwargs))

How can i solve it?

I see you ran the script through Home Assistant. I haven’t tried that way, try the normal operating system.

@VietNgoc

Can you check:
Trip Data → Overview, clicking on “State of Charge” number will bring up the “Max State of Charge” History.

EDIT: Version v1.0.2 installed.

Thomas

1 Like

Is there a way of importing the car’s location and put it on the HA map, for tracking purposes ?

If the location data is available for your car then a standard HA device-tracker is created. You can use the standard map tile to track your car. Example:
image

1 Like

I can see the car’s location in real time in the MercedesMe app on my Android phone … this means it’s available ? I would guess so …

… but I don’t see it appearing on the HA map

am I doing something wrong ?
do I need to configure something ?

Please check if an device_tracker is in your sensor list. It will not be shown on the default map when the car is in your home zone.

I do see a “device tracker” but it only gives “Home” or “Away” …

do I need to “import” this tracker onto the map ?

Home Assistant hides items on the map if they are in the “Home” zone.
Check if you have device_tracker.<your registration>_device_tracker, and if it has lat/long in the attributes.

1 Like

Just add a map tile to your dashboard and configure it.
Example

type: map
entities:
  - entity: device_tracker.<your registration>_device_tracker
hours_to_show: 96
default_zoom: 14
theme_mode: auto

I don’t have a separate map (only the standard supplied one), and I do have the car on the map, except when I’m at home.
See: Hide device_trackers from showing on map? - #2 by dshokouhi

got it !
it’s working !
awesome !

thanks !

Correct. I just wanted to show the tracking feature based on my first screenshot.

Download Images using Mercedes Vehicle Images API

Mercedes has a slew of API for various applications, offered to businesses, predominantly for businesses in the EU, and most are available for purchase only.
These APIs are not the one @ReneNulschDE is using for his Home Assistant integration.

Luckily, some APIs are offered on a trial basis, without having a business in the EU.

One of these is the Vehicle Images API, which can used by car dealers to present rendered pictures of the new or used cars they are offering as a basis for a “3D view”. Mercedes has a database of the options of all the cars they manufactures, and they use it to generate images that reflect the individual cars for which the images are requested. Meaning, if your car has blue paint, the images will show a blue car, etc. Its kind of a digital twin of your car:

This tutorial has three part:

  • Getting access to the API
  • Using the API
  • Programs that use the API to download the images

A prerequisit to play along with the manual download is curl, which should come preinstalled on both Windows and Linux. Use it on the terminal/command line of your computer, not in Home Assistant.

Lets start. Click the arrow to expand a section.

Getting Access to the API

Set-up account and API

All of Mercedes’ API are found in the Developers Portal, so you need to get a Mercedes Developer Access.
The address for the Developers site is https://developer.mercedes-benz.com/
On there click Login.

Accept the terms of use:

You will land in your console page, where you need to create your project.

Fill out the form (the details are not relevant or checked as far as I know).

Then inside your project, add a Product:

Select “Vehicle Images”:

As the purchase model, select “Get for Free”. No credit card required.

Choose the “360° Trial” for the Package.

Please note that the free version cames with some pretty hefty restrictions, limiting it to 5 calls. More on that later.

Subscribe, then go to your project page.


There you need to create the API key for your project. Copy it down for further reference.


Thats it for setting up your developers account and activate the Vehicle Images API.

Using the API

Using the API

Go to the page of the Vehicle Images API, either click on the link on your project page, or from the “Products” page.

On the Vehicle Images page, you find the documentation under the appropriately named “Docs” link.

The workflow for getting the images are:

  1. Getting the ImageIds, which are unique IDs tied to both your API key, and the VIN of the car.
  2. Use the ImageIds to download the actual images.

The endpoint for the API is https://api.mercedes-benz.com/vehicle_images/v2

To get the ImageIds, GET the following URL, with the authentification (API key) in the header.
curl -X "GET" "https://api.mercedes-benz.com/vehicle_images/v2/vehicles/<vehicleId>" -H "x-api-key: <insert_your_api_key_here>" -H "accept: application/json"

The result is a JSON output with the ImageIds of each individual image. There are several parameters availabe to influence how the pictures are generated (backgrounds, daytime/nighttime, image parameters, open/closed root for convertibles etc.). See the “Default Image Settings” page.

A sample request looks like this:

Not every car model does have the same number of images available.

With the ImageIds, you can now download the images.
As with the ImageIds, the curl command to GET the images (with the API key in the header) is:
curl -X "GET" "https://api.mercedes-benz.com/vehicle_images/v2/images/<image-id>" -H "x-api-key: <insert_your_api_key_here>" -H "accept: */*"

You may want to include a -o <filename> to save the image.

A sample request looks like this:

Now do that with all the rest of the images that you got from the previous step.

A note about the limit of “5 calls” that we touched on earlier.
As stated by Mercedes in the documentation (under “Caching of Images” section):

Even though all image references are generated dynamically, we will give you a limited time period to get the images from our side. You have to request the images within 24 hours, starting from the time of requesting the image references.

After this time period you will not be able to get the images anymore and you have to request new imageId(s). If you want to use these images for a longer time period, we advice you to store the files on your own.

So as long as you don’t generate new ImageIds, you have all day long to download the actual images.

Automating the Downloads

There is a python script out there that lets you download the images without going through each step indivdually:

As the python script generates the ImageIds on each run, each run may count against the 5 calls from the trial. Haven’t tested that myself.

Thats it, have fun with the stock image of your individual car. I’m looking forward to what you all come up with these images for your Home Assistant instance.

Thomas

3 Likes