Hello. I’m trying to write some ESPHome code to integrate the AT02 into Home Assistant. Here is where I’ve got to so far. At the moment I’m just trying to dump out the data to a string at the moment. My thinking if I can see some data, I can then try to process it as above.
Here is my code
esphome:
name: barbeque
friendly_name: Barbeque
esp32:
board: esp32dev
framework:
type: esp-idf
# Enable Home Assistant API
api:
encryption:
key: "#################"
ota:
- platform: esphome
password: "####################"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Barbeque Fallback Hotspot"
password: "##############"
captive_portal:
# Enable logging
logger:
level: DEBUG
# Enable Home Assistant API
esp32_ble_tracker:
scan_parameters:
interval: 1100ms
window: 1100ms
active: true
# on_ble_advertise:
# - then:
# - lambda: |-
# ESP_LOGD("ble_adv", "New BLE device");
# ESP_LOGD("ble_adv", " address: %s", x.address_str().c_str());
# ESP_LOGD("ble_adv", " name: %s", x.get_name().c_str());
# ESP_LOGD("ble_adv", " Advertised service UUIDs:");
# for (auto uuid : x.get_service_uuids()) {
# ESP_LOGD("ble_adv", " - %s", uuid.to_string().c_str());
# }
# ESP_LOGD("ble_adv", " Advertised service data:");
# for (auto data : x.get_service_datas()) {
# ESP_LOGD("ble_adv", " - %s: (length %i)", data.uuid.to_string().c_str(), data.data.size());
# }
# 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());}
ble_client:
- mac_address: E6:2D:7C:52:22:B3
id: at02
on_connect:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Connected to Barbeque Sensor");
- delay: 3s
- ble_client.ble_write:
id: at02
service_uuid: CEE0
characteristic_uuid: CEE1
# List of bytes to write.
value: [0x55, 0xAA, 0x00, 0x03, 0xA0, 0x00, 0x00, 0x5C]
- delay: 200ms
- ble_client.ble_write:
id: at02
service_uuid: CEE0
characteristic_uuid: CEE1
# List of bytes to write.
value: [0x55, 0xAA, 0x00, 0x02, 0xA1, 0x00, 0x5C]
on_disconnect:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Disconnected from Barbeque Sensor");
text_sensor:
- platform: ble_client
ble_client_id: "at02"
name: "data"
service_uuid: CEE0
characteristic_uuid: CEE2
icon: 'mdi:battery'
on_value:
then:
- lambda: |-
ESP_LOGD("ble_client_lambda", "Characteristic value: %s", x.c_str());
Here is my log:
[21:11:46][D][esp32_ble_tracker:694]: Name: 'AT-02'
[21:11:46][D][esp32_ble_tracker:219]: Pausing scan to make connection...
[21:11:46][D][esp32_ble_tracker:219]: Pausing scan to make connection...
[21:11:46][D][esp-idf:000][BTU_TASK]: E (705388) BT_BTM: BTM_BleScan scan not active
[21:11:46][D][esp-idf:000][BTU_TASK]: W (705392) BT_APPL: bta_dm_ble_scan stop scan failed, status=0x6
[21:11:47][D][esp32_ble_client:110]: [0] [E6:2D:7C:52:22:B3] ESP_GATTC_CONNECT_EVT
[21:11:47][D][esp32_ble_client:110]: [0] [E6:2D:7C:52:22:B3] ESP_GATTC_OPEN_EVT
[21:11:47][I][ble_text_sensor:034]: [data] Connected successfully!
[21:11:47][D][esp32_ble_tracker:270]: Starting scan...
[21:11:47][D][esp32_ble_client:306]: [0] [E6:2D:7C:52:22:B3] Event 46
[21:11:47][D][esp32_ble_client:110]: [0] [E6:2D:7C:52:22:B3] ESP_GATTC_SEARCH_CMPL_EVT
[21:11:47][I][esp32_ble_client:227]: [0] [E6:2D:7C:52:22:B3] Connected
[21:11:47][D][ble_client_lambda:067]: Connected to Barbeque Sensor
[21:11:47][D][ble_client.automation:181]: Write type: ESP_GATT_WRITE_TYPE_NO_RSP
[21:11:47][D][ble_client.automation:188]: Found characteristic 0xCEE1 on device E6:2D:7C:52:22:B3
[21:11:47][D][ble_client.automation:181]: Write type: ESP_GATT_WRITE_TYPE_NO_RSP
[21:11:47][D][ble_client.automation:188]: Found characteristic 0xCEE1 on device E6:2D:7C:52:22:B3
[21:11:47][D][ble_client:058]: All clients established, services released
[21:11:47][D][esp32_ble_client:188]: [0] [E6:2D:7C:52:22:B3] cfg_mtu status 0, mtu 23
[21:11:50][D][esp32_ble_client:110]: [0] [E6:2D:7C:52:22:B3] ESP_GATTC_WRITE_CHAR_EVT
[21:11:51][D][esp32_ble_client:110]: [0] [E6:2D:7C:52:22:B3] ESP_GATTC_WRITE_CHAR_EVT
So the AT02 connects to the ESP32 (and the connected icon appears on the AT02). However, I don’t get any data shown in the text sensor. Can anyone give me a few points please?
Thanks
Adam