BLE Heartrate monitor

Hi everybody,
i have a bluetooth heartratemonitor (HRM) and wanted to get my heartrate into Home Assistant for further automatisation.
My yaml got me so far that i can track the rssi of the HRM but i could not figure out how to get the HR itself…

esphome:
  name: esp_hr
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "geheim"
  password: "geheim"
  fast_connect: true
  
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.155
    gateway: 192.168.1.1
    subnet: 255.255.255.0

time:
  - platform: sntp
    id: sntp_time
    
captive_portal:

logger:

api:
  password: "geheim"
  
ota:
  password: "geheim"

sensor:
  - platform: template
    name: "Heart_rate"
    id: Heart_rate
  - platform: ble_rssi
    mac_address: F0:13:C3:B1:AC:67
    name: "Heart_rate_rssi"
    
esp32_ble_tracker:
  on_ble_service_data_advertise:
    - service_uuid: 2A37
      then:
       - lambda: 'id(Heart_rate).publish_state(x[0]);'    

the service_uuid: 2A37 I found online, I also tried 1006 (the yaml editor complains that this is not a string) found on Bluetooth.com
is there any way to read all the data send by one device and then figure out the stuff you need?

that is the result from scanning BLE as I know:

[10:15:01][D][esp32_ble_tracker:544]: Found device F0:13:C3:B1:AC:67 RSSI=-49
[10:15:01][D][esp32_ble_tracker:565]: Address Type: PUBLIC
[10:15:01][D][esp32_ble_tracker:567]: Name: ‘TICKR FIT C601’

1 Like

Perhaps try 0x1006 or “1006”

Also, I think this will be what we want, when it is merged BLE client support on ESP32 by buxtronix · Pull Request #1177 · esphome/esphome · GitHub

Thanks for pointing out that request. It really looks like the solution! Sadly it also looks kind of stalled :confused:.
Is there any other option to receive and forward “everything received” and then do the figuring out on HA?

Not as far as I know.

ok figured out a little more:

[06:38:23][D][ble_adv:196]: New BLE device
[06:38:23][D][ble_adv:197]: address: F0:13:C3:B1:AC:67
[06:38:23][D][ble_adv:198]: name: TICKR FIT C601
[06:38:23][D][ble_adv:199]: Advertised service UUIDs:
[06:38:23][D][ble_adv:201]: - 18:0D
[06:38:23][D][ble_adv:201]: - 18:0F
[06:38:23][D][ble_adv:201]: - 18:0A
[06:38:23][D][ble_adv:201]: - 8B:EB:9F:0F:50:F1:FA:97:B3:4A:7D:0A:01:00:26:A0
[06:38:23][D][ble_adv:203]: Advertised service data:
[06:38:23][D][ble_adv:207]: Advertised manufacturer data:

so it should be one of the UUIDs, i guess. Still nothing on each of them though…

180D is the heartrate service
180F is the battery service
189A is the device information service
2A37 is the Heartrate measurement

in general see here https://btprodspecificationrefs.blob.core.windows.net/assigned-values/16-bit%20UUID%20Numbers%20Document.pdf

thanks!
so to my understanding my code:

esphome:
  name: esp32test
  platform: ESP32
  board: esp-wrover-kit

wifi:
  ssid: "geheim"
  password: "geheim"
  fast_connect: true
  
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.1.155
    gateway: 192.168.1.1
    subnet: 255.255.255.0

time:
  - platform: sntp
    id: sntp_time
    
captive_portal:

logger:

api:
  password: "geheim"
  
ota:
  password: "geheim"

sensor:
  - platform: template
    name: "HR"
    id: HR
  - platform: ble_rssi
    mac_address: F0:13:C3:B1:AC:67
    name: "Heart_rate_rssi"
    
esp32_ble_tracker:
  on_ble_service_data_advertise:
    - service_uuid: "2A37"
      then:
       - lambda: 'id(HR).publish_state(x[0]);'   

should result in a response whenever this service is available (similar to the rssi service), is this correct?

[09:59:11][D][sensor:092]: ‘Heart_rate_rssi’: Sending state -67.00000 dB with 0 decimals of accuracy
[09:59:27][D][sensor:092]: ‘Heart_rate_rssi’: Sending state -65.00000 dB with 0 decimals of accuracy
[09:59:28][D][sensor:092]: ‘Heart_rate_rssi’: Sending state -64.00000 dB with 0 decimals of accuracy

The “advertised service UUIDs” you see are services you have to connect to before you can get their information. Connecting to a BLE device is implemented in the PR @nickrout mentioned. Without this PR, you can’t access the heart rate from your device.

The on_ble_service_data_advertise key you are using does something else: it listens to “advertised service data”, which are broadcasted (so you don’t have to connect to read these data). But your device doesn’t have these.

1 Like

thanks a lot for the clarification

There is an example here Collecting Temperature Data from ELA Bluetooth Puck with ESPHome - Steves Home in the wilderness

And some good beginners intro to ble here Introduction | Introduction to Bluetooth Low Energy | Adafruit Learning System

2 Likes

in the github request is was mentioned that:

You can use the source fork directly, I think HA can be configured to use ESPhome from any Github repo.

where would i need to add this repo?

Thanks

Are you using the HA esphome addon?

If so use the esphome_version setting

yes using the addon.
I am pretty new to Home Assistant, what is the needed format?

Options
 
esphome_version
esphome/tree/ble-client
 
relative_url
https://github.com/buxtronix/esphome/tree/ble-client

does give me a

502: Bad Gateway

error

thanks in advance

out of the documentation:

Option: esphome_version

Manually override which ESPHome version to use in the add-on. For example to install the latest development version, use "esphome_version": "dev", or for version 1.14.0: "esphome_version": "v1.14.0".

This can also be used to specify a branch of a fork of the esphome repository. For example to install the test_new_component branch of a fork made by user123, use "user123:test_new_component". This usage assumes the forked repository is named esphome.

so I tried:

Options
 
esphome_version
buxtronic:ble-client
 
relative_url

still same bad gateway error

This has now been merged into the dev channel of ESPhome. I’ve added my bluetooth-enabled washing machine and it’s bringing back data. Just need to work out what each number means now!

that’s awesome! would you be willing to share your yaml?

No worries.

First, I changed to the dev branch of the add-on:

image

Then I used the BLE scanner to find the mac address. Using the mac address Is used the ble_client:

ble_client:
  - mac_address: 00:A0:50:27:79:13
    id: washing_machine

This brought back:

[19:14:04][I][ble_client:159]: Service UUID: 0x1800
[19:14:05][I][ble_client:160]:   start_handle: 0x1  end_handle: 0x7
[19:14:05][I][ble_client:339]:  characteristic 0x2A00, handle 0x3, properties 0x2
[19:14:05][I][ble_client:339]:  characteristic 0x2A01, handle 0x5, properties 0x2
[19:14:05][I][ble_client:339]:  characteristic 0x2A04, handle 0x7, properties 0x2
[19:14:05][I][ble_client:159]: Service UUID: 0x1801
[19:14:05][I][ble_client:160]:   start_handle: 0x8  end_handle: 0xb
[19:14:05][I][ble_client:339]:  characteristic 0x2A05, handle 0xa, properties 0x22
[19:14:05][I][ble_client:159]: Service UUID: 0xAC00
[19:14:05][I][ble_client:160]:   start_handle: 0xc  end_handle: 0x17
[19:14:05][I][ble_client:339]:  characteristic 0xAC01, handle 0xe, properties 0x16
[19:14:05][I][ble_client:339]:  characteristic 0xAC02, handle 0x11, properties 0x14
[19:14:05][I][ble_client:339]:  characteristic 0xAC03, handle 0x14, properties 0x14
[19:14:05][I][ble_client:339]:  characteristic 0xAC04, handle 0x17, properties 0x4
[19:14:05][I][ble_client:159]: Service UUID: 00060000F8CE11-E4AB-F400-02A5-D5C51B
[19:14:05][I][ble_client:160]:   start_handle: 0x18  end_handle: 0x1b
[19:14:05][I][ble_client:339]:  characteristic 00060001F8CE11-E4AB-F400-02A5-D5C51B, handle 0x1a, properties 0x18
[19:14:05][I][ble_client:159]: Service UUID: 0x180A
[19:14:05][I][ble_client:160]:   start_handle: 0x1c  end_handle: 0x26
[19:14:05][I][ble_client:339]:  characteristic 0x2A29, handle 0x1e, properties 0x2
[19:14:05][I][ble_client:339]:  characteristic 0x2A24, handle 0x20, properties 0x2
[19:14:05][I][ble_client:339]:  characteristic 0x2A27, handle 0x22, properties 0x2
[19:14:05][I][ble_client:339]:  characteristic 0x2A28, handle 0x24, properties 0x2
[19:14:05][I][ble_client:339]:  characteristic 0x2A50, handle 0x26, properties 0x2

And I then used the UUIDs to track each characteristic:

sensor:
  - platform: ble_client
    ble_client_id: washing_machine
    name: "Washing Machine Attribute 1"
    service_uuid: '1800'
    characteristic_uuid: '2A00'

  - platform: ble_client
    ble_client_id: washing_machine
    name: "Washing Machine Attribute 2"
    service_uuid: '1800'
    characteristic_uuid: '2A01'

This seems to bring back lots of numbers, I just need to try and understand how that relates to the actual washing machine.

This may help :slight_smile: https://btprodspecificationrefs.blob.core.windows.net/assigned-values/16-bit%20UUID%20Numbers%20Document.pdf

Thanks @nickrout

I’ve looked at this, but all the IDs are generic ones like manufacturer and hardware version. Most of them don’t change, and the ones that do seem to be quite random.

that is pretty amazing!

I also got some of it working after:

[16:56:12][I][ble_client:083]: Attempting BLE connection to f0:13:c3:b1:ac:67
[16:56:15][I][ble_client:159]: Service UUID: 0x1800
[16:56:15][I][ble_client:160]: start_handle: 0x1 end_handle: 0x9
[16:56:15][I][ble_client:339]: characteristic 0x2A00, handle 0x3, properties 0xa
[16:56:15][I][ble_client:339]: characteristic 0x2A01, handle 0x5, properties 0x2
[16:56:15][I][ble_client:339]: characteristic 0x2A04, handle 0x7, properties 0x2
[16:56:15][I][ble_client:339]: characteristic 0x2AA6, handle 0x9, properties 0x2
[16:56:15][I][ble_client:159]: Service UUID: 0x1801
[16:56:15][I][ble_client:160]: start_handle: 0xa end_handle: 0xd
[16:56:15][I][ble_client:339]: characteristic 0x2A05, handle 0xc, properties 0x20
[16:56:15][I][ble_client:159]: Service UUID: 0x180D
[16:56:15][I][ble_client:160]: start_handle: 0xe end_handle: 0x13
[16:56:15][I][ble_client:339]: characteristic 0x2A37, handle 0x10, properties 0x10
[16:56:15][I][ble_client:339]: characteristic 0x2A38, handle 0x13, properties 0x2
[16:56:15][I][ble_client:159]: Service UUID: 0x180F
[16:56:15][I][ble_client:160]: start_handle: 0x14 end_handle: 0x17
[16:56:15][I][ble_client:339]: characteristic 0x2A19, handle 0x16, properties 0x12
[16:56:15][I][ble_client:159]: Service UUID: 6E400001B5A3F3-93E0-A9E5-0E24-DCCA91
[16:56:15][I][ble_client:160]: start_handle: 0x18 end_handle: 0x1d
[16:56:15][I][ble_client:339]: characteristic 6E400003B5A3F3-93E0-A9E5-0E24-DCCA91, handle 0x1a, properties 0x10
[16:56:15][I][ble_client:339]: characteristic 6E400002B5A3F3-93E0-A9E5-0E24-DCCA91, handle 0x1d, properties 0xc
[16:56:15][I][ble_client:159]: Service UUID: 4512154051F240-6E92-7A3E-1E18-3412E0
[16:56:15][I][ble_client:160]: start_handle: 0x1e end_handle: 0x26
[16:56:15][I][ble_client:339]: characteristic 4512154151F240-6E92-7A3E-1E18-3412E0, handle 0x20, properties 0x10
[16:56:15][I][ble_client:339]: characteristic 4512154251F240-6E92-7A3E-1E18-3412E0, handle 0x23, properties 0x10
[16:56:15][I][ble_client:339]: characteristic 4512000451F240-6E92-7A3E-1E18-3412E0, handle 0x26, properties 0xc
[16:56:15][I][ble_client:159]: Service UUID: 0x180A
[16:56:15][I][ble_client:160]: start_handle: 0x27 end_handle: 0x2f
[16:56:15][I][ble_client:339]: characteristic 0x2A29, handle 0x29, properties 0x2
[16:56:15][I][ble_client:339]: characteristic 0x2A25, handle 0x2b, properties 0x2
[16:56:15][I][ble_client:339]: characteristic 0x2A27, handle 0x2d, properties 0x2
[16:56:15][I][ble_client:339]: characteristic 0x2A26, handle 0x2f, properties 0x2
[16:56:15][I][ble_client:159]: Service UUID: A026EE010A7D4A-B397-FAF1-500F-9FEB8B
[16:56:15][I][ble_client:160]: start_handle: 0x30 end_handle: 0xffff
[16:56:15][I][ble_client:339]: characteristic A026E0020A7D4A-B397-FAF1-500F-9FEB8B, handle 0x32, properties 0x14
[16:56:15][I][ble_client:339]: characteristic A026E0040A7D4A-B397-FAF1-500F-9FEB8B, handle 0x35, properties 0x10

I modified my yaml to:

esp32_ble_tracker:
sensor:
  - platform: ble_client
    ble_client_id: tickr_fit
    name: "tickr_HR"
    service_uuid: '180D'
    characteristic_uuid: '2A37'
 
  - platform: ble_client
    ble_client_id: tickr_fit
    name: "tickr_battery"
    service_uuid: '180F'
    characteristic_uuid: '2A19'
    
ble_client:
  - mac_address: F0:13:C3:B1:AC:67
    id: tickr_fit

which results in two entities, the battery one works, the HR one doesn’t…

in the log i have this error:

[18:55:36][W][ble_sensor:082]: Error reading char at handle 16, status=2

any Idea what I am doing wrong here?
thanks