How I used AI to keep my house plants alive... For $5 on the cloud.

Last year I bought and killed a total of 6 tropical plants. I was quite frustrated. It's well known every species has different needs – Some more humidity than others, some less light, etc. I just couldn't get it right for my apartment's conditions (for context I live in Berlin, winters are quite dark here). In most cases I would notice  negative changes on the leaves, panic and then overwater the plants with a mix of water and fertiliser. This clearly led to even more detrimental effects, and subsequently, the death of all of them. And yes, I have also used those self watering pots with a reservoir in the past and let me tell you...they are not that great either.

After almost killing my favourite monstera I decided there had to be a way to use technology to understand what was I doing wrong. I came up with the idea of  installing in the plant pot an array of low power sensors connected to the internet which would allow me to process the data in the cloud and track day by day all the "plant vitals" in a web app. Once I had collected enough data from the sensors, I would then train a Naive-Bayes classifier algorithm to understand under which conditions the plant looked the healthiest.

This is how Earthchip was born –A hardware and software weekend project which so far (≈3.5 months ) has managed to keep my favorite monstera fresh and healthier than ever 🙌 🌱

Special thanks to @knajjars for the name idea.

So what does earthchip do exactly ? It measures in realtime the plant vitals and sends them to a cloud application to be further processed, stored, and presented in a web dashboard. The platform is capable to detect when a plant's health or "pulse" is in poor conditions and notify the user about it.

I'm following a "show and tell" format for this blog post. The project is open source so just drop me a line if you would like to run your own instance of Earthchip.

As you can imagine, this is a two part story. I will begin with the software section of it and then I will jump into the actual device and sensor details.

Spoiler alert: The software I built for this is an overkill.

When I started going through the possible solutions for this project I couldn't help it to over engineer it. Could I have used SQLite or even Excel ? Probably. But it would have not been as fun, or performant.

The device on the plant uses the MQTT protocol to push the vitals to the server every two seconds. For now it supports humidity, temperature and soil moisture. I used mosquitto as the MQTT message broker, it's always my go to for this kind of projects.

MQTT is a lightweight publish/subscribe messaging protocol designed for low-bandwidth, high latency, unreliable networks. These features make it the best option for sending high volumes of sensor data to analytics platforms and cloud solutions.

The Earthchip-app is composed of four parts:

  • An MQTT consumer service which listens to any published messages coming from the plant and then inserts them to the MongoDB instance.
  • A MongoDB instance with three different aggregation collections: base granularity (seconds), hourly, daily and weekly.
  • An Aggregation service which operates on the MongoDB instance to execute data roll-ups from the base granularity (seconds) to the upper collections. I used Agenda for scheduling the aggregation jobs.
  • A Classifier service where the AI algorithm lives, it trains itself every 6 days. I will detail its functioning later on in this post.

You can see LIVE the health of my monstera via the Eartchip user interface at It's a very basic Express view. I used Figma to design the dashboard. The frontend also relies on a single endpoint to retrieve the vitals in realtime,  the "Pulse API".

The Earthchip-app code is on GitHub under mourraille/earthchip-consumer. The server where the Earthchip-app container is running is a $5 VPS I got from two years ago as a sandbox.

Using an AI algorithm. Because this is 2022, right?

This was actually an additional step I took as earthchip was already being super representative about the state of the monstera. Nonetheless, I thought I could optimize my interactions with the system by simply having it let me know whenever I need to do something for the plant (E.g water it , put it under the sun, etc.) instead of having to check the dashboard everyday.

I trained a Bayes classification algorithm by having it summarize the plant conditions every 6 days and then ask me twice a week:

"How's the plant looking today?" –I would then reply either Good, Okay or Bad.

I created a Siri automation for this last part – My phone asks me the question on Wednesdays and Sundays at 8:00 pm, converts my voice input to a string and then pushes it to an endpoint to train the algorithm.

The algorithm takes my visual input and understands under which combination of variables the results are more favorable, or "healthier" for the plant.

This is an example of what the output for the Naive-Bayes algorithm would look like:

Temperature: 21 degrees , Humidity 40%, Soil moisture: 67%

  category: 'Healthy',
  probability: 1,
  timesMoreLikely: Infinity,
  secondCategory: 'Unhealthy',
  probabilities: [
    { category: 'Healthy', probability: 0.1875 },
    { category: 'Unhealthy', probability: 0 },
    { category: 'Regular', probability: 0 }
The most likely state for those variables is "Healthy"

Let's talk hardware.

I'm really no expert in electronic components, but I do have a passion for playing around with them and specially for connecting them to the internet. Nowadays, open source hardware makes it possible and affordable to put together all sorts of sensors and microcontrollers. This allows people to easily create gadgets to solve super specific problems in their households  and moreover document and share progress with the community which after all is what makes open source hardware so great.

For this project I used a popular internet enabled microcontroller – The NodeMCU based on the ESP8266 Wi-Fi SOC. It' really small and cheap. It costs around €8 on Amazon.

NodeMCU ESP8266 v1.0

The soil moisture is measured by a capacitive sensor which pulls the value as an analog signal which is then mapped as a percentage in the ESP8266's firmware.

Analog moisture sensor

The soil moisture is measured by a capacitive sensor which pulls the value as an analog signal which is then mapped as a percentage in the ESP8266's firmware.

BMP180 - Digital Barometric pressure and temperature sensor

I pretty much just soldered all these sensors to a generic PCB board and 3d printed a cool looking case for it!

The device sends a pulse to the mosquitto instance every 2 seconds. It's really not necessary to over monitor the values to this just felt nice to be able to see a live feed of the plant. If it weren't for this, it could totally work on bluetooth and run on batteries which would make it more autonomous. (no need to connect it to a power outlet). I will probably iterate on this for future versions.

Next steps

The ultimate goal is to create a small greenhouse that is self sustainable, meaning the system should have the mechanic components to water itself, turn on or off UV lamps and ultimately grow herbs or other small vegetables.

I would also like to keep better track of any anomalities when I'm away, for that I need to creat an alerting system.

For these intiatives, the system requires to be completely autonomus. This clearly implies extending and training even more the model. So in the future the whole system will "live" around the AI service.  

Hey! I'm Mauricio. You can follow me on Twitter for more posts.

Show Comments