DIY Home Assistant Irrigation Controller

by taste_the_code in Outside > Backyard

4837 Views, 35 Favorites, 0 Comments

DIY Home Assistant Irrigation Controller

How to Build Your Own Smart Irrigation System: DIY Home Assistant Controlled Valve
MVI_0926.MP4.00_00_03_03.Still001.jpg
MVI_0889.MP4.00_00_01_17.Still001.jpg
MVI_0891.MP4.00_00_03_10.Still001.jpg

Last year I installed a drip irrigation system in my backyard garden, but since it was manually operated I wanted to make a smart controller so I can schedule it and have one less chore to do each day.

Since I already have Home Assistant set in my home, I wanted to make a controller that will integrate with Home Assistant, and through it, I can set schedules and automation for the watering without needing to do any manual intervention. The device is integrated using ESPHome which allows for any ESP-based microcontroller to be added to Home Assistant.

The entire project is housed inside an electrical box for which I recently designed custom PCBs that were manufactured by PCBWay and you can order them directly for just $5. Register through this link to get a $5 welcome bonus on your first order so you can get the PCBs for free 😉.

Supplies

MVI_0894.MP4.00_00_26_27.Still001.jpg
MVI_0894.MP4.00_01_16_24.Still002.jpg

The main component of the system is the solenoid valve from a washing machine. These are cheap and reliable valves that are controlled with mains voltage, so you need to be a bit careful with them. There are also solenoid valves that operate on lower voltages so if you are uncomfortable working with mains, then you can use one of those as well.

Below is a list of everything that you'll need for the project:

Test the Circuit

MVI_0897.MP4.00_00_49_19.Still001.jpg

Before making anything permanent, I connected everything up with jumper wires so I can test out the idea. The NTC thermistor is connected in series with another same-value resistor to form a voltage divider. This voltage is then read by the NodeMCU on its analog input. To prevent self-heating on the NTC, the voltage divider is controlled on pin D0 so it is only on while measuring the voltage, and kept off in the meantime.

The relay is connected to the incoming 5V supply on the Vin pin on the NodeMCU and it is controlled by pin D2.

The relevant part of the ESPHome configuration is placed below:

switch:
  - platform: gpio
    id: irrigation_relay
    name: "Irrigation"
    restore_mode : ALWAYS_OFF
    pin:
      number: D2

  - platform: gpio
    pin: D0
    id: adc_vcc

sensor:
  - platform: ntc
    sensor: resistance_sensor
    calibration:
      b_constant: 3950
      reference_temperature: 25°C
      reference_resistance: 10kOhm
    name: "Temperature"
    filters:
      - offset: -2.5

  - platform: resistance
    id: resistance_sensor
    sensor: source_sensor
    configuration: UPSTREAM
    resistor: 9.9kOhm
    name: Resistance Sensor

  - platform: adc
    id: source_sensor
    update_interval: never
    pin: A0
    filters:
      - multiply: 3.3
 
interval:
  - interval: 5min
    then:
      - switch.turn_on: adc_vcc
      - delay: 1s
      - component.update: source_sensor
      - switch.turn_off: adc_vcc

Prepare the Relay

MVI_0901.MP4.00_00_58_26.Still001.jpg
MVI_0902.MP4.00_00_27_23.Still001.jpg
MVI_0903.MP4.00_00_26_10.Still001.jpg

The relay will be housed inside the electrical box so to have its LEDs visible, I extended the wires so I can then mount the LEDs on the electrical box lid.

Additionally, I flipped the pin headers of the relay so they can be soldered from the bottom so the relay can be mounted to the carrier PCB.

Solder Components to the Carrier PCB

MVI_0906.MP4.00_00_58_01.Still001.jpg
MVI_0906.MP4.00_04_10_27.Still002.jpg
MVI_0906.MP4.00_06_01_16.Still003.jpg
MVI_0909.MP4.00_00_34_15.Still001.jpg
MVI_0910.MP4.00_00_27_20.Still001.jpg

Since the entire carrier PCB is a prototyping area, I selected a suitable position for each of the modules and soldered them to it. The NodeMCU module is not directly soldered but, I used female pin headers so it can be later plugged into them.

Add Mains Connection

MVI_0916.MP4.00_00_46_05.Still001.jpg
MVI_0918.MP4.00_00_09_09.Still001.jpg
MVI_0919.MP4.00_01_00_09.Still002.jpg

For the mains connection, I made sure to first thread the wires inside the electrical box and then connect the input to the screw terminal I soldered earlier. From there, the two wires are soldered directly to the HLK-PM01 module that converts the incoming 220V to 5V, and one of the output connections is switched on through the relay so it can turn on the solenoid valve.

Once everything was connected, I threaded the NTC thermistor through the lid and I also mounted the LEDs in the holes I made earlier.

Secure the Enclosure

MVI_0919.MP4.00_00_14_00.Still001.jpg
MVI_0920.MP4.00_00_05_08.Still001.jpg
MVI_0923.MP4.00_00_00_07.Still001.jpg
MVI_0923.MP4.00_00_21_00.Still002.jpg

As a final step, I secured the PCB to the electrical box with a small screw and I then secured the lid of the box.

Enjoy

MVI_0924.MP4.00_00_13_08.Still001.jpg
MVI_0927.MP4.00_01_19_18.Still001.jpg

Because of some bad weather while writing this, I did not mount the controller yet in my yard but it can be very easily connected using some quick-connect hose adapters.

I can now set a schedule through Home Assistant so the garden will be watered automatically while I can use my time to do other stuff, and most importantly, the garden will also be watered while I'm on vacation!

If you liked this project, I have many others as well that you can check out and you can also subscribe to my YouTube channel so you don't miss any future ones.