Connect to new BMW CarData service through MQTT

Do you update all the items manually after the initial setup?
The token update only works with your Client_ID and the refresh_token.
In my example i use String items to store these.

String carBMW_Client_ID "Client ID [%s]" (gPersist, gBMWTokens)
String carBMW_Token_Refresh "Refresh Token [%s]" (gPersist, gBMWTokens)

After step 7 I don’t get an ā€œauthenticatedā€ screen on the link you BMW ID page but instead a ā€œlogin successfulā€ > please continue in the vehicle. The text does not mention you need to sit inside the car for any step - or did I miss something? I’m currently not at home so that’s an issue for me.

I never had this message.

Edit: Is your car connected to the BMW ID you“re using?
It sounds like the car isn“t connected to your account and needs to be authenticaed first.

Yes the car is connected to the same ID. I can control it using the myBMW App.

Is not required. You can find mij solution BMW CarData service through MQTT

Hey @Bredmich, this is really great work! It took me a few hours to get everything up and running, but I’m happy to have my BMW data back in my openhab server!

I changed the code a little bit, because I’m not using file based rules but rules within the main ui. I’m also not using telegram for notification but the openhab app, which is connected to my openhab server by the openhab cloud. If anyone is interested, I can also share my code, but I don’t want to get this thread more complicated.

Some hints for anyone who is using this tutorial:

  • You have the install the JSONPATH transformation for getting the thing channels working.

  • If you are using the great JS scripts from @Bredmich and skip the telegram and logviewer parts of the installation, you have to fill the following items with the right information, before you are able to use BMW_Token_Refresh.js and BMW_ID_Token_Update.js

    String carBMW_Token_Refresh "Refresh Token \[%s\]" (gPersist, gBMWTokens)
    String carBMW_Token_ID "ID Token \[%s\]" (gPersist, gBMWTokens)
    String carBMW_Client_ID "Client ID \[%s\]" (gPersist, gBMWTokens)
    String carBMW_Username "Username \[%s\]" (gPersist, gBMWTokens)
    Number carBMW_Expire "Expiry date" (gPersist, gBMWTokens)
    
1 Like

Hi @kuczerek, I am interested in your modifications using the openHAB app instead of Signal. Somehow this solution stopped working for me so I am planning to start again. I am also using MainUI only for rules, things and items.

In order not to confuse this tutorial with a different solution perhaps DM me, I plan to make a new tutorial from a-z as this is still quite complicated for a lot of users.

1 Like

It is the same for me, but it still works fine for the authentication.

@Bredmich Thank you for your work!
Quick question: if I just created a copy of your scripts and updated the associated variables, items let’s say to carBMWB_Token_Access, etc. - do you think it’d work with a second car on a separate ConnectedDrive account?

Give it a try :wink:
I tried to put every item definition in the beginning so they can be changed easily.

HI @mvbergen ,

no problem, you’ve got mail :wink:

1 Like

Hello,

Thanks for putting this together!

Trying the link you provided to set up the CarData, I cannot log in at this link, despite having a BMW connected drive account. I’m in the US and wondering if the link to geo specific? If I go to https://www.bmwusa.com/, I can log into my account with my usual uname/passwd.

From there, trying to find where I can do what you described:. I start here:

Then to ā€œMy Garageā€

Then to ā€œCarDataā€

Then to ā€œManage Access Permissionsā€

Once I’m here I don’t see anywhere to create a client. Any idea if this is possible from BMW-USA?

Yes, itā€˜s probably only for europe.

It should be a global service but i canā€˜t find any information about the CarData API in the USA.

@Bredmich thanks for the quick reply!

I found this info, where under the ā€œ2. Technical registrationā€ → ā€œ2.1 Step 1: Generate your client IDā€ section it has a link to the world wide portals:

However when I follow this for the US, it takes me to the same site I was looking on previously.

Hi, the token setup is not working anymore. I get the following message. Any ideas?


2026-01-30 10:13:30.991 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - BMW API returned error
2026-01-30 10:13:30.991 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Code: invalid_request
2026-01-30 10:13:30.992 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Description: The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed
2026-01-30 10:13:30.992 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Full JSON Response: {"error": "invalid_request", "error_description": "The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed"}
2026-01-30 10:13:31.139 [INFO ] [.openhab-js.BMW_MQTT_Password_Update] - Username unchanged: b9ba23df-43c6-366f-92a7-5565cd5259eb
2026-01-30 10:13:31.181 [ERROR] [ion.openhab-js.BMW_Token_Setup_Step1] - Incomplete response received. Missing required fields.
2026-01-30 10:13:31.181 [ERROR] [ion.openhab-js.BMW_Token_Setup_Step1] - Response: {"user_code":"TYr6smoD","device_code":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJodHRwczovL2Zvcmdlcm9jay1ibHVlLnByb2QtZ2NkbS5ldS1jZW50cmFsLTEuYXdzLmNsb3VkLmJtdzo0NDMvYW0vb2F1dGgyIiwibmJmIjoxNzY5NzY0NDExLCJ1c2VyX2NvZGUiOiJUWXI2c21vRCIsImlzcyI6Imh0dHBzOi8vZm9yZ2Vyb2NrLWJsdWUucHJvZC1nY2RtLmV1LWNlbnRyYWwtMS5hd3MuY2xvdWQuYm13OjQ0My9hbS9vYXV0aDIiLCJleHAiOjE3Njk3NjQ3MTEsImlhdCI6MTc2OTc2NDQxMSwianRpIjoiYWUyZGViY2ItNWM0MS00NjhmLThjYWQtZGY0YWRiNWUyMTJhIn0.NpjX1b7jTu2KCddAjFFH-Tm_dLEOIk4CNXVhe1XvTHk","interval":5,"verification_uri":"https://customer.bmwgroup.com/oneid/link","expires_in":300}
2026-01-30 10:13:31.182 [ERROR] [ion.openhab-js.BMW_Token_Setup_Step1] - BMW Token Setup Failed

Incomplete response received from BMW.

Response: `{"user_code":"TYr6smoD","device_code":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiJodHRwczovL2Zvcmdlcm9jay1ibHVlLnByb2QtZ2NkbS5ldS1jZW50cmFsLTEuYXdzLmNsb3VkLmJtdzo0NDMvYW0vb2F1dGgyIiwibmJmIjoxNzY5NzY0NDExLCJ1c2VyX2NvZGUiOiJUWXI2c21vRCIsImlzcyI6Imh0dHBzOi8vZm9yZ2Vyb2NrLWJsdWUucHJvZC1nY2RtLmV1LWNlbnRyYWwtMS5hd3MuY2xvdWQuYm13OjQ0My9hbS9vYXV0aDIiLCJleHAiOjE3Njk3NjQ3MTEsImlhdCI6MTc2OTc2NDQxMSwianRpIjoiYWUyZGViY2ItNWM0MS00NjhmLThjYWQtZGY0YWRiNWUyMTJhIn0.NpjX1b7jTu2KCddAjFFH-Tm_dLEOIk4CNXVhe1XvTHk","interval":5,"verification_uri":"https://customer.bmwgroup.com/oneid/link","expires_in":300}`
2026-01-30 10:13:31.244 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'customer.streaming-cardata.bmwgroup.com' with clientid 17660ecc-e480-486d-b52b-8834dfd5735e
2026-01-30 10:13:44.505 [INFO ] [.reconnect.PeriodicReconnectStrategy] - Try to restore connection to 'customer.streaming-cardata.bmwgroup.com'. Next attempt in 60000ms
2026-01-30 10:13:44.507 [INFO ] [.transport.mqtt.MqttBrokerConnection] - Starting MQTT broker connection to 'customer.streaming-cardata.bmwgroup.com' with clientid 17660ecc-e480-486d-b52b-8834dfd5735e
2026-01-30 10:14:00.832 [INFO ] [hab-js.BMW_Token_Refresh_ExpireCheck] - current time: 30.01.2026 10:14:00, expiry of token: 24.01.2026 00:00:59
2026-01-30 10:14:00.832 [INFO ] [omation.openhab-js.BMW_Token_Refresh] - Token needs to be updated! -> Starting update
2026-01-30 10:14:00.832 [INFO ] [omation.openhab-js.BMW_Token_Refresh] - Starting token refresh...
2026-01-30 10:14:00.903 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - BMW API returned error
2026-01-30 10:14:00.903 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Code: invalid_request
2026-01-30 10:14:00.903 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Description: The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed
2026-01-30 10:14:00.903 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Full JSON Response: {"error": "invalid_request", "error_description": "The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed"}
2026-01-30 10:14:00.904 [WARN ] [omation.openhab-js.BMW_Token_Refresh] - First attempt failed with BMW API error. Will retry in 30 seconds.
2026-01-30 10:14:00.904 [WARN ] [omation.openhab-js.BMW_Token_Refresh] - Scheduling retry in 30 seconds...

The response looks good but it seems like BMW changed something, so the rule can“t read the parameters.

I“ll have a look.

BMW removed the parameter verification_uri_complete and the rule failed.
I changed it to verification_uri and combined it with the user_code manually.

New version is posted in first post.

Changes:
Line 206 - replace:
if (!jsonResponse.user_code || !jsonResponse.device_code || !jsonResponse.verification_uri_complete) {
if (!jsonResponse.user_code || !jsonResponse.device_code || !jsonResponse.verification_uri) {

Line 221 - replace:
logger.debug("Verification URI: " + jsonResponse.verification_uri_complete);
logger.debug("Verification URI: " + jsonResponse.verification_uri);

Line 230 - replace:
escapeTelegram(jsonResponse.verification_uri_complete) + "\n\n" +
escapeTelegram(verificationUrl) + "\n\n" +

Line 249 - replace:
logger.info(jsonResponse.verification_uri_complete);
logger.info(verificationUrl);

Line 223 - add:

var verificationUrl = jsonResponse.verification_uri + "?user_code=" + jsonResponse.user_code;```
1 Like

Hi,

the update is not functioning yet.

2026-01-30 18:22:30.702 [INFO ] [omation.openhab-js.BMW_Token_Refresh] - === RETRY ATTEMPT - Second try after initial failure ===
2026-01-30 18:22:30.703 [INFO ] [omation.openhab-js.BMW_Token_Refresh] - Starting token refresh...
2026-01-30 18:22:30.774 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - BMW API returned error
2026-01-30 18:22:30.775 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Code: invalid_request
2026-01-30 18:22:30.775 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Description: The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed
2026-01-30 18:22:30.775 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Full JSON Response: {"error": "invalid_request", "error_description": "The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed"}
2026-01-30 18:23:00.638 [INFO ] [hab-js.BMW_Token_Refresh_ExpireCheck] - current time: 30.01.2026 18:23:00, expiry of token: 24.01.2026 00:00:59
2026-01-30 18:23:00.638 [INFO ] [omation.openhab-js.BMW_Token_Refresh] - Token needs to be updated! -> Starting update
2026-01-30 18:23:00.639 [INFO ] [omation.openhab-js.BMW_Token_Refresh] - Starting token refresh...
2026-01-30 18:23:00.708 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - BMW API returned error
2026-01-30 18:23:00.709 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Code: invalid_request
2026-01-30 18:23:00.709 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Error Description: The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed
2026-01-30 18:23:00.709 [ERROR] [omation.openhab-js.BMW_Token_Refresh] - Full JSON Response: {"error": "invalid_request", "error_description": "The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed"}
2026-01-30 18:23:00.709 [WARN ] [omation.openhab-js.BMW_Token_Refresh] - First attempt failed with BMW API error. Will retry in 30 seconds.
2026-01-30 18:23:00.710 [WARN ] [omation.openhab-js.BMW_Token_Refresh] - Scheduling retry in 30 seconds...


Thatā€˜s the refresh, you need to start with the Token Setup.

Please check that your CarData Client is still active because the error points in the direction of an inactive CarData Client.

The provided access grant is invalid, expired, or revoked.

See steps 1 and 2 of the BMW Portal.