Stop killing your plants

Lately I’ve been in an automation spree around the house. Since COVID-19 we’ve been working from home and spending most of our time indoors, so it makes sense that all the projects we had gathering dust are becoming important again.

In future posts I’ll talk more about what I’m using to drive my IoT devices, but the core of it all is a Home Assistant instance running inside my FreeNAS (now TrueNAS) server, in a Virtual Machine with Home Assistant Operating System.

This gives me access to the official Add-on Store and runs everything seamlessly, without fear of breaking everything up on an upgrade.

I’ve got a few wall switches, some plugs, LED strips and bulbs… everything running the latest Tasmota. Tasmota is an Open Source firmware that can be installed on almost all Chinese IoT devices that are running inside an ESP8266 (think of it like an Arduino with integrated WiFi).

Tasmota works great, and in latest version it integrates directly with Home Assistant. Older versions needed an MQTT server to broker messages to and from the devices. If you’ve never used MQTT you’ll find it similar to an email inbox and outbox, where your device sends messages to Home Assistant (ie: I turned myself on) and Home Assistant leaves messages for your device (ie: Turn yourself on).

Home Assistant integrates with MQTT as a way to communicate with a lot of stuff, not only with Tasmota devices, but with basically anything that can send messages in a format HA understands.

And thats the intro, now the more interesting part. I bought a couple of soil moisture, nutrient and light detection off Aliexpress. They’re based on the Xiaomi MiFlora and you talk with them through Bluetooth LE with a phone. They’ll tell you if your plant needs watering or if there’s too much or too little light for it to grow.

MiFlora plant sensor

My original intention was to have it talk with HA directly, since there’s a custom component that integrates this and more Xiaomi Bluetooth sensors. I couldn’t go this route because my HA instance runs in a bhyve Virtual Machine inside FreeNAS, and I can’t pass it USB hardware. That leaves me without BLE support, plus the server is too far away from the plants.

My next strategy was to setup a HA remote instance on a Raspberry Pi 3 and link it with my main Home Assistant. That proved too complicated, and Home Assistant is a bit too bulky for a Raspberry Pi 3.

Then I found out about miflora-mqtt-daemon. It’s a Python application that will talk with MiFlora devices and push messages to an MQTT server. That’s a perfect way to talk with Home Assistant, and I already had an MQTT server set up.

MiFlora MQTT Daemon debug output

I won’t go into detail of how to set it up, since the README in the official repository is very comprehensive.

Raspberry Pi Zero W

I decided to install it on a Raspberry Pi Zero W, running the latest Raspbian. I put it near my plants and power it with one of my router’s USB ports. The Zero doesn’t need as much power as a Pi 3 and that makes it perfect for this.

It took less than 10 minutes to get the decide IDs, write up a config and have them show up in Home Assistant.

Home Assistant MiFlora plant sensor integration

Next step is to add automations and a Telegram bot, so the plants can tell me when they need watering.