DIY Home Assistant Irrigation Controller
by taste_the_code in Outside > Backyard
4837 Views, 35 Favorites, 0 Comments
DIY Home Assistant Irrigation Controller
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
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:
- NodeMCU - https://s.click.aliexpress.com/e/_DCidiwV
- Relay Module - https://s.click.aliexpress.com/e/_DmQ7eGv
- NTC Thermistor - https://s.click.aliexpress.com/e/_DeucEI5
- 220V to 5V module - https://s.click.aliexpress.com/e/_DkbyFPj
- Low Voltage Solenoid valve - https://s.click.aliexpress.com/e/_DlHysWl
- Brass solenoid valve - https://s.click.aliexpress.com/e/_Ddk2tFj
- Solenoid valve with hose attachment - https://s.click.aliexpress.com/e/_DkoJV4z
- Soldering iron - https://s.click.aliexpress.com/e/_DlP3Fj3
- NPN Transistor - https://s.click.aliexpress.com/e/_DDOBNtX
- Resistors - https://s.click.aliexpress.com/e/_DCUjGtF
- Electrical box black - https://s.click.aliexpress.com/e/_Dl1bHVn
- Electrical box white - https://s.click.aliexpress.com/e/_DlIegup
Test the Circuit
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
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
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
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
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
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.