Script to access the BMW ConnectedDrive portal via OH

Hi,

cause I was not satified with the existing possibilties to access the car data of my BMW i3 in openhab, I’ve made the python script bmwcdapi.py
You can query various properties as the state of charge, the mileage and the remainig range.
For insiders, “socMax” can also be queried.

To use the script, you need a running OH2 instance and python3, a BMW ConnectedDrive login and, of course, a supported car. I’ve tested it with my BMW i3, but as far as I know, there are also other BMW’s that are supported by the ConnectedDrive portal.

All of the magic that the script needs to work is derived from https://github.com/sergejmueller/battery.ebiene.de

You’ll find bmwcdapi on

The installation is described in the readme.

9 Likes

Hi,

I’ve uploaded a new version of the script.

It’s now possible to execute services as to climate the car or lock / unlock it.
Also the error handling is slightly improved.

For those of you that are already using the script:
The naming of the OH-items was not very smart IMO, so I’ve renamed all items ( added leading “Bmw_”). That is a breaking change of course, but better now then never :slight_smile:

Great, Thanks for your efforts.
I will try it as soon as my BMW arrives :slight_smile:

BMW Integration

I posted something a while ago, have you seen this?

Hi, youre welcome.
If there are any problems, just drop me a line.

Not yet - Thanks for this link.
@peter_juenger:

You mention the i3, but I assume it works for all newer BMW with Connected Drive services?

I think that it works with all BMWs that could be adressed through CD, but I only own an i3, so I could not test it :slight_smile:
Maybe there are some other segments or properties for cars with combustion engine.
You could figure it out by calling the script directly from the shell with the “-p” parameter.
That prints out all available data.
If there are important things missing, just drop me a PR (or an example of the data) to add it.

Thanks, @peter_juenger .

Lucky you, that you have an i3.
I would prefer one, too, but I live in an appartment house from 1900 with no garage - so no charging option.

Anyway, as soon as I got mine and I have time to play I will update you if anything is missing.

Thanks again.

Just to let you know that it works like charm, I have accessed my i3 withing 15 minutes from starting the idea to implementation.
Many thanks for sharing.
I just have problem with the icons. I did put them into the icons dir but they do not display properly. Where do I put them to display nicely in BasicUI

Hi, nice to hear that it works out for you.

The icons are vector graphics (svg). To use them, copy them into your icon folder (mine is located under /etc/openhab2/icons/classic).

And than it is important to configure the basic UI (and maybe the openhab-app) to use vector icons. For the basic UI that can be done through paper UI. Just set “icon format” to vector under configuration / services / UI.

The icon thing is kind of strange, as I only have problems with them in Vivaldi , and after multiply purges of cache I still miss 2 icons (unlock and for car icon) In Chrome, Edge they are fine.

Is there a way to get the same nice icons in the Android app?

You only need to configure the vector icons in the app (SVG instead of PNG, it’s in the setting).
Regarding the Vivaldi problems, I have no idea.

Anyone has problems with the ConnectedDrive recently? 3 days ago the script stopped updating, but I look into the BMW portal over web and it is missing most of the information on the current range and SOC. Claims GPS possition is not activated in the car, while it is activated. I have error frames over charge schedule. but remote comands do work, so I can honk the car but that’s nothing else. Did they change something?

I also noticed some failures on the ConnectedDrive portal in the last few days.

But right now everything is back to normal here, so I think they didn’t change anything fundamental.

Ok so it got back to normal on my portal as well this morning. Must have been a 2 day failure on the BMW side.

Thanks for sharing this - just implemented it on my 2016 X5 30d. For a diesel vehicle obviously the EV related fields are not populated, also for some reason the mileage and remaining fuel figures are incorrect. But other than that I can send the lock, unlock, climate, light and horn commands just fine.

One field that I find very useful is gps_lat and gps_lng - you can combine these two in a new PointType item and use it in your presence / location rules if your car exposes them to you.

Also, instead of using simple switches and rules to send the lock, unlock etc commands, I have used switches linked to the Exec binding so there is no need for separate rules, and as a bonus, the switches revert back to OFF themselves.

Again, thanks for the work!
Yetkin

Yetkin, can you please share your items and provide examples of how you used the exec binding for it?
Many thanks!

Sure - assuming you have the Exec binding installed, first you need to define a thing for each command:

Thing exec:command:BMW_Refresh 		"BMW Script - Refresh Data"	[command="/home/yetkin/bmwcdapi.py", interval=600, timeout=30, autorun=false]
Thing exec:command:BMW_LockDoors 	"BMW Script - Lock Doors"	[command="/home/yetkin/bmwcdapi.py -e lock", interval=0, timeout=30, autorun=false]
Thing exec:command:BMW_UnlockDoors 	"BMW Script - Unlock Doors"	[command="/home/yetkin/bmwcdapi.py -e unlock", interval=0, timeout=30, autorun=false]
Thing exec:command:BMW_Climate 		"BMW Script - Climate"		[command="/home/yetkin/bmwcdapi.py -e climate", interval=0, timeout=30, autorun=false]
Thing exec:command:BMW_Lights 		"BMW Script - Lights"		[command="/home/yetkin/bmwcdapi.py -e light", interval=0, timeout=30, autorun=false]
Thing exec:command:BMW_Horn 		"BMW Script - Horn"			[command="/home/yetkin/bmwcdapi.py -e horn", interval=0, timeout=30, autorun=false]

Notice how interval = 600 on BMW_Refresh - that tells exec binding to automatically execute the command every 10 minutes, which means you won’t need a separate rule triggered via cron.

Then you need to define an item for each thing:

Switch  Bmw_Refresh         "Refresh Data"      <update>    (gBMW)  {channel="exec:command:BMW_Refresh:run"}
Switch  Bmw_Climate         "Climate"           <ac_unit>   (gBMW)  {channel="exec:command:BMW_Climate:run"}
Switch  Bmw_LockDoors       "Lock Doors"        <lock>      (gBMW)  {channel="exec:command:BMW_LockDoors:run"}
Switch  Bmw_UnlockDoors     "Unlock Doors"      <lock_open> (gBMW)  {channel="exec:command:BMW_UnlockDoors:run"}
Switch  Bmw_Lights          "Lights"            <light>     (gBMW)  {channel="exec:command:BMW_Lights:run"}
Switch  Bmw_Horn            "Horn"              <horn>      (gBMW)  {channel="exec:command:BMW_Horn:run"}

One thing that I would add to the scripts (i3 specific) would a switch for the “charge immediately/off peak charging”

Had multiple cases that I left a car with home settings (off-peak) on a public charger and it did not charge. I could have openhab detect this case and send me a notification on my Telegram home alert channel.

1 Like

Thank you @peter_juenger for the work.

It works nicely.
Just some details which can help those who want to install it:

  • python3 needs to be installed but also chosen as the default python environment
  • Exec binding needs to be version 1.13. I have both version (2.4 and 1.13 installed without issue).