Advertisements
SubscribeBluetoothAdvertisements
Sends a subscription request and registers handlers for incoming BLE advertisement packets. Handles both the legacyBluetoothLEAdvertisementResponse (message type 67) and the newer BluetoothLERawAdvertisementsResponse (message type 93).
Calling the returned unsubscribe function deregisters the handlers and sends an UnsubscribeBluetoothLEAdvertisementsRequest to the device.
Called for every incoming advertisement. Type-assert the message to
*pb.BluetoothLEAdvertisementResponse or *pb.BluetoothLERawAdvertisementsResponse to access the fields.Connection management
BluetoothConnect
Connects to a BLE device via the ESPHome Bluetooth proxy. UsesBLUETOOTH_DEVICE_REQUEST_TYPE_CONNECT_V3_WITH_CACHE for the connection request.
Waits up to 30 seconds for the BluetoothDeviceConnectionResponse.
The BLE device address as a
uint64. The lower 6 bytes hold the 48-bit Bluetooth address.BluetoothDisconnect
Disconnects from a connected BLE device. Waits up to 10 seconds for theBluetoothDeviceConnectionResponse confirming disconnection.
The BLE device address.
GATT operations
BluetoothGATTGetServices
Retrieves all GATT services from a connected BLE device. Accumulates multipleBluetoothGATTGetServicesResponse packets until the device sends BluetoothGATTGetServicesDoneResponse.
Waits up to 30 seconds for the done response. Returns a GATT error if the device sends a BluetoothGATTErrorResponse.
The BLE device address.
*pb.BluetoothGATTService, each containing a UUID and a list of BluetoothGATTCharacteristic entries.
BluetoothGATTRead
Reads the value of a GATT characteristic by its handle. Waits up to 10 seconds for theBluetoothGATTReadResponse. Returns a GATT error if the device sends a BluetoothGATTErrorResponse for the same address and handle.
The BLE device address.
The GATT characteristic handle (from
BluetoothGATTGetServices).[]byte.
BluetoothGATTWrite
Writes data to a GATT characteristic. Whenresponse is false, the message is sent fire-and-forget and the method returns immediately. When response is true, the method waits up to 10 seconds for a BluetoothGATTWriteResponse confirming the write.
The BLE device address.
The GATT characteristic handle.
The bytes to write to the characteristic.
true to wait for a write acknowledgement (Write with Response); false for a fire-and-forget write (Write without Response).BluetoothGATTNotify
Enables or disables GATT notifications for a characteristic. When enabling, the providedhandler is called each time the device sends a BluetoothGATTNotifyDataResponse for the specified address and handle.
Waits up to 10 seconds for the BluetoothGATTNotifyResponse confirming the subscription change.
The BLE device address.
The GATT characteristic handle.
true to subscribe to notifications, false to unsubscribe.Called with the raw notification payload each time the characteristic value changes. Only used when
enable is true.Scanner control
BluetoothScannerSetMode
Sets the Bluetooth scanner mode on the ESPHome device. This controls whether the device actively scans for BLE advertisements.The scanner mode. Use
pb.BluetoothScannerMode_BLUETOOTH_SCANNER_MODE_ACTIVE or pb.BluetoothScannerMode_BLUETOOTH_SCANNER_MODE_PASSIVE.Connection capacity
SubscribeBluetoothConnectionsFree
Subscribes to updates reporting how many free Bluetooth connection slots remain on the proxy device. The handler is called whenever the available count changes.Called whenever the connection slot count changes. The response includes
Free (available slots) and Limit (total slots).Timeouts summary
| Method | Timeout |
|---|---|
BluetoothConnect | 30 seconds |
BluetoothDisconnect | 10 seconds |
BluetoothGATTGetServices | 30 seconds |
BluetoothGATTRead | 10 seconds |
BluetoothGATTWrite (with response) | 10 seconds |
BluetoothGATTNotify | 10 seconds |