|
現: 2022-09-22 (木) 17:15:12 nao-pon  |
| | + | #navi |
| | + | RIGHT:&rsslink(../); |
| | + | #boxdate |
| | | | |
| | + | * ESP32 + ESPHome の Bluetooth Proxy で SwitchBot Mater [#o4ddaff8] |
| | + | RIGHT:&tag(ESP32,ESPHome,Bluetooth,SwitchBot,HomeAssistant); |
| | + | |
| | + | [[Home Assistant 2022.9:https://www.home-assistant.io/blog/2022/09/07/release-20229/#bluetooth-everywhere]] から、ESPHome の [[Bluetooth Proxy:https://esphome.io/components/bluetooth_proxy.html]] が対応したので、今まで BLE Aadvertise を Listen して独自に処理していたものを、SwitchBot 統合を利用した方法に変更してみた。 |
| | + | |
| | + | 手順はとても簡単。ESPHome の設定に "bluetooth_proxy:" を書き加えて、SwitchBot 統合を追加するだけで、自動的にデバイスを発見して追加してくれた。 |
| | + | |
| | + | 素晴らしい! |
| | + | |
| | + | #ref(site://modules/xelfinder/index.php/view/47/220922-170734.png,left,mw:400,mh:400) |
| | + | |
| | + | Home Assistant で ESPHome の ESP32 が動いているなら、 |
| | + | esp32_ble_tracker: |
| | + | bluetooth_proxy: |
| | + | を追加するだけで、Bluetooth Proxy としても動作するので、対応した Bluetooth デバイスを気軽に追加できるようになった!本当に素晴らしい! |
| | + | |
| | + | ちなみに以前、独自に BLE Aadvertise を Listen していた設定は次のような感じ。 |
| | + | |
| | + | #code(yaml){{ |
| | + | sensor: |
| | + | - platform: template |
| | + | name: "$devicename Humidity" |
| | + | id: humidity0 |
| | + | unit_of_measurement: '%' |
| | + | accuracy_decimals: 0 |
| | + | icon: "mdi:water-percent" |
| | + | - platform: template |
| | + | name: "$devicename Temperature" |
| | + | id: temperature0 |
| | + | unit_of_measurement: '°C' |
| | + | accuracy_decimals: 1 |
| | + | icon: "mdi:thermometer" |
| | + | - platform: template |
| | + | name: "$devicename BT RSSI" |
| | + | id: rssi0 |
| | + | unit_of_measurement: 'dB' |
| | + | accuracy_decimals: 0 |
| | + | icon: "mdi:bluetooth" |
| | + | - platform: template |
| | + | name: "$devicename Battery" |
| | + | id: battery0 |
| | + | unit_of_measurement: '%' |
| | + | accuracy_decimals: 0 |
| | + | icon: "mdi:battery" |
| | + | |
| | + | esp32_ble_tracker: |
| | + | on_ble_advertise: |
| | + | - mac_address: f4:42:fa:xx:xx:xx |
| | + | then: |
| | + | - lambda: |- |
| | + | for (auto data : x.get_service_datas()) { |
| | + | if(data.data.size() == 6) { |
| | + | float temperature = (float)(data.data[4] & 0b01111111) + ((float)(data.data[3] & 0b00001111) / 10); |
| | + | if (!(data.data[4] & 0b10000000)) { |
| | + | temperature = -temperature; |
| | + | } |
| | + | int8_t humidity= data.data[5] & 0b01111111; |
| | + | int8_t battery = data.data[2] & 0b01111111; |
| | + | int8_t rssi=x.get_rssi(); |
| | + | id(humidity0).publish_state(humidity); |
| | + | id(temperature0).publish_state(temperature); |
| | + | id(rssi0).publish_state(rssi); |
| | + | id(battery0).publish_state(battery); |
| | + | } |
| | + | } |
| | + | }} |
| | + | |
| | + | RIGHT:&font(90%){&page_comments;}; |
| | + | #navi |