In my last project, I built a beautiful E-Paper dashboard to monitor my plant's health. It was a huge success! It told me the weather, my calendar, and most importantly, when my plant was thirsty. There was just one problem: I still had to do the watering.
I'd see the "Almost Dry" status on the screen, make a mental note to water it, get pulled into a meeting, and... forget. The system was monitoring perfectly, but the final, crucial step—the human action—was still the weakest link.
I realized I hadn't built a solution; I'd built a beautiful guilt-machine. It was time to close the loop. It was time to build a system that not only knows the plant is thirsty but can also do something about it. It was time to build a true, automated plant guardian.
The philosophy remains modular, but the roles have evolved.
- The Senses: The same Seeed Studio XIAO Soil Moisture Sensor from the last project. It's our reliable informant, living in the soil and reporting conditions over Wi-Fi. Its job is unchanged.
- The Muscles: This is the new part. A dedicated "actuator" module built from a XIAO ESP32-C3, a Grove Relay, and a small water pump. Its only job is to listen for the command to "water" and execute it precisely.
- The Brains: Crucially, the decision-making logic doesn't live on either device. It resides in Home Assistant. Using its powerful automation engine, we can create sophisticated rules based on the sensor's state to control the actuator. This makes the system incredibly flexible and easy to tweak.
This build requires a few more components, but thanks to the Grove ecosystem, it's still a solder-free experience.
The Sensor:
The Actuator Module:
- One Seeed Studio XIAO ESP32-C3
- One Seeed Studio Grove Base for XIAO
- One Grove - Relay
- A small 5V or 12V DC water pump
- A separate power supply for the pump (e.g., a 5V USB wall adapter) that matches your pump's voltage. Do not power the pump from the XIAO!
- Some silicone tubing
- A water reservoir (a simple jar, bottle, or container)
This is where we get our hands dirty, but it's very straightforward.
- Assemble the Core: Snap the XIAO ESP32-C3 onto the Grove Base.
- Connect the Relay: Use the Grove cable to connect the Grove Relay to one of the digital ports on the base (e.g., D2).
Wire the Pump Circuit: This is the most critical step. The relay acts as a remote-controlled switch for the pump.
- Connect the positive (+) wire from your separate power supply to the positive (+) terminal on the water pump.
- Connect the negative (-) wire from the water pump to one of the screw terminals on the relay.
- Connect the other screw terminal on the relay to the negative (-) wire (Ground) of your power supply.
- Final Setup: Place the pump into your water reservoir and run the tubing from the pump's outlet to your plant's pot.
First, we need to flash the actuator module with ESPHome. This code simply connects it to Wi-Fi and exposes the relay as a switch that Home Assistant can control.
esphome:
name: xiao-water
friendly_name: xiao_water
esp32:
board: esp32-c3-devkitm-1
framework:
type: arduino
# Enable logging
logger:
# Enable Home Assistant API
api:
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
# Enable fallback hotspot (captive portal) in case wifi connection fails
ap:
ssid: "Xiao-Water Fallback Hotspot"
password: "IunbCOy225cs"
captive_portal:
text_sensor:
- platform: homeassistant
entity_id: sensor.xiao_soil_moisture_b4c0f4_soil_moisture_status
id: soil
internal: true
switch:
- platform: gpio
name: "Water Pump Relay"
id: relay_pump
pin: GPIO2
restore_mode: ALWAYS_OFF
Code Breakdown:
api
andwifi
: Standard setup to connect the device to your network and Home Assistant.text_sensor
: This is an optional but good practice. It listens to the state of our soil sensor directly. While we won't use it for automation on the device itself, it's useful for debugging.switch
: This is the most important part. It defines the GPIO pin connected to our relay (pin: GPIO2
) and gives it a friendly name and an ID (id: relay_pump
). This ID is how Home Assistant will find and control it.
This is where the magic happens. We'll create two automations in Home Assistant to handle the different levels of "thirst." You can do this in the Automation Editor in the UI or by adding the YAML to your automations.yaml
file.
Automation 1: The Gentle Drink (Almost Dry)This gives the plant a small, 1-second sip when it's starting to get thirsty.
- id: '1677888001'
alias: 'Plant Watering - Almost Dry'
trigger:
- platform: state
entity_id: sensor.xiao_soil_moisture_b4c0f4_soil_moisture_status
to: 'Almost Dry'
action:
- service: switch.turn_on
target:
entity_id: switch.water_pump_relay # This must match your relay's entity ID
- delay:
seconds: 1
- service: switch.turn_off
target:
entity_id: switch.water_pump_relay
mode: single
Automation 2: The Deep Quench (Dry)This gives the plant a longer, 3-second drink when it's truly dry.
- id: '1677888002'
alias: 'Plant Watering - Dry'
trigger:
- platform: state
entity_id: sensor.xiao_soil_moisture_b4c0f4_soil_moisture_status
to: 'Dry'
action:
- service: switch.turn_on
target:
entity_id: switch.water_pump_relay
- delay:
seconds: 3
- service: switch.turn_off
target:
entity_id: switch.water_pump_relay
mode: single
- Power the Pump Separately! I cannot stress this enough. A water pump draws far more current than a microcontroller's pins can supply. Attempting to power it from the XIAO will damage or destroy your board. Use a dedicated power supply that matches your pump's voltage and use the relay to switch it.
- Calibration is Everything. My "1 second" and "3 second" values are just guesses. The perfect duration depends on your pump's flow rate, your pot size, and your soil type. Start with very short durations, trigger the automation manually, and watch how much water is dispensed. Adjust the
delay
until you're happy. - Prevent a Flood! What happens if your sensor fails or gets stuck in the "Dry" state? The automation could run over and over, emptying your reservoir and drowning your plant. Add a
condition
to your automations to prevent this. For example, add a time condition to only allow it to run during the day, or a cooldown so it can't be triggered more than once every 12 hours. - Water and Electronics Don't Mix. Position your actuator module and power supply away from any potential splashes. A small drip tray is not a bad idea.
With this system in place, I have finally closed the loop. My smart home doesn't just tell me about a problem anymore; it solves it for me. The sensor detects the need, Home Assistant makes a decision, and the actuator takes action.
I've gone from a passive observer to the creator of a fully autonomous ecosystem. My plant is thriving, my desk looks great, and my conscience is clear. This project is a perfect example of how a few simple components and a powerful software platform can create a solution that is genuinely useful, taking one more small task off my plate.
Happy Automating!
Comments