miflora-mqtt-ha

Mi Flora’s and Home Assistant

Plants are expensive. And they tend to die when not looked after carefully. Since my wife and I suck at looking after plants, I bought a Mi Flora’s. Here’s how they help us safe money via Docker, MQTT and Home Assistant!

You’re probably reading this because every year you have to buy several new plants, because the old ones dried out. Luckely, there is a solution from Xiaomi called Mi Flora and they come packed in a neat white casing. You can buy them via AliExpress for about €12 per piece, which is way less then your average houseplant. They have a range of about 6 to 8 meters, depending on the line of sight.

These devices use Bluetooth to communicate with your phone/server/whatever. If you’re using a Raspberry Pi, you’re in luck. I am not, so I bought a Bluetooth dongle based on the Cambridge chip. Just inserted it into my server with Ubuntu Server (or Synology DSM 6+) and I was good to go.

In case you want this, what do you need? Well,
* Mi Flora(s)
* Server with BT availability
* Docker (tutorial)
* Home Assistant
* A MQTT broker (tutorial) (also comes with Home Assistant)


PlantGateway

Ok, so let’s go. Start with the Docker container. If you run on a RPi you can run this Docker image for the RPi. I however, as said, run on Ubuntu Server so I had to build my own image. You can download it from the Docker Hub: https://hub.docker.com/r/lolgast/plantgateway. This image can also be used when you run Docker on Synology DSM.

Before running the image get yourself a copy of the plantgw.yaml and configure it to your needs. You’ll notice you need to know the MAC-address of the Mi Flora. You can find this using hcitool. Start this in a SSH console using the command hcitool lescan

After about 10-15 seconds after you started the container it shuts down and the data from the plant should be published to your MQTT broker.


Home Assistant integration

Now to get this into Home Assistant, you have to create some sensors. In my plantgw.yaml the MQTT prefix is ‘plantgwateway/plants‘ and one of my plants has the alias phoenix_canariensis. To get the sensors in Home Assistant I have created to following sensors in my sensors.yaml file.

- platform: mqtt
  state_topic: "plantgateway/plants/phoenix_canariensis/"
  unit_of_measurement: "%"
  force_update: true
  value_template: '{{ value_json.battery }}'
  name: Phoenix Canariensis Battery MQTT

- platform: mqtt
  state_topic: "plantgateway/plants/phoenix_canariensis/"
  force_update: true
  unit_of_measurement: "lux"
  value_template: '{{ value_json.brightness }}'
  name: Phoenix Canariensis Brightness MQTT

- platform: mqtt
  state_topic: "plantgateway/plants/phoenix_canariensis/"
  force_update: true
  unit_of_measurement: "µS/cm"
  value_template: '{{ value_json.conductivity }}'
  name: Phoenix Canariensis Conductivity MQTT

- platform: mqtt
  state_topic: "plantgateway/plants/phoenix_canariensis/"
  unit_of_measurement: "%"
  force_update: true
  value_template: '{{ value_json.moisture }}'
  name: Phoenix Canariensis Moisture MQTT

- platform: mqtt
  state_topic: "plantgateway/plants/phoenix_canariensis/"
  unit_of_measurement: "°C"
  force_update: true
  value_template: '{{ value_json.temperature }}'
  name: Phoenix Canariensis Temperature MQTT

Save the sensors.yaml with coding support for Unicode UTF-8 or you’ll get problems with the formatting of the ‘µ’ and ‘°’
Now add these sensors to a group in your group.yaml you should and up with something like

Now all that is left is to go nuts with automations to make sure your plants will never run out of water or nutrition ever again!

About: lolgast


Leave a Reply

Your email address will not be published.