Mercedes Me Component

Rene,

I dont know if this was already mentioned but my integration from the US is still working.

RM

2 Likes

HI RM,

good to know, thank you - I assume this will change soon. :frowning:
BR
Rene

@ReneNulschDE I do the same for iobroker I already extracted the protos but also struggling to convert the ws data to deserialize data. Maybe we can join forces here.

I have also tested the available APIs with my car, but couldn’t get production data from the Connected Vehicle API. Scope ( mb:vehicle:status:general ) of Bearer Token should be ok according to documentation, but I only get “reason”:“invalid or missing authorization in header”,“code”:“401” from example https://api.mercedes-benz.com/experimental/connectedvehicle/v1/vehicles/FIN/location. Other APIs like https://api.mercedes-benz.com/vehicledata/v1/vehicles/FIN/resources are working with same token.

Hi @markus1

You have to register for the different APIs with the BYOCAR subscription model.
See here:




BR
Rene
PS: or you wait some days… eventually, we have a different way.

1 Like

Is there any movement or is MB limiting all possibilities?

I guess you could exploit the BYOV(ehicle) API on your own, but I failed scripting the basic auth to get a token.

Hi All,
I’ve had some limited success in getting the BYOCAR API working. I’ve managed to get an access token and am querying against my own car but getting a series of error messages. There is a notice saying they are having issues for the API since August so not sure if the errors are with me or the service.

My method is very cumbersome currently as I’m using node red to send my REST commands and I hope to feed the sensors in Home assistant once they query succesfully.

I’ve logged support ticket with MB. I’m querying successfully but I’m getting no content (204 error) for my car. I can see the API queries in the data access history in the Mercedes me Portal for my car so it looks like I’m querying correctly.

1 Like

Got it working. MB came back and stated the API issues are fixed. It takes a couple of days for your car to start populating data on the BYOCAR API it seems. Also you need to use your car so that the data updates for the first time. So for instance if you’ve not opened a particular door since you signed up then it won’t be in the API until you do.

The data set is limited as stated previously and they really need to make the connected car 2.0 API functional on your own car. Once it is available I’m sure I can get it working.

I’m using Nodered to do the curl commands, refresh tokens and populate sensor data. Every time I get home node red polls and populates the sensors.

If anyone is interested, I can share my flow but be warned, it’s messy :slight_smile:

image

4 Likes

Very interested :slight_smile:

Very interested :slight_smile:

Ok :slight_smile:

There is a fair bit to this. First step is to sign up to the API’s at
https://developer.mercedes-benz.com/products and get BYOCAR access to Vehicle Staus, Fuel Staus and Lock Status API’s. Create an app within the console, all API’s can use the same app name.

Once that is all in place we need tokens. The Oauth documentation is useful here.

I got some of the below auth code steps working in Node red but unreliably. As it stands, you’ll need to do the auth code manually to start. You may have to do these steps again if you restart the node red host. If someone can figure out the syntax in node red, I’d be most grateful.

First step to getting a token is to formulate the url as per below with your client id etc, paste it into a browser.

https://id.mercedes-benz.com/as/authorization.oauth2?response_type=code&client_id=<insert_your_client_id_here>&redirect_uri=https://localhost&scope=mb:vehicle:mbdata:fuelstatus mb:vehicle:mbdata:vehiclestatus mb:vehicle:mbdata:vehiclelock offline_access&state=<any 8 digit string>

You’ll get a consent page then an error page but It will return an auth code in the url. Copy that code and do a curl command as follows. I use RESTED extension for firefox:

The grant type syntax is:
authorization_code&code=auth code here&redirect_uri=https://localhost
If all has gone well, you’ll see an access and refresh token. Copy this detail somewhere.

Now the Node Red flow.

[{"id":"f21a039d.42c8f","type":"tab","label":"Mercedes API Prod","disabled":false,"info":""},{"id":"522ab9f0.255008","type":"inject","z":"f21a039d.42c8f","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":150,"y":360,"wires":[["783fecb4.8e0124"]]},{"id":"d8222ef0.4d66e","type":"http request","z":"f21a039d.42c8f","name":"Fuel Status","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.mercedes-benz.com/vehicledata/v2/vehicles/<Vehicle-VIN>/containers/fuelstatus","tls":"","persist":false,"proxy":"","authType":"","x":210,"y":440,"wires":[["28c39fa4.9a0d9","50e1caef.2d0d1c"]]},{"id":"28c39fa4.9a0d9","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":130,"y":480,"wires":[]},{"id":"c08cd592.df4a38","type":"http request","z":"f21a039d.42c8f","name":"Lock Status","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.mercedes-benz.com/vehicledata/v2/vehicles/<Vehicle-VIN>/containers/vehiclelockstatus","tls":"","persist":false,"proxy":"","authType":"","x":530,"y":440,"wires":[["9fcfc753.2cff58","46a4c61a.9c6d3","21fe202f.57b41"]]},{"id":"f6256e3c.de7ac","type":"http request","z":"f21a039d.42c8f","name":"Vehicle Status","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.mercedes-benz.com/vehicledata/v2/vehicles/<Vehicle-VIN>/containers/vehiclestatus","tls":"","persist":false,"proxy":"","authType":"","x":920,"y":440,"wires":[["91c97df0.b5f71"]]},{"id":"9fcfc753.2cff58","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":470,"y":480,"wires":[]},{"id":"91c97df0.b5f71","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":480,"wires":[]},{"id":"4bbd748c.2bd49c","type":"inject","z":"f21a039d.42c8f","name":"Inject Refresh Token","props":[{"p":"payload.refresh_token","v":"merc.refresh_token","vt":"flow"}],"repeat":"6000","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":140,"y":220,"wires":[["4879c57c.f16bbc"]]},{"id":"6788377c.911e18","type":"http request","z":"f21a039d.42c8f","name":"refresh token","method":"POST","ret":"obj","paytoqs":"ignore","url":"https://id.mercedes-benz.com/as/token.oauth2","tls":"","persist":false,"proxy":"","authType":"basic","x":520,"y":220,"wires":[["5d75b7e6.becef8","41a1c7bf.457f98","b66fbf84.66bf1"]]},{"id":"5d75b7e6.becef8","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":510,"y":280,"wires":[]},{"id":"4879c57c.f16bbc","type":"function","z":"f21a039d.42c8f","name":"login request","func":"flow.set(\"token\",msg.payload.refresh_token);\n\nmsg.headers = {\"content-type\":\"application/x-www-form-urlencoded\"}\nmsg.payload = {\"grant_type\":\"refresh_token\",\"refresh_token\": flow.get(\"token\")}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":220,"wires":[["ceced150.46c28","6788377c.911e18"]]},{"id":"ceced150.46c28","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":330,"y":280,"wires":[]},{"id":"41a1c7bf.457f98","type":"function","z":"f21a039d.42c8f","name":"Define Access and Refresh Token vars","func":"flow.set(\"merc.access_token\",msg.payload.access_token);\nflow.set(\"merc.refresh_token\",msg.payload.refresh_token);\n// node.warn(\"Tokens refreshed successfully.\");\nmsg.payload={\n    \"access_token\":flow.get(\"merc.access_token\"),\n    \"refresh_token\":flow.get(\"merc.refresh_token\")\n};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":830,"y":220,"wires":[[]]},{"id":"cbfee138.920ae","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":950,"y":280,"wires":[]},{"id":"783fecb4.8e0124","type":"function","z":"f21a039d.42c8f","name":"Set Headers","func":"\nmsg.headers = {\"content-type\":\"application/json;charset=utf-8\"}\nmsg.headers = {\"authorization\":\"Bearer \" + flow.get(\"merc.access_token\")}\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":530,"y":360,"wires":[["c08cd592.df4a38","d8222ef0.4d66e","f6256e3c.de7ac"]]},{"id":"b66fbf84.66bf1","type":"change","z":"f21a039d.42c8f","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"msg.payload.refresh_token","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":780,"y":280,"wires":[["cbfee138.920ae"]]},{"id":"d0aa0f79.515c7","type":"debug","z":"f21a039d.42c8f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":100,"wires":[]},{"id":"f06accf.49362b","type":"change","z":"f21a039d.42c8f","name":"","rules":[{"t":"set","p":"merc.refresh_token","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":426,"y":100,"wires":[["d0aa0f79.515c7"]]},{"id":"e0f44a65.1d0e2","type":"inject","z":"f21a039d.42c8f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"token","payloadType":"str","x":136,"y":100,"wires":[["f06accf.49362b"]]},{"id":"4e2dc28c.f5a2e4","type":"comment","z":"f21a039d.42c8f","name":"Refesh Token Every 100 Mins","info":"","x":140,"y":163,"wires":[]},{"id":"50e1caef.2d0d1c","type":"ha-entity","z":"f21a039d.42c8f","name":"CarRange","server":"32c9017a.7989d6","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Car Range"},{"property":"device_class","value":"sensor"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":"km"}],"state":"payload[0].rangeliquid.value","stateType":"msg","attributes":[{"property":"range","value":"","valueType":"num"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":190,"y":600,"wires":[[]]},{"id":"46a4c61a.9c6d3","type":"switch","z":"f21a039d.42c8f","name":"Boot","property":"payload[0].doorlockstatusdecklid.value","propertyType":"msg","rules":[{"t":"eq","v":"false","vt":"str"},{"t":"eq","v":"true","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":450,"y":600,"wires":[["3860fef5.82be02"],["92909ff9.5f2ca8"]]},{"id":"21fe202f.57b41","type":"switch","z":"f21a039d.42c8f","name":"Doors","property":"payload[1].doorlockstatusvehicle.value","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":450,"y":680,"wires":[["7d778553.8a2d44"],["63584930.cc2678"],["63584930.cc2678"],["7d778553.8a2d44"]]},{"id":"3860fef5.82be02","type":"change","z":"f21a039d.42c8f","name":"Locked","rules":[{"t":"set","p":"payload","pt":"msg","to":"Locked","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":580,"wires":[["13777e2a.7f4a8a"]]},{"id":"92909ff9.5f2ca8","type":"change","z":"f21a039d.42c8f","name":"Unlocked","rules":[{"t":"set","p":"payload","pt":"msg","to":"Unlocked","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":620,"wires":[["13777e2a.7f4a8a"]]},{"id":"13777e2a.7f4a8a","type":"ha-entity","z":"f21a039d.42c8f","name":"CarBoot","server":"32c9017a.7989d6","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Car Boot"},{"property":"device_class","value":"sensor"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"lock","value":"","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":800,"y":600,"wires":[[]]},{"id":"63584930.cc2678","type":"change","z":"f21a039d.42c8f","name":"Locked","rules":[{"t":"set","p":"payload","pt":"msg","to":"Locked","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":602,"y":660,"wires":[["c537edcd.1b5bb8"]]},{"id":"7d778553.8a2d44","type":"change","z":"f21a039d.42c8f","name":"Unlocked","rules":[{"t":"set","p":"payload","pt":"msg","to":"Unlocked","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":602,"y":700,"wires":[["c537edcd.1b5bb8"]]},{"id":"c537edcd.1b5bb8","type":"ha-entity","z":"f21a039d.42c8f","name":"CarDoors","server":"32c9017a.7989d6","version":1,"debugenabled":false,"outputs":1,"entityType":"sensor","config":[{"property":"name","value":"Car Doors"},{"property":"device_class","value":"sensor"},{"property":"icon","value":""},{"property":"unit_of_measurement","value":""}],"state":"payload","stateType":"msg","attributes":[{"property":"lock","value":"","valueType":"str"}],"resend":true,"outputLocation":"","outputLocationType":"none","inputOverride":"allow","x":800,"y":680,"wires":[[]]},{"id":"8bcfa89e.d5b1d8","type":"comment","z":"f21a039d.42c8f","name":"Get Sensor Values","info":"","x":110,"y":320,"wires":[]},{"id":"b9a05e31.08936","type":"comment","z":"f21a039d.42c8f","name":"Manually input Refresh Token","info":"","x":140,"y":40,"wires":[]},{"id":"32c9017a.7989d6","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

You’ll need to input your refresh token into the first inject node. the update the refresh token http node with your credentials:

And your VIN in the other http nodes:

Hopefully this gets you guys on the right path! Let me know.

Thank.
i’m trying using bash.
I’m ablet to gereate access token. but not able to get status.
How do you ged vehicle id?

Vehicle ID is your VIN. Look at the bottom of your windshield or in your car data on the mercedes me site.

thanks. but seems not working…
{“exveErrorId”: “103”, “exveErrorMsg”: “Forbidden”, “exveErrorRef”: “16f1a53e-6266-41b4-970d-8a4698dcf925”}

Did you get a consent page when you tried the first URL? It may be also that it takes some time register your API access.

Just for claity, for the lock status, I use URL:
https://api.mercedes-benz.com/vehicledata/v2/vehicles/WDD0000000A000000/containers/vehiclelockstatus

And the curl headers are:

msg.headers = {“content-type”:“application/json;charset=utf-8”}
msg.headers = {“authorization”:"Bearer " access_token}

i’ve recreated application. the error now is:
{“exVeErrorId”:“2”,“exVeErrorMsg”:“Account Created in Country We Are Not Allowed To Share Data From.”,“exVeErrorRef”:“6b9a4a88-942f-4da3-85ae-148a190d5230”}

I come from Italy…