Just wanted to give something back to the community which has been really helpful to me.
I’ve found cheap little rain sensor on AE and wanted to give it a go: https://www.aliexpress.com/item/1005006344050442.html
I’m hosting my HA instance on my Windows “server” PC with no direct bluetooth hardware connected to HA - just using multiple ESP32s as BT proxies around my home.
Update 07-2024: Official Xiaomi BLE integration now picks up the sensor automatically (BLE key is needed). I disabled Passive BLE monitor and automation. I left my ESP config unchanged.
Steps:
- Connecting the sensor to Xiaomi Home app (using Chinese server).
- Getting encryption key and MAC for the device.
- Installing Passive BLE Monitor custom (HACS) integration.
- Configuring ESP32 as BLE Gateway in ESPHome.
- Configuring the device in Passive BLE Monitor.
- Created automation to listen to events.
Instructions:
-
I first went and connected rain sensor to the Xiaomi Home app using Chinese server (I’ve created dual app on my phone a while back as I have some devices that can only be added to the app using CN server).
-
I extracted encryption key (BLE KEY) and MAC address from my Xiaomi Home account using this tool. More info and help is available here.
-
Then I installed Passive BLE monitor from HACS - I did not yet configure it at this point.
-
I configured my ESP32 using this config (first I installed external_components and after that I added and installed esp32_ble_tracker and ble_gateway config):
external_components:
- source: github://myhomeiot/esphome-components
- source: github://pr#2854
components: [esp32_ble_tracker]
esp32_ble_tracker:
ble_gateway:
devices:
- mac_address: AA:BB:CC:DD:EE:FF
on_ble_advertise:
then:
homeassistant.event:
event: esphome.on_ble_advertise
data:
packet: !lambda return packet;
I have a dedicated ESP32 for this sensor, so I don’t know how it’s going to behave if there are some additional sensors/components added (beside basic config).
- Then I configured Passive BLE Monitor in Home Assistant:
- Then I created automation as it says in readme from BLE Gateway:
automation:
- alias: ESPHome BLE Advertise
mode: queued
trigger:
- platform: event
event_type: esphome.on_ble_advertise
action:
- service: ble_monitor.parse_data
data:
packet: "{{ trigger.event.data.packet }}"
I had to wait for about 15 minutes to get the data to HA. Eventually, I could see a device and sensor in Passive BLE Monitor integration in HA:
I know the guide is not detailed, but it’ll maybe save some time to someone.
P.S. At one time, after I rebooted Home Assistant, I noticed that the sensor was not reporting any states back (not even RSSI and battery) - in the logs, I’ve found:
WARNING (ImportExecutor_0) [custom_components.ble_monitor.bt_helpers] There are no BT controllers present in the system!
Reload of Passive BLE monitor integration solved the issue (and this occured only once for me). I’m not sure why it happened - I assume that the ESPHome integration loaded after Passive BLE Monitor one. This can be solved with automation that reloads the integration after HA boots - more info here.
Also, after HA reboot, the sensor “moisture” state is unknown until it detects “moisture” or “no moisture” again. It does report RSSI and battery after a few minutes.