Today’s article will be about how to get data from the Xiaomi Mi Flora device into your central of home automation.
I’ll show you a way that is a little more complicated but has two major advantages:
Sounds good, isn’t it? Let’s start.
First let’s talk little about the solution itself – what we will need and how it will be connected together in general.
As you can see from the schema we will have three devices involved:
Don’t you have all / any of these parts yet or need more details?
For HomeAssistant I recommend to check my article about overview how to install and what could be good for it.
For Xiaomi Mi Flora I recommend to check my article with detailed description about that device.
For ESP32 I would recommend the version named DoIt DevKit it contains WiFi and Bluetooth and has power by MicroUSB cable – you could be there:
ESPHome – firmware for ESP32
We will start in middle – with preparing ESP32 firmware. Because this article shouldn’t be about ESP32 I will start with the easiest solution – if anyone need help, let me know in comments.
Suppose we have a functional HomeAssistant instance running as Hass.io. Then we could install ESPHome as Hass.io addon from Add-on store.
ESPHome is not included inside default repositories so we have to add one new with the link
In the add-on settings section, I recommend to enable the Show in sidebar option and you will have quick access to ESPHome directly from the left HomeAssistant menu.
When the installation is done we could connect ESP32 microcontroller into a computer where Hass.io is running and on the top right side of ESPHome we should see more ports:
For ESP32 the middle option is what we are looking for and we should choose it.
ESPHome – Basic firmware
The best is not to start with the final version of firmware but gradually add more functionality by pieces.
At the beginning, we will only need active WiFi and Bluetooth scanning
Click on the big red + button and fill in the wizard:
Use the edit button to check the generated configuration and add line:
The complete configuration could look something like this:
esphome: name: flora_01 platform: ESP32 board: esp32doit-devkit-v1 wifi: ssid: "<WIFINAME>" password: "<WIFIPASSWORD>" esp32_ble_tracker: # Enable logging logger: # Enable Home Assistant API api: ota:
Save the configuration and press the Upload button this time, which will first compile and then upload the new firmware via USB serial interface directly to ESP32.
19:56:52][I][app:096]: esphome version 1.13.6 compiled on Oct 20 2019, 19:50:15 [19:56:52][C][wifi:372]: WiFi: [19:56:52][C][wifi:254]: SSID: [redacted] [19:56:52][C][wifi:255]: IP Address: 10.2.1.21 [19:56:52][C][wifi:257]: BSSID: [redacted] [19:56:52][C][wifi:258]: Hostname: 'flora_01' [19:56:52][C][wifi:262]: Signal strength: -61 dB ▂▄▆█ [19:56:52][C][wifi:263]: Channel: 1 [19:56:52][C][wifi:264]: Subnet: 255.255.255.0 [19:56:52][C][wifi:265]: Gateway: 10.2.1.1 [19:56:52][C][wifi:266]: DNS1: 10.2.1.1 [19:56:52][C][wifi:267]: DNS2: 126.96.36.199 [19:56:52][C][logger:137]: Logger: [19:56:52][C][logger:138]: Level: DEBUG [19:56:52][C][logger:139]: Log Baud Rate: 115200 [19:56:52][C][logger:140]: Hardware UART: UART0 [19:56:52][C][ota:029]: Over-The-Air Updates: [19:56:52][C][ota:030]: Address: flora_01.local:3232 [19:56:52][C][api:103]: API Server: [19:56:52][C][api:104]: Address: flora_01.local:6053
… But we will only be interested in information from the Bluetooth module later, which should gradually show all Bluetooth devices within range.
As soon as we see Got Xiaomi Mi Flora we should write down the MAC address in parentheses.
20:45:46][D][xiaomi_ble:118]: Got Xiaomi Mi Flora (C4:7C:8D:6A:9C:FF): [20:45:46][D][xiaomi_ble:136]: Moisture: 34% [20:46:02][D][xiaomi_ble:118]: Got Xiaomi Mi Flora (C4:7C:8D:6A:9C:FF): [20:46:02][D][xiaomi_ble:121]: Temperature: 28.8°C [20:46:02][D][esp32_ble_tracker:147]: Starting scan..
ESPHome – final firmware
Open the ESPHome configuration again and add one more section to the configuration:
sensor: - platform: xiaomi_hhccjcy01 mac_address: 'C4:7C:8D:6A:9C:FF' temperature: name: "Xiaomi MiFlora Temperature" moisture: name: "Xiaomi MiFlora Moisture" illuminance: name: "Xiaomi MiFlora Illuminance" conductivity: name: "Xiaomi MiFlora Soil Conductivity" battery_level: name: "Xiaomi MiFlora Battery Level"
🥁If you are using ESPHome <1.14 you need to change platform configuration to value
Click on the upload button and upload the updated firmware version.
After the restart, we should see in the ESPHome log the specific values of all sensor values that ESPHome from Mi Flora Plant has read.
20:11:46][D][xiaomi_ble:118]: Got Xiaomi Mi Flora (C4:7C:8D:6A:9C:FF): [20:11:46][D][xiaomi_ble:130]: Conductivity: 649µS/cm [20:11:46][D][sensor:092]: 'Xiaomi MiFlora Soil Conductivity': Sending state 649.00000 µS/cm with 0 decimals of accuracy [20:11:53][D][xiaomi_ble:118]: Got Xiaomi Mi Flora (C4:7C:8D:6A:9C:FF): [20:11:53][D][xiaomi_ble:121]: Temperature: 22.5°C [20:11:53][D][sensor:092]: 'Xiaomi MiFlora Temperature': Sending state 22.50000 °C with 1 decimals of accuracy [20:12:02][D][xiaomi_ble:118]: Got Xiaomi Mi Flora (C4:7C:8D:6A:9C:FF): [20:12:02][D][xiaomi_ble:133]: Illuminance: 82lx [20:12:02][D][sensor:092]: 'Xiaomi MiFlora Illuminance': Sending state 82.00000 lx with 0 decimals of accuracy
Now we have one last step – adding Mi Flora Plant to HomeAssistant. Since we used ESPHome, the integration will be easy.
In HomeAssistant we click on Configuration / Integrations and in Discovered section you should automatically see ESPHome. Click Configure and confirm.
ESPHome configuration now appears in the Configured section, where you can see in detail the name of all sensors or you could rename them directly.
To display on the Dashboard in the case of Lovelace we can use something like this:
- type: entities entities: - entity: sensor.xiaomi_miflora_soil_conductivity - entity: sensor.xiaomi_miflora_illuminance - entity: sensor.xiaomi_miflora_moisture - entity: sensor.xiaomi_miflora_temperature title: Rostina - Fikus II show_header_toggle: false
.. which will produce something like this:
That’s all. If you have any questions or suggestions let me know in comments.