My Garden Irrigation

UPDATE - 9 June 2020

Version 2 is now (as good as) finished. What I mean is that unless someone finds anything wrong I don’t plan to make any more material changes. That doesn’t mean I won’t tinker with the UI, there is always something there that can be improved on…

Small edit to add: I won’t be announcing any changes on here unless they are significant or I think especially interesting. Keep an eye on Github if you want to be sure to have the latest version of all files.

Version 1 lives on; I know some people are still using it as was I until today when I ripped out my old hardware ready for the new one. So it is still worth giving it a try if your needs are smaller and simpler than provided for by Version 2. As previously stated though, I don’t support it as a matter of course. I will however consider reasonable requests for help.

UPDATE - 23 April 2020

I have just uploaded a the latest iteration of Version 2 (still considered a preview).
Its new home is

For anyone interested in Version 1 (which is the version I am currently using until Version 2 is finalised) I have uploaded it including all fixes and updates, to its new home:

The old repository is still there but should be considered an archive and at some point in the future I will probably delete it.

Update Added, 24 February 2020, amended, 17 April 2020)

I am currently re-writing my system so I will not be updating the existing code again. It is fully functional, has served me well for a couple of summers and in fact I am still using it this summer until I have put the new hardware together and installed some more zones in my garden.

Anyone wishing it use it on v0.103 of HA or later (up to at least v0.108, which is at the time of writing this is the latest version of HA), will need to make some very small updates as detailed here.

I originally wrote here that, “I expect the new version to to be leaner and hopefully easier to maintain and configure for more or less zones, hence simpler for anyone to adapt it to their own use.” I am not sure I entirely achieved that goal but you can see the readme on GitHub for more details :wink:

If you’re interested in jumping straight to v2 in this thread you can skip down to it here. It is fully functional as is but I am calling it a preview as I am still making occasional small changes and also I haven’t actually used it yet in my garden yet as I am still waiting to put the new hardware together).


There is a thread here - Garden Irrigation - which whilst old and long is an excellent resource that I encourage anyone interested in using HA in conjunction with their garden irrigation systems to read. It is full of very useful information and various different ideas and implementations for setting up a system.

Some months ago I posted my own code there and I know from feedback that it was picked up by a few people. It’s been winter here for several months so I haven’t used it for a while but I have been maintaining it to deal with breaking changes and have made a few small additions and improvements based on things I have learnt from others in this forum. I also updated it to work with Lovelace.

I recently had a message form someone asking if I would share the most recent version so I have decided to put the code on GitHub for anyone who is interested.

I of course welcome any feedback.


Awesome stuff. For completeness I would love to see the hardware you have in this thread too, can do?

I’m so close to this adventure now after so many delays. Just waiting on a final design from the irrigation company so we can kick off on the plumbing.

Looks like I’ll be using your code! I’ll be looking to integrate a flow meter - this way I can see how much I have used in the garden and current flow rate per minute, but also if the pipes/solenoids have started leaking (showing an unexpected flow) or if watering isn’t happening when the system says it should be (pump or solenoid fail)…

I’m also looking at a pool top off zone… Should be easy!

Love the simplicity of your solution.


(My hardware should be an esp8266 or esp32 depending on WiFi reception, a small display, and an 8 way relay board - 24v Hunter irrigation gear and Toro fittings)

I am one of those who uses the Klogg code that I still thank the incredible work done, as hardware I use a Sonch 4ch with Tasmota firmware and following this guide ( ) with only 30 $ I did everything! in the past I built the hardware myself but I preferred to use the Sonoff for the low costs.

1 Like

Im doing a similar system currently using Sonoffs and Valves to control each zone of the system. I plan on using my Netatmo system.

Out of interest have you worked out accumulated rainfall? I read through the files but i couldnt find out how you created sensor.rainfall_today

No I haven’t! And I wouldn’t take what I have here too seriously, I have been playing with it a lot but never got anything satisfactory.

I suspect the only reliable method is to have your own rain gauge but please post here or message me if you figure anything out!!!

1 Like

@brendanheyu I’m sorry but I forgot all about you asking about my hardware. I will try and give a few details in the next few days.

@klogg I have the Netatmo rain sensor, however i dont receive the accumulated rainfall, so i have had to make my own sensor and take a good guess at what the measurement is!

However, your system does look very good! I am hoping to get all of mine sorted in the next 4 weeks ready for the start of April!

Let me know if you use it :slight_smile:
Or of course make any improvements…

Sorry it’s been a while but here is my hardware.

I use a Sonoff 4ch which provides power via some transformers housed in a weather proof cabinet

to an eZyvalve 4 Solenoid Valve Box 24V. I use Rainbird Pop Up sprinlers.

I have a 5th zone which is separate as we only set it up when we go on holiday and it too uses a Sonoff Basic and another of the same transformers and has it’s own valve. It feeds some drip lines and a soaker hose.

I am pretty sure I haven’t done things the most economical way but it works :slight_smile:
And better still my wife (who is chief gardener here) loves it and appreciates HA because of it :wink:



That really looks quite serious! So you have 240v being switched - that feeds the 240-24v lines to the solenoids?

That will outlive you! nice!


Why have 4 transformers? Do you ever run more than one station at a time?
I run a single transformer and switch the 24VDC side with relays connected to an ESP8266.

You have certainly put A LOT of effort into the control side of things regards to weather offsets etc. (well done!) I went with a basic approach and just look at any rainfall that has been recorded prior to the irrigation running, or the chance of rainfall for the rest of the day. No where near as impressive as what you have.

Love what you’ve done here. I’m just starting out with my gardens and looking at my options. Rainmachine is one option I really like, but looking at the DIY before I go that way.

Also love that Solenoid Valve Box. Where did you get that from?

Would a newer Sonoff 4CH Pro (or Pro 2) do the same as what you’ve done here, but without the transformers?

Great ideas. I am still at the workbench stage. So far I have a single Nodemcu esp8266 driving 16 relays using esphome. My plan is to have 2 separate zones but using a esp32, one zone for the back yard, the other for the front.

On my todo list:
For each ESP32:

  • 8 ouputs (easily expand) driving the relays
  • 8 inputs (easily expand) to allow manual operation via a rotary switch with manual over-ride (Something the wife wants), albeit this still talk to hass. So you can switch between auto or manual.
  • Bluetooth to receive from miplant sensors due to their limited range and relay to hass

While the ESP32 has bluetooth I haven’t actually tried it as per above yet.
All of my valves run off 24VAC.

Just a little pic of the NodeMCU ESP8266 with 16 relays. I did do it with 80 relays, just to see how it would go, and it was fine. Only tried 80 as I ran out of relays. Not that I could see myself ever needing that many.


Yes… As I have already said this was the first thing I did with HA and coming from an entirely ‘Big Corporate’ IT background I had never really come across ‘small’ IT before. This was my first RPi and I had never even heard of Arduino or NodeMCU, never really had any visibility of (dare I say it) ‘hobbyist’ sensors and still thought a breadboard was something you, err, cut bread on. That along with only having (proficient) DIY level electrical skills means that, yes I am pretty sure now that what I have done was overkill!

Because I didn’t know any better! To be honest I’m still not confident enough to play with mains wiring unless I am 100% sure it will work and be safe. I’m getting there though… (and see above, you can add ESP8266 to the list of invisibility!)

Yes but whilst what I have done might look impressive and does provide (I think) a solid framework it sounds like you have something that actually uses rainfall data! Where do you get the amount of rainfall prior to irrigation running?

Thank you. The solenoid valve box is I think an Australian product but widely available in the UK (which is where I am) - I got it from here and yes, as I said, I am sure there are more economical ways of doing this.

I’m not sure about the new Sonoff 4CH, but I don’t think so. I won’t say anymore because I am not qualified to (or confident yet of my ability to be correct!!) but if you find out otherwise that would be a good solution.

@Paul_Flavel This just highlights how little I know! I understand everything you are say but could never have come up with it myself!!

One final point in my defence… I discovered HA in March and we needed something in place by June, including my wife and I digging in all the water hoses, and we all know how long it takes to get used to HA and yaml :rofl: so to be honest I was only too happy to spend a bit more on the hardware and remove the pressure of the learning curve for the electronics side.

Thanks all for the feedback, I hope what I have done is useful to others, it’s nice to give something back after all the other help I’ve had from this community.

My weather provider gives a percentage chance of rainfall for the day and a value (mm) that is expected, at said percentage chance. I use those figures with an adjustable cut-off as a condition

All good. Doesn’t hurt to ask. I’m still researching my options.

I suggest doing what I have: ESP8266 controlling a relay board. Run a single 24v transformer and switch it through the relays to each solenoid. Cheap, easy and HA loves ESP’s with ESPhome :grin:


I have one on order to have a play with and learn. No idea what to do with it yet, but I may just have a new project now.

This looks really good <3. Looking forward to see how rain calculations works. I used your work last summer and it worked fantastic. Looking forward to update my HA today with this. I am using sainsmart 16 relays and ESP8266 flashed with konnected to controll my irrigation. Flashed konnected because I found it more reliable then ESPhomeyaml. Only thing I would suggest is to post lovelace snipps to your first thread.

Good idea. Done!

I’m not sure it works as is. All you need to do though is give it the right data source and it should work. I have yet to find any reliable or useful rainfall data to use for my area.