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

Yes, they do. Let me know what you are seeing in the MQTT homeassistant discovery topic

Really nothing bout the Mi Scale:

Did you receive and try the ESP32 ?

Hiya @1technophile
I have a BM2 sensor connected to my car battery & an ESP32 loaded with OpenMQTTGateway and am just seeing “Battery %” like this

Also, if it helps, the BM2 message received is like this
{
“stat_t”: “+/+/BTtoMQTT/94A9A8427243”,
“dev_cla”: “battery”,
“unit_of_meas”: “%”,
“name”: “BM2-batt”,
“uniq_id”: “94A9A8427243-batt”,
“val_tpl”: “{{ value_json.batt | is_defined }}”,
“state_class”: “measurement”,
“device”: {
“identifiers”: [
“94A9A8427243”
],
“connections”: [
[
“mac”,
“94A9A8427243”
]
],
“manufacturer”: “GENERIC”,
“model”: “BM2”,
“name”: “BM2 Battery Monitor-427243”,
“via_device”: “OpenMQTTGateway_ESP32_BLE”
}
}

I think that the BM2 needs to be paired in Bluetooth to work?

Hope this helps

Steve

I’m also seeing this in MQTT Explorer

Hi @sew999,

The BM2 only has the battery level in its advertising data, so the 100% you are seeing is correctly the only value which can be decoded from this freely available broadcast.

For any other BM2 services you correctly assume that a connection is required, which you might possibly achieve with the OpenMQTTGateway READ command.

Additionally if you expand the BTtoMQTT section under OpenMQTTGateway_ESP_BLE in MQTT Explorer you will see the different devices detected and decoded by OMG, which some or all created the Home Assistant sensor entries.

Hi @e-raser,

Could you also have a look under the BTtoMQTT section for your Mi Scale - when it is on/just been used for weighing. It should definitely show up there, also with its MAC address (“id”) for entry into Theengs App, and if you copy and past the information from there might show us why the auto-discovery might not have worked correctly.

Hi @DigiH
Bummer… I am having battery problems overnight and was hoping to get a remote record of the voltage. I bought this sensor as it said it was supported :frowning:
Thanks for your help…
Cheers
Steve

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