Linptech/Xiaomi BT Water Leak/Rain Sensor RS1BB using Passive BLE and ESPHome

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.

Steps:

  1. Connecting the sensor to Xiaomi Home app (using Chinese server).
  2. Getting encryption key and MAC for the device.
  3. Installing Passive BLE Monitor custom (HACS) integration.
  4. Configuring ESP32 as BLE Gateway in ESPHome.
  5. Configuring the device in Passive BLE Monitor.
  6. Created automation to listen to events.

Instructions:

  1. 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).

  2. I extracted encryption key (BLE KEY) and MAC address from my Xiaomi Home account using this tool. More info and help is available here.

  3. Then I installed Passive BLE monitor from HACS - I did not yet configure it at this point.

  4. 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).

  1. Then I configured Passive BLE Monitor in Home Assistant:

  1. 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.

Thanks for adding this tutorial. I was wondering why it was not initially connecting to Xiaomi app, then i saw this small, but VERY important comment - Chinese servers. Switched to China and immidiately it was discovered and managed to extract the token. This evening i will try to continue when i get back home.
Thanks again.
P.S. Put the chinese servers in bold - really important part :smiley:

1 Like

Can this also work directly with a Pi 4’s Bluetooth radio?
I am only asking because I have tried to the past 2 days to make it work without any success.

I assume you have to configure your Home Assistant instance following first steps here (instead of step no. 4 in my guide): Configuration parameters | Passive BLE Monitor integration

And if the device is in range of your Pi’s Bluetooth, it should work.

Whenever I restart the HA server, the sensor shows an “unknown” state, and this state remains unchanged until the next rain. Signal and battery levels are reported every 50 minutes. Should this be fixed on the server side or with a firmware update for the device?

Moreover, the device is far from reliable. All night it was heavy raining and in the middle of the night it changed the state from wet to dry. Maybe rain water too clean to conduct? Can we change the sensitivity somehow?