BLE 客户端传感器
ble_client 组件是一个传感器平台,可以查询 BLE 设备的 RSSI 或服务特性的特定值。
对于文本/字符串值,请参阅 BLE 客户端。
有关 BLE 服务和特性的更多信息,请参阅 BLE 客户端。
esp32_ble_tracker:
ble_client: - mac_address: XX:XX:XX:XX:XX:XX id: itag_black
sensor: - platform: ble_client type: characteristic ble_client_id: itag_black name: "iTag battery level" service_uuid: '180f' characteristic_uuid: '2a19' icon: 'mdi:battery' unit_of_measurement: '%'
- platform: ble_client type: rssi ble_client_id: itag_black name: "iTag RSSI"- type (必需):
rssi或characteristic之一。
rssi 选项:
characteristic 选项:
-
ble_client_id (必需, ID): 关联的 BLE 客户端的 ID。
-
service_uuid (必需, UUID): 设备上服务的 UUID。
-
characteristic_uuid (必需, UUID): 要查询的服务特性的 UUID。
-
descriptor_uuid (可选, UUID): 要查询的特性描述符的 UUID。
-
id (可选, ID): 用于代码生成的 ID,以及供依赖组件引用的 ID。
-
lambda (可选, lambda): 用于将原始数据读数转换为传感器值的 lambda。有关更多信息,请参阅 原始数据解析 Lambda。
-
notify (可选, 布尔值): 指示服务器为此特性发送通知。
-
update_interval (可选, 时间): 轮询设备的时间间隔。
-
所有其他选项来自 传感器。
自动化:
原始数据解析 Lambda
Section titled “原始数据解析 Lambda”默认情况下,只有服务特性上收到的每条消息的第一个字节用于传感器读数。对于更复杂的消息,可以通过自定义 lambda 函数来覆盖此行为以解析原始数据。接收到的数据字节作为类型为 std::vector<uint8_t> 的变量 x 传递给 lambda。该函数必须返回一个 float 值。
...
sensor: - platform: ble_client type: characteristic ble_client_id: t_sensor name: "Temperature Sensor 32bit float" ... device_class: "temperature" lambda: |- return *((float*)(&x[0]));BLE 传感器自动化
Section titled “BLE 传感器自动化”on_notify
Section titled “on_notify”当设备/服务器发送特性的通知消息时触发此自动化。配置变量 notify 必须为 true,否则这将没有效果。
一个类型为 float 的变量 x 被传递给自动化,用于 lambda 中。
示例 UUID
Section titled “示例 UUID”设备上可用的 UUID 取决于设备类型和可用的功能。请检查 ESPHome 设备日志以查找设备上的 UUID。
一些常见的 UUID:
| 服务 | 特性 | 描述 |
|---|---|---|
| 180F | 2A19 | 电池电量 |
| 181A | 2A6F | 湿度 |