# Script to access the BMW ConnectedDrive portal via OH

**URL:** <https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345>\
**Category:** Solutions\
**Tags:** bmwi3, bmw, carintegration\
**Created:** [December 16, 2017, 12:00pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345 "2017-12-16T12:00:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [December 16, 2017, 12:00pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/1 "2017-12-16T12:00:36Z")

</div>

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](https://github.com/sergejmueller/battery.ebiene.de)

You’ll find bmwcdapi on

> **[GitHub - jupe76/bmwcdapi: a python script to access the BMW ConnectedDrive...](https://github.com/jupe76/bmwcdapi)**
>
> a python script to access the BMW ConnectedDrive portal in openhab

The installation is described in the readme.

---

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [January 14, 2018, 7:47pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/2 "2018-01-14T19:47:08Z")

</div>

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 🙂

---

<div class="post-metadata">

**Author:** ![NCO](https://community.openhab.org/user_avatar/community.openhab.org/nco/32/55938_2.png) [@NCO](https://community.openhab.org/u/NCO)\
**Post date:** [January 25, 2018, 11:23am UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/3 "2018-01-25T11:23:24Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Maximo](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/cab0a1/32.png) [@Maximo](https://community.openhab.org/u/Maximo)\
**Post date:** [January 25, 2018, 12:31pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/4 "2018-01-25T12:31:56Z")

</div>

[BMW Integration](https://community.openhab.org/t/bmw-integration-with-openhab/21701?source_topic_id=31638)

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

---

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [January 25, 2018, 9:33pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/5 "2018-01-25T21:33:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![NCO](https://community.openhab.org/user_avatar/community.openhab.org/nco/32/55938_2.png) [@NCO](https://community.openhab.org/u/NCO)\
**Post date:** [February 10, 2018, 3:21pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/6 "2018-02-10T15:21:38Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [February 10, 2018, 4:27pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/7 "2018-02-10T16:27:50Z")

</div>

> [@NCO](#):
>
> 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 🙂  
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.

---

<div class="post-metadata">

**Author:** ![NCO](https://community.openhab.org/user_avatar/community.openhab.org/nco/32/55938_2.png) [@NCO](https://community.openhab.org/u/NCO)\
**Post date:** [February 14, 2018, 6:09am UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/8 "2018-02-14T06:09:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xsherlock](https://community.openhab.org/user_avatar/community.openhab.org/xsherlock/32/37207_2.png) [@xsherlock](https://community.openhab.org/u/xsherlock)\
**Post date:** [March 7, 2018, 2:05pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/9 "2018-03-07T14:05:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [March 7, 2018, 6:24pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/10 "2018-03-07T18:24:39Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xsherlock](https://community.openhab.org/user_avatar/community.openhab.org/xsherlock/32/37207_2.png) [@xsherlock](https://community.openhab.org/u/xsherlock)\
**Post date:** [March 14, 2018, 9:56pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/11 "2018-03-14T21:56:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [March 15, 2018, 9:00pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/12 "2018-03-15T21:00:05Z")

</div>

> [@xsherlock](#):
>
> 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.

---

<div class="post-metadata">

**Author:** ![xsherlock](https://community.openhab.org/user_avatar/community.openhab.org/xsherlock/32/37207_2.png) [@xsherlock](https://community.openhab.org/u/xsherlock)\
**Post date:** [April 11, 2018, 9:11pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/13 "2018-04-11T21:11:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![peter\_juenger](https://community.openhab.org/letter_avatar_proxy/v4/letter/p/f08c70/32.png) [@peter\_juenger](https://community.openhab.org/u/peter_juenger)\
**Post date:** [April 12, 2018, 6:08am UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/14 "2018-04-12T06:08:07Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![xsherlock](https://community.openhab.org/user_avatar/community.openhab.org/xsherlock/32/37207_2.png) [@xsherlock](https://community.openhab.org/u/xsherlock)\
**Post date:** [April 12, 2018, 8:39am UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/15 "2018-04-12T08:39:52Z")

</div>

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.

 ![2018-04-12%2010_35_59-Photos](https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/9/a/9aa099fae7d9533cdd732475cdcb298164a385f5.png)

---

<div class="post-metadata">

**Author:** ![yetkin](https://community.openhab.org/letter_avatar_proxy/v4/letter/y/97f17d/32.png) [@yetkin](https://community.openhab.org/u/yetkin)\
**Post date:** [April 30, 2018, 12:51pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/16 "2018-04-30T12:51:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Moshe\_Dahan](https://community.openhab.org/letter_avatar_proxy/v4/letter/m/d26b3c/32.png) [@Moshe\_Dahan](https://community.openhab.org/u/Moshe_Dahan)\
**Post date:** [April 30, 2018, 3:00pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/17 "2018-04-30T15:00:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yetkin](https://community.openhab.org/letter_avatar_proxy/v4/letter/y/97f17d/32.png) [@yetkin](https://community.openhab.org/u/yetkin)\
**Post date:** [April 30, 2018, 5:01pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/18 "2018-04-30T17:01:57Z")

</div>

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

```auto
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:

```auto
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"}

```

---

<div class="post-metadata">

**Author:** ![xsherlock](https://community.openhab.org/user_avatar/community.openhab.org/xsherlock/32/37207_2.png) [@xsherlock](https://community.openhab.org/u/xsherlock)\
**Post date:** [May 21, 2018, 1:15pm UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/19 "2018-05-21T13:15:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Fa\_Bien](https://community.openhab.org/letter_avatar_proxy/v4/letter/f/c4cdca/32.png) [@Fa\_Bien](https://community.openhab.org/u/Fa_Bien)\
**Post date:** [January 9, 2019, 9:57am UTC](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345/20 "2019-01-09T09:57:26Z")

</div>

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).

[Next page](https://community.openhab.org/t/script-to-access-the-bmw-connecteddrive-portal-via-oh/37345.md?page=2)
