Integrate Bluetooth battery monitoring devices (cars, motorbikes etc.)

Received: yes, 5 of them in front of me.
Tried: Unfortunately not. Priorities have changed for now (no Smart Home time currently), I hope to be able to test this within the next two weeks.

On my todo list:

  1. Check Mi Scale autodiscovery
  2. Test OMG with BM2

Will turn back once I can provide experiences on those.

1 Like

Hi @DigiH @1technophile
Interestingly, I was trying out the Windows app “Bluetooth LE Explorer” and was able to access a number of different services on the BM2

Hi @sew999,

Now we need to identify which service/characteristics have the voltage

Well according to GitHub - KrystianD/bm2-battery-monitor: Python MQTT publisher and ESPHome template for Bluetooth based Battery Monitors - reverse engineering. it’ll be service_uuid: 0xFFF0 & characteristic_uuid: 0xFFF4

I have been trying to load my ESP32 with his code, but dont think I’m handling the bm2_mmqt.py file correctly - I dont think its being included…

I will try this tomorrow and see if I get something

I managed to build an ESP32 in ESPHome last night that worked with this code and returned the voltage reading in mqqt. I put the include.h and secrets.yaml file in the config/esphome directory.
I’m guessing from the lambda part of the sensor code that the voltage source is encrypted, so does that help with making an update of OpenMQTTGateway, possibly?

esphome:
  name: esp32s3
  friendly_name: ESP32S3

  includes:
  - include.h

esp32:
  board: esp32-s3-devkitc-1
  framework:
    type: arduino

logger:

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

time:
  - platform: sntp
    id: sntp_time
    
web_server:
  port: 80

mqtt:
  broker: 192.168.0.XXX
  discovery: false
  topic_prefix: esphome/BM2
  username: mqtt-user
  password: XXXXXXXXX

esp32_ble_tracker:

sensor:
  - platform: ble_client
    type: characteristic
    ble_client_id: bm2_battery_meter
    name: Voltage
    service_uuid: 'fff0'
    characteristic_uuid: 'fff4'
    unit_of_measurement: 'V'
    accuracy_decimals: 2
    state_class: measurement
    device_class: voltage
    force_update: true
    notify: true
    lambda: |-
      mbedtls_aes_context aes;
      mbedtls_aes_init(&aes);
      unsigned char output[16];
      unsigned char key[16] = { 108, 101, 97, 103, 101, 110, 100, 255, 254, 49, 56, 56, 50, 52, 54, 54, };
      unsigned char iv[16] = {};
      mbedtls_aes_setkey_dec(&aes, key, 128);
      mbedtls_aes_crypt_cbc(&aes, MBEDTLS_AES_DECRYPT, 16, iv, (uint8_t*)&x[0], output);
      mbedtls_aes_free(&aes);
      return ((output[2] | (output[1] << 8)) >> 4) / 100.0f;  
 
ble_client:
  - mac_address: 94:A9:A8:42:72:43
    id: bm2_battery_meter
3 Likes

Working on my side, will be in the next version of OMG.

Credit to KrystianD (Krystian Dużyński) · GitHub

2 Likes

Wow… Great news… Thank you…

2 Likes

You guys are amazing. Thanks!
Looking forward to the release. Will have a look at the release notes to grab the right one right from start.

First I will have a test look at the Mi scale (off-topic). Thumbs up for BM2, sounds pretty good so far.

@sew999 @e-raser we need some data to identify properly that the BM2 is a BM2 and not an iBeacon without relying on the name.

Could you upload esp32dev-ble-mqtt-undecoded from the web upload

And share what you are getting by PM or remove the MAC address from the message (id), should look like this:

{"id":"11:22:33:44:55:66","mac_type":0,"adv_type":0,"name":"Battery Monitor","manufacturerdata":"4c000215655f83caae16a10a702e31f30d58dd82f6444d7164","rssi":-93,"txpower":0,"brand":"GENERIC","model":"BM2 Battery Monitor","model_id":"BM2","type":"BATT","batt":100}

We want to identify a pattern accross the advertisements to identify the BM2 with reliability.

Hiya
I setup an ESP32 with the unencoded profile, but dont see any messages in the format you wanted, I see only this:
{“id”:“94:A9:A8:42:72:43”,“name”:“Battery Monitor”,“rssi”:-73,“txpower”:0}

Strange, could you verify that your configuration looks like this (Settings->Devices->your gateway):

Ahhh… No it doesnt… I’ll try again… Thank you…

Hi
is this better?

{“id”:“94:A9:A8:42:72:43”,“mac_type”:0,“adv_type”:0,“name”:“Battery Monitor”,“manufacturerdata”:“0d658b3c0df642e282dd9840b13e4aa7”,“rssi”:-62,“txpower”:0}

1 Like

Perfect, and if you wait a bit or look at your history you may have a message with "model":"iBeacon" like this:
{"id":"11:22:33:44:55:66","rssi":-87,"brand":"GENERIC","model":"iBeacon","model_id":"IBEACON","mfid":"4c00","uuid":"655f83caae16a10a702e31f30d58dd82","major":-4094,"minor":0,"volt":0}
This one is very interesting for us as it is causing troubles in the integration and need to be filtered.
So if you could share one like that please

Hi
Sorry, I’m not seeing those iBeacon messages in my mqtt, but I did find in my home assistant a file called bluetooth.remote_scanners which had this (if its any help):

        "94:A9:A8:42:72:43": {
          "device": {
            "address": "94:A9:A8:42:72:43",
            "name": "Battery Monitor",
            "rssi": -82,
            "details": {
              "source": "78:21:84:9b:56:0c",
              "address_type": 0
            }
          },
          "advertisement_data": {
            "local_name": "Battery Monitor",
            "manufacturer_data": {
              "76": "0215655f83caae16a10a702e31f30d58dd82f641505164",
              "25869": "8b3c0df642e282dd9840b13e4aa7",
              "25172": "f34c92a7374a306e9cb8288528a7",
              "15540": "3a552b95b35cb2828303454d52c9",
              "29977": "420e5334bbe464c6b1659d940607",
              "9112": "3637fa097b5ff673c5a26b70ad75",
              "15864": "7bc9a84a93164bcafb46393a98f7",
              "53974": "8efe659ade5b0bb5b6dec64fd5c4",
              "32202": "e18d8b9a0faa8c21ea486fe990e9"
            },
            "service_data": {},
            "service_uuids": [
              "0000fff0-0000-1000-8000-00805f9b34fb"
            ],
            "rssi": -82,
            "tx_power": -127,
            "platform_data": []
          }
1 Like

Hello,

You can test if it is working with the development version of OMG, it can be uploaded directly to an ESP32 from below:
https://docs.openmqttgateway.com/dev/upload/web-install.html
Choose esp32dev-ble

You can adapt the frequency of connection attempt to the BM2 by changing the parameter below:
image

image

1 Like

THANKYOU!

I have been running a number of BM2’s with Ultimate9 BM (Android) for a very long time.
Nothing I had been trying was working until this release.

I am using these BM2’s

image

With ESP32-WROOM-32 flashed with esp32dev-ble (dev SHA:ac0215) and it works beautifully!

The MiFlora plant monitors on this page are currently connected using Bluetooth proxy (HA BLE Proxy). However, looks like I will now be flashing them with OMG 

4 Likes

Thanks for the feedback, indeed the BM2 support is now integrated into the releases.

1 Like

Unfortunately next to the Theengs app still not sending the Mi Scale values to MQTT (nothing received at all even connection is shown as fine) I am stuck at the very beginning with (Option 1) Upload from the web | OpenMQTTGateway v1.5.1.

After flashing the ESP when scanning for the ESP WiFi according to Wifi and MQTT configuration | OpenMQTTGateway v1.5.1, it just does not show up.

Flashed the ESP several times, using different environments. I used esp32-lolin32lite-ble and esp32dev-ble. Same output.

Hardware is a LOLIN32 (https://www.amazon.de/AZDelivery-LOLIN32-Bluetooth-kompatibel-Arduino/dp/B086V1P4BL).

Any ideas?