esphome:
name: esp32-ble-tracker
friendly_name: ESP32 Ble Tracker
esp32:
board: nodemcu-32s
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
encryption:
key: "IwRqzxtPneWvz2R7WySU7/v+uUXQsJVsu/VXxxrXjOw="
ota:
password: "44f013770e04ae7c36b6b794a4e7f8ee"
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Esp32-Ble-Tracker"
password: "PQiEO6DGBUxo"
captive_portal:
web_server: ## web控制,添加了这2行,就可以在网页端打开设备ip;
port: 80
version: 2
include_internal: true
external_components:
- source: github://ryanh7/esphome-custom-components
components: [ ptx_yk1 ]
esp32_ble_tracker:
scan_parameters:
interval: 300ms
window: 300ms
active: false
on_ble_advertise: # 调试用途,按下无线按钮可查找蓝牙开关MAC地址
then:
- lambda: |-
for (auto data : x.get_manufacturer_datas()) {
if (data.uuid == esp32_ble_tracker::ESPBTUUID::from_uint16(0x5348)) {
ESP_LOGD("ptx_yk1", "Found ptx_yk1_qmimb: %s", x.address_str().c_str());
return;
}
}
binary_sensor:
- platform: ptx_yk1
mac_address: "A4:C1:38:C2:63:A6" # 蓝牙开关MAC地址,可使用上面的调试代码查找新开关的MAC地址
name: "BLE Button"
timeout: 300ms # 可选,蓝牙BLE信号接收的超时时间。取决于信号环境和esp32_ble_tracker的scan_parameters配置。如果时间设置过短,可能会导致长按误判为短按;而时间设置过长则会延迟蓝牙开关的松开判定。
on_multi_click: # 单击、双击、长按示例配置
- timing:
- ON for at most 2s # 短按须少于2秒
- OFF for at least 1s # 1秒内无按下动作,判定为单击
then:
- logger.log: "Clicked" # 配置单击动作
- timing:
- ON for at most 2s # 第一次短按须少于2秒
- OFF for 0s to 1s # 两次短按须间隔1秒以内
- ON for at most 2s # 第二次短按须少于少于2秒
- OFF for at least 0s
then:
- logger.log: "Double-Clicked" # 配置双击动作
- timing:
- ON for at least 2s # 长按须大于2秒
then:
- logger.log: "Long-Pressed" # 配置长按动作
sensor:
# RSSI based on MAC address
- platform: ble_rssi
mac_address: A4:C1:38:C2:63:A6
name: "BLE 英俊"
写入后BLE BUTTON一直时关闭的
|