Did you configure your telegram items that contain the reply ID and last message text?
Yes, I double-checked and when I send messages from my phone to the bot they appear in the Last Message item. I also tried deleting the client on the BMW portal and creating a new one with a new Client ID. Still nothing. I guess Iām missing something on my system, compared to yours.
So you set your Client_ID and then you don“t receive a Telegram message?
Could you please open the log viewer and filter for bmw.
When you change or update your Client_ID item, you should see this message:
Starting BMW Device Code Flow for Client ID:
Iām not used to working with file based rules and might be doing something silly here. So before i try again, letās make sure files are in the right place.
I assume i should have:
$OPENHAB_CONF/automation/js/BMW_Token_Setup.js
$OPENHAB_CONF/automation/js/BMW_ID_Token_Updates.js
$OPENHAB_CONF/items/carBMW.items
Correct?
Yes looks good.
Does you log say something like āRule loaded: BMW Token Setup - Step 1 ā¦ā?
Do you have the Javascript Scripting installed?
Itās an option of openHABian and includes openhab-js.
Javascript Scripting is installed.
Steps taken and log output:
Created $OPENHAB_CONF/items/carBMW.items
22:12:41.784 \[INFO \] \[del.core.internal.ModelRepositoryImpl\] - Loading model ācarBMW.itemsā
Created $OPENHAB_CONF/automation/js/BMW_Token_Setup.js
[
INFO \] \[port.loader.AbstractScriptFileWatcher\] - (Re-)Loading script ā/etc/openhab/automation/js/BMW_Token_Setup.jsā
\[INFO \] \[g.openhab.automation.openhab-js.rules\] - Adding rule: BMW Token Setup - Step 1: Device Code Request
\[INFO \] \[g.openhab.automation.openhab-js.rules\] - Adding rule: BMW Token Setup - Step 1.5: Handle Telegram Reply
\[INFO \] \[g.openhab.automation.openhab-js.rules\] - Adding rule: BMW Token Setup - Step 2: Token Request
At this point i do for 1.2 openHAB Telegram in the instructions step 1,2,3 and put the Client_ID into the openHAB item carBMW_Client_ID
\[INFO \] \[del.core.internal.ModelRepositoryImpl\] - Loading model ācarBMW.itemsā
Then i would expect things starting to happen but nothing does. I donāt see the message
Starting BMW Device Code Flow for Client ID:
But you see logs that your carBMW_Client_ID was updated/changed to the new value?
The trigger listens to an update to the item.
triggers.ItemStateUpdateTrigger(clientIDItem)
When i change the Client_ID, i see in the log āLoading model ācarBMW.itemsāā, but not that the carBMW_Client_ID was updated/changed to the new value explicitly. The value in the item changes, though.
I“m not sure what you“re doing
The carBMW.items file shouldn“t be reloaded when you change the state of carBMW_Client_ID.
Just to make sure, how do you set your Client_ID?
There are different ways to set the state and i don“t know which one you“re using.
You could use the API Explorer inside the Main UI.
- Open
http://<openHAB>:8080/developer/api-explorer - On a second tab open
http://<opeNHAB>:8080/developer/log-viewer
replace<openHAB>with the hostname or ip-address of your oH instance - Open Items and search for
PUT - /items/{itemname}/stateand open it. - Click on
Try it out, entercarBMW_Client_IDas itemname and your Client_ID asRequest body. - Click on execute
- Open the log viewer tab and filter for
bmw
Do you see an entry like openhab.event.ItemStateUpdatedEvent Item 'carBMW_Client_ID' updated to 1234567890?
I had been editing carBMW.items directly with vi over an ssh connection. Told you i might be doing something silly ![]()
All works now, i have a stable connection with the BMW broker and have watched the token being refreshed a couple of times. Now itās just a matter of configuring channels/topics.
Thereās quite some logging going on though, but i guess i could just comment out the relevant lines in BMW_Token_Refresh.js for that.
Thanks a million, finally thereās a fire-and-forget solution for communicating with the bimmer now! ![]()
Perfect!
For the logging, just change all references of logger.info to logger.debug
@Bredmich Hi, today I noticed that problem with refreshing token begin. I have such line in the logs:
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ā}
When i had these errors it was coming from the BMW backend.
You can try to setup a new Token but youāll probably receive the same error for a few hours.
My tokens has been refreshed for three weeks now.
Did you stop and start the openhab service in these three weeks? This may be coincidential: after restarting the openhab service tonight, the bmw broker first came online without problems. But when the tokens needed to be refreshed after half an hour, i got this:
22:06:00.956 \[INFO \] \[tomation.openhab-js.BMW_Token_Refresh\] - Token needs to be updated! ā Starting update
22:06:00.991 \[ERROR\] \[tomation.openhab-js.BMW_Token_Refresh\] - Exception during token refresh: TypeError: null has no such function ātoStringā
Iāll leave it for now and see if it recovers.
Yes, multiple times.
It always recovers.
You should try to do the setup again, as the tokens are probably aleady expirer. Including the refresh token.
Doing the setup again worked smoothly, however this āeventā resulted in trying to refresh the token every 30 seconds (is that supposed to happen?), exceeding my bmw quota and spamming the Telegram bot all day as a result. Iāll try again when theyāve recovered a bit
Not sure if it was the OH restart that triggered this or a glitch at bmw.
Strange behavior.
Iām currently out of office and canāt check it.
Thx a lot, works like a charme.
We got our new BMW yesterday and immediately tried this out.
First I went the manual way and was not successful, then I tried the Telegram way and it worked out of the box.
Without your work I would never have been able to find out myself.
Are you sure it comes from refreshing the token? I had a similar problem with a syntax error in one of the Channels and the log messages came from MQTT trying to reconnect, which was not possible because of the syntax error.
I commented out the Items with the Channel linking one by one until I found the bad one ā¦
I had a strange bug today, but it“s not openHAB related.
Just want to make you aware of it since some use the location of the car for rules.
I went to a shop, stopped the engine, opened the trunk and unloaded something.
The war was not locked while i did this and the whole stop took around 10 minutes.
After this stop, the car stopped sending data to the backend.
I just noticed this at home, as the car was still showing were i stopped to unload.
The MyBMW app also showed the car at this location and the trunk as open.
I used the app to send a locking command and this updated the data.
Seems like a stop without locking can potentially interrupt the connection between the car and the backend.
It looks like 2 Items are missing in your Items example in 3.1 (although setup worked without them):