BMW i3 in Smart Home

BMW i3 in Smart Home

In this article, we will show how to get information about the BMW i3 into a tablet using OpenHAB. Of course, you can use the MyBMW app, but with the API, we have the opportunity to customize the interface, display simple dashboard with all information on a single page. It is also possible to send supported commands via the API, such as opening, closing, starting the air conditioning/heater, etc., and, most importantly, to integrate these actions with a smart home system.

Examples of usage:

- automatically locking the car at 10:00 PM if we are at home

- voice commands via Alexa - air conditioning, opening/close

- alarm - flashing lights in case of movement in the garden based on security cam or pir, etc.

 

Hardware

Pi-Home - if you don’t have it, see the section How to

Ideally, a tablet in a central room or Alexa if needed

Software

OpenHAB 4

Steps:

1) Install the MyBMW binding in OpenHAB

MyBMW Binding OpenHAB

2) Create a bridge Things -> MyBMW -> MyBMWAccount

MyBMW SmartHome  Edit: In the new version, the Account also has a Captcha token. Simply click on the link: 

https://bimmer-connected.readthedocs.io/en/stable/captcha/rest_of_world.html

confirm that you are not a robot and generate a token. Copy the token and paste it into the required field in OpenHAB. Save.

The newly added thing BMWAccount should turn green with the status "Online".

 

3) Add the car through Things -> MyBMW -> Electric vehicle. Don’t forget to enter the real VIN of your vehicle.

BMW i3 OpenHAB

 

After clicking on the thing of the added car, the status should turn green to "Online." Click on Channels. From them, you can then create Items. Not all Channels are supported; you can try creating all of them and then determine which ones are active. If you are satisfied with what we have in our dashboard, you can also add the Items all at once using the text below (Developer Tools -> Add Items from Textual Definition).

Group    CarBMW                      "BMW"                                (bmw)    ["Equipment"]
Image    BMWRenderedVehicleImage     "BMW Image"                          (CarBMW) ["Point"] { channel="mybmw:bev:bmwaccount:bmwi3:image#png" }
Number   BMWBatteryChargeLevel       "Battery Charge Level [%.0f%]"      (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:range#soc"}
Number   BMWElectricRange            "Electric Range"                     (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:range#electric"}
String   BMWPlugConnectionStatus     "Plug Connection Status"             (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:status#plug-connection"}
String   BMWChargingStatus           "Charging Status"                    (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:status#charge"}
Number   BMWChargingRemainingTime    "Remaining Charging Time [%.0f min]" (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:status#charge-remaining"}
String   BMWDoorsStatus              "Overall Door Status"                (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:status#doors"}
String   BMWWindowsStatus            "Overall Window Status"              (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:status#windows"}
String   BMWDoorsLocked              "Doors Locked"                       (CarBMW) ["Point"] {channel="mybmw:bev:bmwaccount:bmwi3:status#lock"}
Switch   BMWLock                     "Lock"                               (CarBMW)           {expire="1s,command=OFF"}
Switch   BMWUnlock                   "Unlock"                             (CarBMW)           {expire="1s,command=OFF"}
Switch   BMWLights                   "Lights"                             (CarBMW)           {expire="1s,command=OFF"}
Switch   BMWClimateStart             "Climate Start"                      (CarBMW)           {expire="1s,command=OFF"}

Copy the above Items. Be careful with the name of the Channel; if you changed the ID for the BMWAccount or BMWi3 thing, adjust accordingly.

4) Now you can create a Dashboard. In Settings -> Pages, create a new page and arrange the fields. If you want to save time and like our dashboard, go to the Code tab and copy the code below:

 config:
  label: Car
  order: ""
  sidebar: true
blocks:
  - component: oh-block
    config: {}
    slots:
      default:
        - component: oh-grid-cells
          config: {}
          slots:
            default:
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        action: navigate
                        actionPage: page:overview
                        label: Back to Main Page
        - component: oh-grid-row
          config: {}
          slots:
            default: []
  - component: oh-block
    config: {}
    slots:
      default:
        - component: oh-grid-row
          config: {}
          slots:
            default:
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-gauge-card
                      config:
                        borderColor: "#2196f3"
                        borderWidth: "20"
                        item: BMWBatteryChargeLevel
                        max: 100
                        min: 0
                        size: 200
                        type: semicircle
                        valueFontSize: "30"
                        valueTextColor: "#2196f3"
                        title: Current Battery Status
                        action: analyzer
                        actionAnalyzerItems:
                          - BMWBatteryChargeLevel
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-image-card
                      config:
                        item: BMWRenderedVehicleImage
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-list-card
                      config: {}
                      slots:
                        default:
                          - component: oh-label-item
                            config:
                              item: BMWDoorsStatus
                              title: Doors
                          - component: oh-label-item
                            config:
                              item: BMWWindowsStatus
                              title: Windows
                          - component: oh-label-item
                            config:
                              item: BMWDoorsLocked
                              title: Status
                          - component: oh-label-item
                            config:
                              item: BMW_i3_Check_Control
                              title: Errors
                          - component: oh-label-item
                            config:
                              item: BMW_i3_Total_Distance_Driven
                              title: Total Distance Driven
                              action: analyzer
                              actionAnalyzerItems:
                                - BMW_i3_Total_Distance_Driven
                          - component: oh-label-item
                            config:
                              item: BMW_i3_Address
                              title: Current Location
  - component: oh-block
    config: {}
    slots:
      default:
        - component: oh-grid-row
          config: {}
          slots:
            default:
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        item: BMWElectricRange
                        label: =items.BMWElectricRange.displayState
                        title: Current Range
                        trendItem: BMWElectricRange
                        action: analyzer
                        actionAnalyzerItems:
                          - BMWElectricRange
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        action: command
                        actionItem: BMWLock
                        icon: iconify:icon-park-solid:lock
                        iconUseState: false
                        iconSize: 50
                        actionCommand: ON
                        vertical: true
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        action: command
                        actionItem: BMWUnlock
                        icon: iconify:icon-park-solid:unlock
                        iconUseState: false
                        iconSize: 50
                        actionCommand: ON
                        vertical: true
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        action: command
                        actionItem: BMWClimateStart
                        icon: iconify:mingcute:fan-fill
                        iconUseState: false
                        iconSize: 50
                        actionCommand: ON
                        vertical: true
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        action: command
                        actionItem: BMWLights
                        icon: iconify:mdi:car-light-high
                        iconUseState: false
                        iconSize: 50
                        actionCommand: ON
                        vertical: true
        - component: oh-grid-row
          config: {}
          slots:
            default:
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        item: BMWPlugConnectionStatus
                        title: Charger
                        fontSize: 20px
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: oh-label-card
                      config:
                        title: Charging Status
                        item: BMWChargingStatus
                        fontSize: 20px
              - component: oh-grid-col
                config: {}
                slots:
                  default:
                    - component: widget:widget_remainingchargingtime
                      config: {}
masonry: []
grid: []
canvas: []

Copy the above Items. Be mindful of the Channel names; if you changed the ID for the BMWAccount or BMWi3 thing, adjust them as needed.

Now you can create a Dashboard. In Settings -> Pages, create a new page and arrange the fields. If you want to save time and like our dashboard, switch to the Code tab and copy the following code below:

And that's it. It should be functional; if not, feel free to write in the comments. The last thing: to make the buttons for unlocking, locking, flashing, and climate control work, we’ll add a rule that sets the RemoteCommand based on the button pressed. Add a new rule in Rules.
Go to the Code tab and copy the rule's source code.

configuration: {}
triggers:
  - id: "2"
    configuration:
      itemName: BMWLock
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
  - id: "3"
    configuration:
      itemName: BMWUnlock
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
  - id: "4"
    configuration:
      itemName: BMWLights
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
  - id: "8"
    configuration:
      itemName: BMWClimateStart
      state: ON
      previousState: OFF
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "1"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: "if(BMWLock.state == ON){

        \   sendCommand(BMW_i3_Remote_Command, \"door-lock\")

        \   }

        if(BMWUnlock.state == ON){

        \   sendCommand(BMW_i3_Remote_Command, \"door-unlock\")

        \   }

        if(BMWLights.state == ON){

        \   sendCommand(BMW_i3_Remote_Command, \"light-flash\")

        \   }

        if(BMWClimateStart.state == ON){

        \   sendCommand(BMW_i3_Remote_Command, \"climate-now-start\")

        \   }\

        \  "
    type: script.ScriptAction

It should look something like this:

BMW Rule OpenHAB

 

Done. Test the functionality. Sometimes a command fails, especially if you send multiple commands in quick succession. This is not recommended. In Items, there is also an entry called BMW Service_Execution_State where you can check the processing status of sent commands. Occasionally, you may see an Error 403, but the information still reaches the car. Charge Start/Stop doesn’t work for me, so I haven’t included it. I’d appreciate your experiences and practical use cases in the comments.

 BMW i3 Dashboard

 

Bonus: For Time to full battery field we are using a special widget which transform minutes to hours and minutes or say N/A if car is not on charger. You can add widget in Developer Tools -> Widgets. Create new and import code below:

uid: widget_remainingchargingtime
tags: []
props:
  parameters:
    - description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: item
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Jan 4, 2025, 9:34:49 PM
component: f7-card
config:
  item: DurationInMinutes
  content: '=(items["BMWChargingRemainingTime"].state === "NULL"
    ||  items["BMWChargingRemainingTime"].state === "UNDEF" ? "N/A" :
    Math.floor(items["BMWChargingRemainingTime"].state / 60) + "h " +
    (items["BMWChargingRemainingTime"].state % 60) + "m")'
  title: Time to full battery
  style:
    font-size: 22px
    text-align: center

Rate the article:

No votes yet

Support Us:

Add comment:

Add comment

Newest articles in blog

BMW i3 Tablet
BMW i3 in Smart HomeRating: 
0%

In this article, we will show how to get information about the BMW i3 into a tablet using OpenHAB. Of course, you can use the MyBMW app, but with the API, we have the opportunity to customize the interface, display simple dashboard with all information on a single page. It is also possible to send supported commands via the API, such as opening, closing, starting the air conditioning/heater, etc., and, most importantly, to integrate these actions with a smart home system.

Tailscale - remote access without public IP
Tailscale - remote access without public IPRating: 
90%

The Tailscale service solves access between individual devices if you don't have a public IP address. It's free for one user with support for up to 100 devices. We'll show you how to install Tailscale on a Raspberry Pi that you'll have at home and on a client (Android, iPhone) from which you'll want to access the home Raspberry Pi. Our example will be remote access to OpenHAB running on a Raspberry Pi. However, the same setup applies to many other applications - home NAS, PiHole, Home Assistant, Domoticz, NextCloud, and others.

Shelly OpenHAB MQTT
Shelly vs OpenHABRating: 
90%

The Shelly brand is known for its products that primarily communicate over WiFi, including smart plugs, relay switches, blinds control relays, and many other devices. One of the advantages for deployment is the ability to both read and control these devices using the universal MQTT protocol. Across existing add-ons for both OpenHAB and Home Assistant, we will demonstrate how to use Shelly devices without installing any additional extensions.

Victron & OpenHAB
Victron vs Smart HomeRating: 
0%

In this post, we will show you how to retrieve information from a photovoltaic power plant by Victron. We will connect to the Cerbo unit via MQTT. Based on these values, we can control various appliances (heating, boiler, etc.) and prevent the battery from being drained when they don't need to be.

Smart Home GoodWe inverter
Smart Home vs GoodWeRating: 
50%

In the post, we will demonstrate step by step how to communicate directly with the GoodWe inverter in a smart home setup and obtain real-time information (unlike the SEMS portal). This information is essential if we want to react to current parameters in a smart home, such as activating additional cooling or controlling a socket with a various load.

Voice control smart home
Voice control of the houseRating: 
60%

In this article, we will connect the Amazon Echo Dot voice assistant with open source home automation. We won't be using OpenHAB Cloud, so everything runs locally. In this case, a few additional settings are necessary, but the result is worth it!

MikroTik - Winbox, DHCP, Ranges
Basics - Winbox, DHCPRating: 
68.8%

In this series, we will look at the step-by-step setup of MikroTik devices for home users or a small business (up to 25 people). In the first article, we will focus on the initial setup - we will download Winbox and set up DHCP for the primary network and guest network. Similarly, we will also adjust the WiFi settings.

Alarm Smart Home PIR
Alarm from existing PIR sensors in a smart home.Rating: 
0%

In a your smart home, PIR sensors may not only be used to switch lights on and off based on motion, it is possible to utilize these sensors to detect the presence of motion in a particular room. This information can be used to create a relatively reliable uncertified home security system. In this guide, you will find the logic for how this can work in the OpenHAB software in our model smart home.

NFC Tag Example in Smart Home
NFC tags in smart homeRating: 
80%

NFC (Near Field Communication) tags are small plastic or paper stickers that can be used to automate various functions in the smart home. In this article, we will show you examples of use and a guide on how to write an action on an NFC tag using a mobile phone.

WireGuard iOS
WireGuard on iOS devicesRating: 
88%

In this article, you will find a detailed guide on how to connect to WireGuard VPN from iOS.