Skip to main content

Smart wifi controlled irrigation system using Sonoff and Home Assistant on Raspberry Pi - Part 1

If you have a backyard just for the sake of having one or it came with the house and you hate watering your garden or lawn/backyard then you have come to the right place. I genuinely believe that it is a waste of my valuable time. I would rather watch bachelorette on TV than go outside, turn on tap, hold garden hose in hand to water. Too much work!!
Luckily, we have things like sprinkler system, soaker etc which makes things a bit easy. But you still have to get off that comfy couch and turn on tap (then turn off if there's no tap timer in place).


** Skip to the youtube video part if reading is not your thing 


When I first moved into my house at first it was exciting to get a backyard (decent size), but soon that turned on annoyance when it came down maintaining it, specially the watering part. I laid bunch sprinklers and soaker through out the yard and bought tap timer but I still needed to routinely turn on the tap timer. Eventually few days ago I had enough of this rubbish and decided to do something about.

In my opinion, we really should have had talking, walking robots (like the Jetsons) by now to do these pesky house chores; what a disappointment!!

But at least we have IoT; and that's exactly what I used to make the dumb tap timer smart (again).
  • I already have a home automation system (the voice controlled AI I built few years ago which is dumb as potato, but understands some basic commands).
  • I know of cheap wifi switches that's available these days.
  • I know how to program
  • I know how to watch youtube videos.
WHAT Did I Do?
Combining all of the above skills I decided to build a automated or semi automated watering system for my backyard that will
  • Fundamentally, remotely turn on off water in my backyard -- Part 1
  • I can turn it on or off from anywhere in the world using any mobile/tab/laptop. -- Part 1
  • Once it is turned on it will auto turn off after 15 mins -- Part 1
  • I will run without my intervention by analysing weather data and my manual usage -- Part 2
  • Cloud based automation but connected to home assistant -- Part 2

HOW did I do it, exactly? 

The Smart Watering System Project - Part 1

At a very high level 
  • I built a water control system using solenoid valve
  • solenoid valve is connected to a IoT device
  • the IoT device is controlled using home assistant
So, like a true Architect I started with a diagram and I came up with a plan, first.
(** yep I am very particular about planning, in my opinion people who jump on things before planning should go to Mars; Earth ain't a place for them)


  1. Measure tap to ground distance and where (how far away from the tap) the solenoid valve should be placed and cut/use poly pipes to connect waterflow from tap to solenoid valve and solenoid valve to garden hose/soaker/sprinkler.
Setup the water flow from tap:
  1. Attach a "Tap Nut & Tail" to the garden tap and fix poly pipe to ground.
  2. Attach elbow to the join poly pipe from tap and poly pipe to solenoid (so that the solenoid is away from the tap and closed to power source)
  3. Attach a joiner to the solenoid valve and fix the poly pipe to its other end. This is the input pipe to the solenoid.
  4. Attach a 2nd joiner to the other end (output flow) of the solenoid and fix a poly pipe. This is the output pipe.
Setup the power supply from mains:
  1. Solenoid valves are usually 24VAC which means a 220VAC to 24VAC power adaptor needs to be hooked up with the valve wires. You will also need 2 gel caps to secure and waterproof the wire joins.
  2. Get/Buy a Sonoff wifi switch (I bought basic, because I am cheap). And flash it with tasmota firmware so that it connect to Home Assistant using MQTT. !this is important. Because it makes you sound clever. Also there's no way to connect eWilink to HA. The main purpose is to not connect sonoff and HA via cloud rather use it locally as much as possible. In this case flashing with tasmota makes it work locally via MQTT and its super fast.
  3. Add the switch to Home Assistant. !important: this is how you show off to random people how clever you are.
  4. Add the Sonoff switch to an extension chord. This extension chord will plug into the mains power.
  5. Plug the connected adapter to the sonoff extention chord.

Some programming

  • Add Sonoff in Home Assistant (my code below)
switch
- platform: mqtt name: "smart water" state_topic: "smartthings/water/switch 01" command_topic: "cmd/smartthings/water/switch 01" payload_on: "on" payload_off: "off" retain: true
  • Create Script in Home Assistant to turn off the switch after 15 mins
- alias: Turn off water system after running for 15 mins
trigger: platform: state entity_id: switch.smart_water from: "off" to: "on" for: minutes: 15 action: service: switch.turn_off entity_id: switch.smart_water


Power on, Tap on, Switch from HA, See the magic. 
(Once you achieve this and see water flow in your lawn/backyard with a touch from mobile phone with or without being connected to wifi, if this doesn't bring smile/smerk on your face then you sir, are a monster.)

Video /


Photos / 

Bucket full of plumbing stuff

started to assemble things

Plumbing assembled

This is how it is powered

End to end finished system


Things I used to build it:
  • 2 x Tap Nut & Tail == $6
  • 1 x Elbow == $4
  • 2 x 1 metre long poly pipe = $2
  • 6 x poly joiners == $16
  • 6 x clams/rings == $9
  • 1 x Sonoff == $15
  • 1 x Solenoid Valve == $21
  • 1 x Power Cable Extension Chord == $4
  • 1 x 24VAC Adapter == $22



Poly Pipe

Joiner

Solenoid Valve 24VAC

Elbow

Tap Nut & Tail


Sonoff
power adaptor


Why not buy one of them off the shelf stuffs:
Well few reasons..
  • Bluetooth tap controls are shit; sometime works sometime doesn't. On top I am still stuck with "I have to be in the house to turn it on". So I am not truly free. Plus they are not really that cheap.
  • Irrigation controllers are dumb; You put input (they call it program, lolz) to turn on water on a certain day of the week, certain time of the day; But if at that time if it is raining the dumb crap will still turn on water. Plus they are expensive.
  • Finally there are some tap controls that are truly advanced like cloud based, programmable scheduling functionality etc. So these ones can be turned on remotely, programmed to auto turn on, some even comes with rain alert. So OK that would have worked. But I still have issues; like they are expensive as and I am cheap as; so we no match. And there's no "for fun's sake" factor in it. And of course I could not have written this blog post to brag about if I had bought one of these tap controllers.

Price Beat Guarantee

The total amount it costed me is $99. By far I have not found a off the shelf irrigation system that costs cheaper. Plus when I will join the 2nd solenoid valve I will just have to spend $30 more. So for $129 I am getting 2 controlled water flow system. The cheapest off the shelf I found is the B-Hyve wifi tap timer that cost's $139 each so 2 will cost me $278 AUD, that's super expensive for me.


What's next:

  • Build the cloud app (I will post on part 2)
  • Connect it to read from Evernote that will read my preferred days (of the week) for watering 
  • Connect it to trigger HA to trigger solenoid -- So I wont have


Then
Add a 2nd solenoid to water the other side of the backyard. And turn them on off in chrono order.


Pretty cool eh!!

Comments

Popular posts from this blog

Reimagining Logs: Building AI powered Conversational Observability System

It is mid-2025 and the cogs of AI are at full speed. So we (I and Mobin) decided to do our own AI project. We called it "IntelliLogs".  IntelliLogs at a glance: Demo:  https://www.youtube.com/watch?v=OXMlORwyMQk In this post I will describe why we did what we did, what is it that we did and how we did it. I will share my personal experience. I am hoping this will, at least, be an interesting read. Table of contents: Why IntelliLogs What is IntelliLogs How IntelliLogs was developed Future of IntelliLogs Conclusion References Why IntelliLogs: Personal motivation 💪 to this were: Explore and experience what does an AI app look like from an architectural and engineering perspective Explore the realm of Huge LLMs (eg: GPT-4.1-170B,  Gemini Pro etc) vs small LLMs (eg: granite-7b, gemma-4b) Explore the possibilities of model tuning / making a model without being a data scientist. How easy or hard it is, what tools available etc. We also wanted to tackle a "not too far from ...

Hall of justice - Authorisation Greeting System

Ever since I watched the Young Justice EP-1 the security system of the Hall Of Justice and Mount Justice wow-ed me. After all it was built by Batman. You see similar AI driven voice guided system in pretty much in all sci-fi series these days. I always dreamed of having something similar of my own. Well, now I have it (sort of). Although we not quite in the flying cars era yet (disappointment) but IOT powered locks are somewhat normal these days. The adoption rate is great.  Some background: What is this Hall Of Justice Authorisation system? This is the security system that Batman built for Hall Of Justice. The movies haven't shown it yet but there're several scenes in the animated series and comic books. Basically, it is a AI powered voice guided intelligent security system that scans bio signatures (like retina, body dimensions, temperature, heart rate) through a scanning device and identifies which member of the justice league it is, logs entry then gr...

The story of a Hack Job

"So, you have hacked it" -- Few days ago one of the guys at work passed me this comment on a random discussion about something I built. I paused for a moment and pondered: Do I reply defending how that's not a hack. OR Do I just not bother I picked the second option for 2 reasons: It was late. It probably isn't worth defending the "hack vs" topic as the comment passed was out of context. So I chose the next best action and replied "Yep, sure did and it is working great.". I felt like Batman in the moment. In this post I will rant about the knowledge gap around hacking and then describe about one of the components of my home automation project (really, this is the main reason for this post) and use that as an example how hacking is cool and does not always mean bad. But first lets align on my definition of hacking: People use this term in good and bad, both ways. For example: "He/she did a hack job" -- Yeah, that probably...

Jenkins on k8s - can it be this easy?

 As developers or devops we have had a somewhat love and hate relationship with Jenkins like "love oss based ci/cd that can be hosted on any environment with ranges of community plugins for pretty much anything" BUT "hate messy UI, lack of documentations, difficult to configure" etc etc. But this post isn't about pros and cons of Jenkins, rather it is about how you can get Jenkins on your k8s super quick and easy (using Merlin). Git Repo:  https://github.com/alinahid477/jenkinsonk8s Table of contents: Why Jenkins Why Merlin for Jenkins What is Merlin for Jenkins How Merlin for Jenkins works How Jenkins on k8s work Some anticipated FAQs Why Jenkins Jenkins remains a popular choice when it comes to CICD solution with a massive community of users and contributors (despite the fact there are new cool kids in block like Tekton etc). The way I see it (because of our love and hate relationship with it) "Jenkins is not CICD tool that you want it's the CICD t...

Do you even Kubernetes ? - in private cloud

Kubernetes (“koo-burr-NET-eez”) /κυβερνήτης/ - Can be used as noun or verb. Noun "helmsman" or "pilot" or "Orchestrator". We use Kubernetes to achieve resiliency for our application. Verb Perform the act of doing Kubernetes. When done using TKG it is easy but can be super hard if the right tool is not used. Do you even Kubernetes? If I were to survey about how many people in IT industry (regardless of role) knows or at least heard about Kubernetes I would be very surprised if the percentage came out any less than at least 80%. I am curious though, How many people have actually deployed on Kubernetes? How many people have created a Kubernetes cluster? How? The answer could go either way of "Yeah, it's easy" OR "Dude!! it's hard". This is because, in my opinion, it all depends on choosing the right toolset that are fit for purpose. In this post I will create a Kubernetes cluster and deploy a microservice application End-To-End, th...