BMW Motorrad connected

Hi, I’m interested in the integration of BMW Motorrad connect (it is the stadnard system for BMW GS bikes) and a mobile App is already available to monitor our bikes. Anybody interested in?

noone have info about this ? this would a good implementation

2 Likes

Definitely same app is used for S1000RR

Hi, sure, I am very interested. Did you find some sort of integration meanwhile?
Thank you

No integration yet, however with a rooted device you can extract/push some data to home assistant using the rest api

Hi, I am also interested in the integration.

@Careliyim Thanks for the info, I will integrate it that way for the moment.

I have integrated the alarm that I installed on the bike, this way I have real time position and also alarm status, battery and ignition (to open the garage door when I start the bike :D).

1 Like

@ferremontagud

Looks nice I was not able to get the buildin Alarm system status from the connected app however the real time position I do.

For the garage door I have the yaml below, It checks the state of the garage door and if I am connected with the motorcycle for at least x amount of time and if the trigger did not already run x minutes ago just to catch false and duplicated triggers. It triggers only when I get home while connected to the bike (works great)

Because I always forget the tire pressure I have added the double dual-gauge-card (see screenshot)
:smiley:

Did you get the data of the battery voltage as well would like to know how?

Hope it helps, please share if you get any improvements or futures :smiley:

`alias: motorhome
description: “”
trigger:

  • platform: state
    entity_id:
    • person.ME
      to: home
      from: not_home
      condition:
  • condition: template
    value_template: >-
    {{ (now()|as_timestamp -
    state_attr(‘automation.stest’,‘last_triggered’)|as_timestamp) > 900 }}
  • condition: state
    entity_id: sensor.btcondev23
    state: “True”
    enabled: true
  • condition: state
    entity_id: cover.garage_door
    state: closed
  • condition: template
    enabled: true
    value_template: |-
    {% set last_changed = states.sensor.btcondev23.last_changed %}
    {% set connected = is_state(‘sensor.btcondev23’, ‘True’) %}
    {% if last_changed and connected %}
    {% set true_duration = now().timestamp() - as_timestamp(last_changed) %}
    {% set true_threshold = 480 %}
    {{ true_duration >= true_threshold }}
    {% else %}
    False
    {% endif %}
    action:
  • service: notify.mobile_app_s23_ultra
    data:
    message: Motorcylce opening GARAGE
    title: Entering Home with Motorcylce opening GARAGE
    data:
    clickAction: /lovelace/garage
    url: /lovelace/garage
  • service: cover.open_cover
    data: {}
    target:
    entity_id: cover.garage_door
    mode: single`

Hi cool thing, could you go a liitle bit more into detail what you mean with the rest api? Which api can be used? Would be very interested in your setup.

To also share what I did so far: an automation for openning bike garage door when reaching home, while phone being connected to bike and/or connected ride cradle

alias: Motorradgarage öffnen
description: >-
  Öffne die Garage bei Heimkehr mit BMW F900R und schicke eine Benachrichtigung ansHandy
trigger:
  - platform: zone
    entity_id: person.me
    zone: zone.home
    event: enter
condition:
  - condition: template
    value_template: >-
      {{ "BC:42:XX:XX:E8:11 (ICC6.5in)" in
      state_attr("sensor.pixel_6_bluetooth_connection",
      "connected_paired_devices") }}
action:
  - service: script.toggle
    data: {}
    target:
      entity_id: script.<script for openning garage door>
  - service: notify.mobile_app_pixel_6
    data:
      message: >-
        Garage wurde geöffnet, da Du mit deiner BMW wieder heimgekommen bist
        🆙🔝
      title: Motoradgarage wurde geöffnet! 🏍️🅿🏡
mode: single

Having data of the bike itself as you do @Careliyim would be great. You said one needs a rooted (android) device? Is there no other way to grab the data?
I think if there’s an api for that, setting up a custom integration wouldn’t be that hard

I googled a lot now, but did not find anything, maybe you could help me out

Any update on this. I’d love to have this enabled in Home Assistant.

1 Like

How?
could you please provide some more information about?
Many thanks

1 Like

Hi @Careliyim

Unfortunately, I cannot find any documentation on the rest API.
Can you help me find the documentation or share your yaml?

Thank you very much

I would really like to get this to work as well. Anyone have updated information?

Hi @ferremontagud, which alarm have you installed in your BWM? Does that alarm allow you to link with Home assistant? Can you explain in more detail or do you have a GitHub repo? Thanks!

Hey @Careliyim, some pointers on how you managed to extract your bike-data would be so helpful to us mere mortals :wink:

Love to hear how you did that. I have a (electric) BMW EC04 from which the battery status would be very nice to have in HomeAssistant.

1 Like

Its more a custom script that I have build, which extracts the data from the bmw app itself then sends it to home assistant

1 Like

Hey dramsauer

I also noticed the data is readable from https://www.bmw-motorrad.nl/nl/my-bmw-motorrad.html#/my-bike/

this could be usable for home assistant if a automatisation could be generated to retreive the data

The current setup that I build:

Is using termux (on a rooted device) which gets the data from the bmw app extracts the data and then uses Macrodroid to run an action when the bt device (motor) is disconnected to push the data to home assistant by the curl an jq commands

In order to accomplish this we need to prefedine entities in home assistant first
like something below

sensor:

  • platform: template
    sensors:
    bmw_tirepresure_front:
    friendly_name: “Presure Front”
    unit_of_measurement: ‘Bar’
    value_template: “{{ states(‘input_number.bmw_tirepresure_front’)|float|round(2) }}”
    icon_template: mdi:car-brake-worn-linings

  • platform: template
    sensors:
    bmw_tirepresure_rear:
    friendly_name: “Presure Rear”
    unit_of_measurement: ‘Bar’
    value_template: “{{ states(‘input_number.bmw_tirepresure_rear’)|float|round(2) }}”
    icon_template: mdi:car-brake-worn-linings

  • platform: template
    sensors:
    s1000_fuel:
    friendly_name: “Fuel Level”
    unit_of_measurement: ‘%’
    value_template: “{{ states(‘input_number.bmw_current_fuel’)|float|round(2) }}”
    icon_template: mdi:gas-station

  • platform: template
    sensors:
    s1000_remaining:
    friendly_name: “Remaining KM”
    unit_of_measurement: ‘Km’

    value_template: “{{ states(‘input_number.bmw_remaining_km’) }}”

    value_template: "{{ states('input_number.bmw_remaining_km')| float / 1000 }}"
    icon_template: mdi:signal-distance-variant
    
  • platform: template
    sensors:
    s1000_total_km:
    friendly_name: “Total KM”
    unit_of_measurement: ‘Km’
    icon_template: mdi:map-marker-distance

    value_template: “{{ states(‘input_number.bmw_total_mileage’)[:-3] }}”

    #value_template: "{{ states('input_number.bmw_total_mileage')| float / 1000}}"
    value_template: "{{ states('input_number.bmw_total_mileage')| float / 1000| float * 0.001}}"
    
  • platform: template
    sensors:
    accurate_speed_23:
    friendly_name: “accurate_speed_23”
    unit_of_measurement: ‘Km/h’
    icon_template: mdi:speedometer
    value_template: “{{ state_attr(‘device_tracker.user_fold6’, ‘velocity’) }}”

Once you extract the data from the data folder com.bmw.ConnectedRide/databases/ on the android manupulate it to your like and post it to the home assistant.

To get the accurate speed of the bike isn’t trough gps I used another app (Owntrack) to get the velocity.

To clearup the questions on APi request I am sending the data to home assistant with curl for android and using the API of home assistant not the api of bmw or anything to retrieve the data.

If someone could automate the login process from https://www.bmw-motorrad.nl/nl/my-bmw-motorrad.html#/my-bike/ and get the data from there it would make live so much more easy.

Hello @ Careliyim,

Could you explain to us better, and in detail, the procedure to follow with the Termux and Macrodoid apps?

Thanks

Extracting and Posting BMW ConnectedRide Data to Home Assistant

This tutorial explains how to extract data from the locally stored BMW ConnectedRide database, convert it into a JSON format, and post it to Home Assistant. The process consists of three stages:

  1. Extract data from the appsyncstore file
  2. Convert it into a JSON file
  3. Post the extracted data to Home Assistant

Prerequisites

  • Termux installed on your Android device
  • jq installed for JSON processing
  • Home Assistant set up with the correct API endpoint
  • Your Home Assistant API token

Extract Data from the BMW ConnectedRide file

#!/bin/sh

# Add necessary paths to the environment
export PATH=/data/data/com.termux/files/usr/bin:$PATH

# Copy data to avoid interfering with the live app
echo "Copying database file..."
cp /data/data/com.bmw.ConnectedRide/databases/appsyncstore /data/data/com.termux/files/home/

# Fix folder permissions
echo "Setting file permissions..."
chmod -R 777 /data/data/com.termux/files/home/appsyncstore

# Wait for the process to complete
sleep 4;

# Extract data and convert to JSON
echo "Extracting relevant data and creating JSON file..."
grep -oP '{"*typename":"CloudBike".*?"_deleted":null}' /data/data/com.termux/files/home/appsyncstore -a |
jq -s '[.[] | select(.["*typename"] == "CloudBike")] | last' > /data/data/com.termux/files/home/data.json

# Verify extraction
echo "Data extraction completed! JSON saved as data.json."

Make the script executable and run it:

Step 2: Extract Key Data Points

Create Another Script to Post Data

Save the following script as bmw_post_to_ha.sh :

#!/bin/sh

# Define Home Assistant API URL
HA_URL="https://myHA-hostnameapi/states/"
HA_TOKEN="Your_HA_Token_Here"

# Read extracted JSON data
data=$(cat /data/data/com.termux/files/home/data.json)

# Extract key values
fuel_level=$(echo "$data" | jq -r '.fuelLevel')
remaining_range=$(echo "$data" | jq -r '.remainingRange')
total_mileage=$(echo "$data" | jq -r '.totalMileage')
tire_pressure_front=$(echo "$data" | jq -r '.tirePressureFront')
tire_pressure_rear=$(echo "$data" | jq -r '.tirePressureRear')
last_connected_lat=$(echo "$data" | jq -r '.lastConnectedLat')
last_connected_lon=$(echo "$data" | jq -r '.lastConnectedLon')
formatted_date=$(date +'%d %B %Y, %H:%M:%S')

# Function to send data to Home Assistant
send_to_ha() {
  entity_id=$1
  state_value=$2
  attributes=$3
  
  curl -X POST "$HA_URL$entity_id" \
    -H "Authorization: Bearer $HA_TOKEN" \
    -H "Content-Type: application/json" \
    -d "{\"state\": \"$state_value\", \"attributes\": $attributes}"
}

# Send extracted values to Home Assistant
send_to_ha "input_number.bmw_current_fuel" "$fuel_level" '{"unit_of_measurement": "%", "icon": "mdi:gas-station", "friendly_name": "Fuel Level"}'

send_to_ha "input_number.bmw_remaining_km" "$remaining_range" '{"unit_of_measurement": "Km", "icon": "mdi:signal-distance-variant", "friendly_name": "Remaining Km", "min": 0, "max": 999999, "step": 1, "mode": "box"}'

send_to_ha "input_number.bmw_total_mileage" "$total_mileage" '{"unit_of_measurement": "Km", "icon": "mdi:map-marker-distance", "friendly_name": "Total Km"}'

# Completion message
echo "Data successfully sent to Home Assistant!"
  • The first script extracts BMW ConnectedRide data and converts it into a structured JSON file.
  • The second script extracts specific data points and posts them to Home Assistant.
  • This allows you to monitor fuel levels, remaining range, mileage, and other parameters from Home Assistant.

Now your BMW ConnectedRide data is available in your smart home system!

Keep in mind I used bash to keep it easy to explain, this can be done in any language you like and is supported by Android.

But again sinds bmw is using AWS to store it’s data a much better solutions should be to get a valid token for the host cpp.bmw-motorrad.com and endpoint /v2/service/county-county/bmc-user-bikes

The response here is actually all you need

{
“typeKey”: “XXX”,
“chargingMode”: null,
“energyLevel”: null,
“remainingRangeElectric”: null,
“chargingTimeEstimationElectric”: null,
“vehicleType”: XX,
“fuelLevel”: 20,
“absType”: null,
“lastConnectedTime”: 1234567890,
“lastActivatedTime”: 1234567890,
“lastConnectedLat”: 52.XXXXX,
“lastConnectedLon”: 5.XXXXX,
“nextServiceDueDate”: 174XXXXXXX,
“nextServiceRemainingDistance”: 74XXXXX,
“tirePressureFront”: 1.9X,
“tirePressureRear”: 2.4X,
“totalMileage”: 14XXXXX,
“trip1”: 10XXXXX,
“color”: “XXXXXX”,
“remainingRange”: 63XXX,
“totalConnectedDistance”: 45XXXXX,
“totalConnectedDuration”: 45XXXX,
“__typename”: “CloudBike”
}

So far I could get a Bearer Token which is only valid for 2 hours, this would be more stable if the token retrieval could be automized.

I tried to set it up like this for 2 hours. Unfortunately, I am already failing to execute the first script. I have downloaded the files to the cell phone via computer but whenever I want to access ‘bash get_data.sh’ it says: no such file or directory.

So i give up because of stupidity :slight_smile: