My Use Case
I have some flowerpots in the outdoor garden and I would like to know if I need to turn on the plant watering switch by checking from moisture level in soil.
I already have the workable Home Assistant running on Rapberry Pi3B. After purchased a MiFlora device, I can manually checkout the moisture level from Mi App but it's not my intention. Integrating the soil moisture level automatically is the purpose of this blog. Automation will be covered in the next coming series.
Install ESPHome add-on in HA first
If you don't have ESPHome add-on install yet, you can follow the instructions below.
- Go to your HA web, click "Supervisor" -> "Add-on Store" and search for "ESPHome".
- Click "install" and wait for the installation.
- You can simple "start" the ESPHome add-on without any further customize in configuration. Don't forget to enable "Start on boot" and "Show in sidebar".
Add New ESPHome Integration for Mi Flora Reader
We are going to create the configuration of ESPHome specifically to read Mi Flora parameters via ESP32 board. For the first time configuration, you have to configure this file, compile and download to your desktop (I'm using Windows).
esphome: name: ble_reader1 platform: ESP32 board: esp-wrover-kit wifi: ssid: "WIFI" password: "PASSWORD" manual_ip: static_ip: 192.168.1.30 gateway: 192.168.1.1 subnet: 255.255.255.0 # Enable fallback hotspot (captive portal) in case wifi connection fails ap: ssid: "Miflora Reader1 Fallback Hotspot" password: "fallback" esp32_ble_tracker: sensor: - platform: xiaomi_hhccjcy01 mac_address: 'AA:AA:AA:AA:AA:AA' temperature: name: "MiFlora Temperature" moisture: name: "MiFlora Moisture" illuminance: name: "MiFlora Illuminance" conductivity: name: "MiFlora Soil Conductivity" captive_portal: # Enable logging logger: # Enable Home Assistant API api: ota:
- Don't forget to change the wifi parameters/ip address/mac address of your reader (ESP32 board) to the appropriate ones.
- I use the android application "BLE Scanner" to find the MAC address of the Mi Flora device.
- click "Compile" to compile the configuration into low level code and "Download Binary" to save it to your desktop.
Flash the Binary to ESP32 Board
- I used "esphomeflasher" from this github. You can follow the installation instructions there.
- Plug the ESP32 board into your laptop. In some cases, you may need to install the USB-to-UART-BRIDEGE driver as I needed. Download it from this URL.
- I also unable to see the usb device after pluged the board. Recommend to use "USBView" utility from Windows Kits. You can find it in this folder "C:\Program Files (x86)\Windows Kits\10\Debuggers\x64\usbview.exe" and run to see the list of connected USB devices.
- If the esphomeflasher was installed correctly, you can simply run "esphomeflasher" in your Windows command prompt or powershell. The GUI application will be poped up and allow you to flash the binary to your ESP32 easily.
- If you got this error --> "A fatal error occurred: Failed to connect to ESP32: Timed out waiting for packet header", just press the Boot button on ESP32 board while flashing the binary code.
After the binary flashing was completely done, you can remove it from your laptop and power it up near Mi Flora device. In my case, the workable distance is not over 2 meters without obstacles between them.
Now you can go back to HA's main web, checkout the ESPHome section and find the log of your BLE reader. In some cases, you may need to wait an hour for complete data set.
Recommend to install "InfluxDB" and "Grafana" add-ons to visualize the data. After understand the data states, automation is made easy in HA.
Happy your DIY without any soldering like me.Buy me a coffee