Esp32_ble_tracker - how to log/look at Bluetooth advertising data

Newbie to ESP32.
Have set up the esp32_ble_tracker component and can get advertising data from my Hormann garage door using the on_ble_advertise: trigger and the code in the docs.

Here’s a sample from the logs

[12:24:21][D][ble_adv:067]: New BLE device
[12:24:21][D][ble_adv:068]:   address: F5:D7:5C:6F:7C:31
[12:24:21][D][ble_adv:069]:   name: 
[12:24:21][D][ble_adv:070]:   Advertised service UUIDs:
[12:24:21][D][ble_adv:072]:     - 669A9001-0008-968F-E311-6050405558B3
[12:24:21][D][ble_adv:074]:   Advertised service data:
[12:24:21][D][ble_adv:078]:   Advertised manufacturer data:
[12:24:21][D][ble_adv:080]:     - 0x07B4: (length 6)
[12:24:21][D][ble_adv:080]:     - 0x07B4: (length 17)

How can I look at the raw data? Docs say “A variable x of type esp32_ble_tracker::ESPBTDevice is passed to the automation for use in lambdas” but I don’t know how to look inside it.

I tried adding data.data.to_string().c_str() to the following code snippet but get a compilation error - data has no to_string method

ESP_LOGD("ble_adv", "  Advertised manufacturer data:");
            for (auto data : x.get_manufacturer_datas()) {
                ESP_LOGD("ble_adv", "    - %s: (length %i)", data.uuid.to_string().c_str(), data.data.size());

Also I tried using the on_ble_manufacturer_data_advertise trigger using manufacturer_id : “1972” - decimal equivalent of 0x07B4 - to narrow things down a bit but it never triggered.

Hoping someone can point me in the right direction - thanks

OK sorted.

This line displays the first byte of the manufacturer data

 ESP_LOGD("ble_adv",  " First byte %i", data.data[0]); 

using the auto iterator lets you see all the data.

For my Hormann garage door I only needed the first byte of the second chunk of manufacturer data. The following detects if the door is open or closed.

esp32_ble_tracker:
  on_ble_advertise:
    - mac_address: F5:D7:5C:6F:7C:31
      then:
        - lambda: |-
            ESP_LOGD("ble_adv", "  Advertised manufacturer data:");
            for (auto data : x.get_manufacturer_datas()) {
            ESP_LOGD("ble_adv", "    - %s: (length %i) ", data.uuid.to_string().c_str(), data.data.size());
            ESP_LOGD("ble_adv",  " First byte %i", data.data[0]);
            if (data.data[0] == 20){
              id(my_garage_door).publish_state(false);
              }
            if (data.data[0] == 19 ){
              id(my_garage_door).publish_state(true);
              }  
            }

where my_garage_door is a template binary sensor.

New to ESPHome but seriously impressed so far!