Automatic garden/sprinkler irrigation system with sonoff basic and solenoid valve

I automated my garden drip irrigation system and sprinkler with a sonoff basic and electric solenoid valve all for about $40.

Parts

Picture of the install:

The sonoff was flashed with tasmota and then setup as a standard MQTT switch in home assistant:

- platform: mqtt
  name: "Back Hose"
  state_topic: "stat/backhose/POWER"
  command_topic: "cmnd/backhose/POWER"

Next the sonoff was just directly wired into the valve. The valve takes 110v AC and is NC (normally closed) so it’s off unless the sonoff is supplying power. This gives you a little extra safety in that if power goes out, the hose will be off by default.

Then the plumbing parts were all snapped together and put into the 1/2 line that feeds our back hose bib. Sharkbite makes this process as easy as legos now, as it all just snaps together. You will need a basic copper pipe cutter if you don’t have one already.

Finally, the whole thing was automated with Node-RED – if the rain chance is greater than 50% for the day, the watering will be automatically disabled – otherwise the watering will run on the normal schedule:

Image:

Flow:

https://hastebin.com/olekajojij.json

Bonus picture of garden:

Let me know if you have any questions! This solenoid was recommended by /r/homeautomation but I can’t find the thread now. Whole system has been working very well and it will be nice to automatically have the entire system off and depressurized when not in use and also to not have to manually postpone watering during spring rain storms!

6 Likes

Great idea!!! Unfortunately I’m running 24VAC solenoids and need a step down (from 230V to 24V) or how it’s called. Not sure how to do that.

couldn’t you just use a modified Sonoff as a dry contact to supply 230v power to the input of your existing 24vac transformer? This is assuming you don’t have 110v power available for the sonoff to control directly. That would be easier of course.

Hmm. Might be an option, although I would have to use 4x transformer/adapter because it is a 4 zone system. 4x Sonoff, 4x adapter comes to 60-80 bucks. I might just order an OpenSprinkler solution to control with hass then (or bypass hass if something is wrong).

Thanks for the suggestion, I’ll keep it in mind.

Hi UltraSub, you can use a 220 v ac to 24 vac transformer and control it with sonoff basic or dual even 4ch pro r2

You might have already found a solution. But I am about to use this Sonoff 4ch pro with tasmota as my irrigation controller for a two zone 24v irrigation system. More info:

Just found this project, which is great, which weather componant did you use to check rain chance? Thanks

I used to use Weather Underground, now using Dark Sky. Rain accumulation via Acurite wireless sensor and a RTL-SDR

Thanks, did you update your node red flow? I’ve managed to use the one you linked in the thread to get something up and running for my system. but interested to see if you’ve changed or tweaked your flow at all?

Thanks

It’s about the same, I think I added a few little changes like skipping watering if there was heavy rain the day before:

[{"id":"6a58a43e.6bf84c","type":"comment","z":"8bb76918.ef6b48","name":"Turn on the back hose when needed","info":"","x":165,"y":2432.5000286102295,"wires":[]},{"id":"a381743e.036fd8","type":"api-current-state","z":"8bb76918.ef6b48","name":"Rain chance","server":"e2a02faf.48099","outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"sensor.dark_sky_precip_probability","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":382,"y":2472.4999961853027,"wires":[["e8967922.2ff208"]]},{"id":"e8967922.2ff208","type":"switch","z":"8bb76918.ef6b48","name":"Under 70%","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"70","vt":"num"},{"t":"gte","v":"70","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":560,"y":2472.4999961853027,"wires":[["ec5bf6e2.f8ab18"],["846deb67.735a58"]],"outputLabels":["Not rainy","Rainy"]},{"id":"31d251d7.58969e","type":"api-call-service","z":"8bb76918.ef6b48","name":"Turn on back hose","server":"e2a02faf.48099","service_domain":"switch","service":"turn_on","data":"{ \"entity_id\": \"switch.back_hose\" }","mergecontext":"","x":1175,"y":2552.5000286102295,"wires":[[]]},{"id":"4abc0609.b8c228","type":"bigtimer","z":"8bb76918.ef6b48","outtopic":"","outpayload1":"","outpayload2":"","name":"Four AM","lat":"40.173508","lon":"-92.58988","starttime":"240","endtime":"300","startoff":"-1","endoff":"1","offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":false,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":false,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"suspend":false,"random":false,"repeat":true,"atstart":false,"odd":false,"even":false,"x":85,"y":2492.5000286102295,"wires":[[],[],["34d839db.5700a6"]]},{"id":"34d839db.5700a6","type":"switch","z":"8bb76918.ef6b48","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":215,"y":2532.5000286102295,"wires":[["a381743e.036fd8"],["178b6065.441b8"]]},{"id":"6e1face1.44b7e4","type":"bigtimer","z":"8bb76918.ef6b48","outtopic":"","outpayload1":"","outpayload2":"","name":"Four PM","lat":"40.173508","lon":"-92.58988","starttime":"960","endtime":"1020","startoff":"-1","endoff":"1","offs":0,"outtext1":"on","outtext2":"off","timeout":1440,"sun":true,"mon":true,"tue":true,"wed":true,"thu":true,"fri":true,"sat":true,"jan":false,"feb":true,"mar":true,"apr":true,"may":true,"jun":true,"jul":true,"aug":true,"sep":true,"oct":true,"nov":true,"dec":false,"day1":0,"month1":0,"day2":0,"month2":0,"day3":0,"month3":0,"day4":0,"month4":0,"day5":0,"month5":0,"d1":0,"w1":0,"d2":0,"w2":0,"d3":0,"w3":0,"d4":0,"w4":0,"d5":0,"w5":0,"suspend":false,"random":false,"repeat":true,"atstart":false,"odd":false,"even":false,"x":85,"y":2572.5000286102295,"wires":[[],[],["34d839db.5700a6"]]},{"id":"54e3e140.59ded","type":"api-current-state","z":"8bb76918.ef6b48","name":"Stop if back hose is off","server":"e2a02faf.48099","outputs":1,"halt_if":"off","entity_id":"switch.back_hose","x":885,"y":2732.5000286102295,"wires":[["65e71ef6.a3277","6d3d7624.6eb058"]]},{"id":"65e71ef6.a3277","type":"api-call-service","z":"8bb76918.ef6b48","name":"Turn off back hose","server":"e2a02faf.48099","service_domain":"switch","service":"turn_off","data":"{ \"entity_id\": \"switch.back_hose\" }","mergecontext":"","x":1215,"y":2732.5000286102295,"wires":[[]]},{"id":"43fb3565.06486c","type":"change","z":"8bb76918.ef6b48","name":"Back Hose Auto variable set to true","rules":[{"t":"set","p":"back_hose_auto","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1225,"y":2512.5000286102295,"wires":[[]]},{"id":"178b6065.441b8","type":"switch","z":"8bb76918.ef6b48","name":"Stop if back hose was not automatically turned on","property":"back_hose_auto","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":475,"y":2612.5000286102295,"wires":[["54e3e140.59ded","ed831830.dfc978"]]},{"id":"ed831830.dfc978","type":"change","z":"8bb76918.ef6b48","name":"Back Hose Auto variable set to false","rules":[{"t":"set","p":"back_hose_auto","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":935,"y":2772.5000286102295,"wires":[[]]},{"id":"846deb67.735a58","type":"api-call-service","z":"8bb76918.ef6b48","name":"Notify Walt","server":"e2a02faf.48099","service_domain":"notify","service":"ios_walts_iphone","data":"{ \"message\":\"Not turning on back hose due to rain chance\"}","mergecontext":"","x":775,"y":2592.5000286102295,"wires":[[]]},{"id":"d9985f81.e3c9f","type":"inject","z":"8bb76918.ef6b48","name":"10PM","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"00 22 * * *","once":false,"onceDelay":0.1,"x":125,"y":2792.5000286102295,"wires":[["d07eaa17.8be018","aab18bea.cfcdb8"]]},{"id":"911bd173.bac08","type":"comment","z":"8bb76918.ef6b48","name":"Turn off hose at 10PM","info":"","x":125,"y":2752.5000286102295,"wires":[]},{"id":"d07eaa17.8be018","type":"change","z":"8bb76918.ef6b48","name":"Back Hose Auto variable set to false","rules":[{"t":"set","p":"back_hose_auto","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":295,"y":2872.5000286102295,"wires":[[]]},{"id":"8f0f86a4.21db68","type":"api-call-service","z":"8bb76918.ef6b48","name":"Turn off back hose","server":"e2a02faf.48099","service_domain":"switch","service":"turn_off","data":"{ \"entity_id\": \"switch.back_hose\" }","mergecontext":"","x":575,"y":2872.5000286102295,"wires":[[]]},{"id":"aab18bea.cfcdb8","type":"api-current-state","z":"8bb76918.ef6b48","name":"Stop if back hose is off","server":"e2a02faf.48099","outputs":1,"halt_if":"off","entity_id":"switch.back_hose","x":345,"y":2792.5000286102295,"wires":[["8f0f86a4.21db68","2922e29a.82534e","2d20e00b.23eb3"]]},{"id":"2922e29a.82534e","type":"api-call-service","z":"8bb76918.ef6b48","name":"Notify Walt","server":"e2a02faf.48099","service_domain":"notify","service":"ios_walts_iphone","data":"{ \"message\":\"Back hose was on, turning it off now\"}","mergecontext":"","x":555,"y":2832.5000286102295,"wires":[[]]},{"id":"ec5bf6e2.f8ab18","type":"api-current-state","z":"8bb76918.ef6b48","name":"Heavy rain yesterday?","server":"e2a02faf.48099","outputs":1,"halt_if":"","entity_id":"input_boolean.heavy_rain_yesterday","x":805,"y":2512.5000286102295,"wires":[["9bfe705a.e25fe"]]},{"id":"9bfe705a.e25fe","type":"switch","z":"8bb76918.ef6b48","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"},{"t":"eq","v":"on","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":975,"y":2512.5000286102295,"wires":[["31d251d7.58969e","43fb3565.06486c","3d91b969.12ee96"],["e85ff99d.8948c8"]],"outputLabels":["No heavy rain yesterday",null]},{"id":"e85ff99d.8948c8","type":"api-call-service","z":"8bb76918.ef6b48","name":"Notify Walt","server":"e2a02faf.48099","service_domain":"notify","service":"ios_walts_iphone","data":"{ \"message\":\"Not turning on back hose due to heavy rain yesterday\"}","mergecontext":"","x":1155,"y":2652.5000286102295,"wires":[[]]},{"id":"c5e1fcf3.67602","type":"comment","z":"8bb76918.ef6b48","name":"Monitor rainfall for last 24 hours","info":"","x":186,"y":2939.5,"wires":[]},{"id":"ff7ce1f6.d9e7e","type":"switch","z":"8bb76918.ef6b48","name":"Over half an inch","property":"payload","propertyType":"msg","rules":[{"t":"gt","v":"0.5","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":547,"y":2980.5,"wires":[["577f7ce6.8deb84","d513b0b3.bfbe5"]]},{"id":"577f7ce6.8deb84","type":"api-call-service","z":"8bb76918.ef6b48","name":"Turn on heavy rain input boolean","server":"e2a02faf.48099","service_domain":"input_boolean","service":"turn_on","data":"{ \"entity_id\": \"input_boolean.heavy_rain_yesterday\"}","mergecontext":"","x":866,"y":2981.5,"wires":[[]]},{"id":"f71999ad.d7cab8","type":"api-call-service","z":"8bb76918.ef6b48","name":"Turn off heavy rain input boolean","server":"e2a02faf.48099","service_domain":"input_boolean","service":"turn_off","data":"{ \"entity_id\": \"input_boolean.heavy_rain_yesterday\"}","mergecontext":"","x":1040,"y":3052.5,"wires":[[]]},{"id":"f37b7a4.a480088","type":"comment","z":"8bb76918.ef6b48","name":"Rainy","info":"","x":755,"y":2552.5000286102295,"wires":[]},{"id":"e9e2afa2.d87de","type":"comment","z":"8bb76918.ef6b48","name":"Low rain chance forecasted","info":"","x":825,"y":2472.5000286102295,"wires":[]},{"id":"457e1f0b.e2bc","type":"comment","z":"8bb76918.ef6b48","name":"But it rained hard yesterday","info":"","x":1205,"y":2612.5000286102295,"wires":[]},{"id":"ce415b20.6e20d8","type":"comment","z":"8bb76918.ef6b48","name":"Water!","info":"","x":1135,"y":2432.5000286102295,"wires":[]},{"id":"3d91b969.12ee96","type":"api-call-service","z":"8bb76918.ef6b48","name":"Logbook entry","server":"e2a02faf.48099","service_domain":"logbook","service":"log","data":"{ \"name\":\"Node-Red\",\"message\":\"Turning on back hose\" }","mergecontext":"","x":1165,"y":2472.5000286102295,"wires":[[]]},{"id":"6d3d7624.6eb058","type":"api-call-service","z":"8bb76918.ef6b48","name":"Logbook entry","server":"e2a02faf.48099","service_domain":"logbook","service":"log","data":"{ \"name\":\"Node-Red\",\"message\":\"Turning off back hose\" }","mergecontext":"","x":1205,"y":2772.5000286102295,"wires":[[]]},{"id":"2d20e00b.23eb3","type":"api-call-service","z":"8bb76918.ef6b48","name":"Logbook entry","server":"e2a02faf.48099","service_domain":"logbook","service":"log","data":"{ \"name\":\"Node-Red\",\"message\":\"Turning off back hose for the night - Found that it was left on\" }","mergecontext":"","x":565,"y":2792.5000286102295,"wires":[[]]},{"id":"4ea198a6.8c5778","type":"comment","z":"8bb76918.ef6b48","name":"Turn off hose at end of scheduled unless it was turned on manually","info":"","x":1025,"y":2692.5000286102295,"wires":[]},{"id":"695971ea.8e33f","type":"server-state-changed","z":"8bb76918.ef6b48","name":"Rainfall accumulation in last 24 hours","server":"e2a02faf.48099","entityidfilter":"sensor.acurite_875_rain_last_24h_in","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":210,"y":2982,"wires":[["ff7ce1f6.d9e7e","8a73ad3b.2f09f"]]},{"id":"8a73ad3b.2f09f","type":"api-current-state","z":"8bb76918.ef6b48","name":"Stop if heavy rain is off","server":"e2a02faf.48099","outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.heavy_rain_yesterday","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","x":487,"y":3031,"wires":[["a47deea6.9f73c"],[]]},{"id":"a47deea6.9f73c","type":"switch","z":"8bb76918.ef6b48","name":"Under 0.25 inches","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"0.25","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":766,"y":3045,"wires":[["f71999ad.d7cab8","63d9f91a.b22c18"]]},{"id":"d513b0b3.bfbe5","type":"api-call-service","z":"8bb76918.ef6b48","name":"Logbook entry","server":"e2a02faf.48099","service_domain":"logbook","service":"log","data":"{ \"name\":\"Node-Red\",\"message\":\"Heavy rain ({{payload}} inches) in last 24 hours. Turning on heavy_rain input boolean\" }","mergecontext":"","output_location":"payload","output_location_type":"msg","x":812,"y":2923,"wires":[[]]},{"id":"63d9f91a.b22c18","type":"api-call-service","z":"8bb76918.ef6b48","name":"Logbook entry","server":"e2a02faf.48099","service_domain":"logbook","service":"log","data":"{ \"name\":\"Node-Red\",\"message\":\"Accumulated rainfall has dropped ({{payload}} inches) in last 24 hours. Turning off heavy_rain input boolean\" }","mergecontext":"","output_location":"payload","output_location_type":"msg","x":983,"y":3108,"wires":[[]]},{"id":"e2a02faf.48099","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

1 Like

@walt thanks for sharing :slight_smile:

@walt I’ve just looked at your node red flow to the rain yesterday. I like the idea of using rain yesterday Could you explain how you setup the input boolean switch for that, was it with another node red flow? Thanks

The integration with a ground humidity sensor will be useful. I have almost the same configuration, but I’m manually start the sprinkler and after 15 min using automation.yaml the sprinkler is off + iOS notifications

Just a simple input_boolean to save state, since the old Weather Underground integration would only report the rainfall for the current calendar day.

input_boolean:
  heavy_rain_yesterday:
    name: 'Heavy rain yesterday'

My new setup, I keep a sliding window of the rainfall in the last 24 hours via Node-RED persistent context, so this isn’t strictly needed any more.

https://hastebin.com/esinitoyot.json

1 Like

If you use a timer, like I do, I would set them on your device itself. I use tasmota on the Sonoff 4ch Pro, which has a timer function build in. With this setup, even when your home assistant is down, your garden will get water, and maybe more important, it will switch the valve off after the set time. In your case, if you restart home assistant, or it become unstable within the 15 minutes, the main tap will stay open.

You can still use the state off the relay for notifications.

Thanks for this project! Just wondering, is this outside? I’m thinking of doing this myself as I need a simple on/off for my single zone watering, but here in NJ the temps get low in winter and I noticed the solenoid says minimum temp 23 fahrenheit.

I have my solenoid inside a heated garage. If you need something outside I would look at 12v/24v AC irrigation valve.

1 Like

Thank you very much … walt … been wanting to do this irrigation automation for a long while, being fed up with my old set up of a all in one stand alone 3 zone controller with limited input / output, i decided to bite the bullet and get a few solenoids and a sonoff 4ch to start and build it into the 3 zones i had and have home assistant do the controlling, and also use it manually when needed.

only thing i was missing was an example config and after searching and trying different bits in yaml / node red etc i nearly gave up, as they did not work ? i was just going to use a timer template, i saw yours and thought its a bit complicated but its what i wanted with rain delay etc anyway i just changed what i needed in the node red flow and tested the automation and it worked a treat.

Thank you very much walt.

1 Like

Awesome, good deal! Are you in your growing season? I’m waiting for spring where I live to turn this all back on and get out in the garden!

Not yet but prepping ready to go and this was one of my goals to get going, along with my revamped raised bed due to my old one rotted away, so it was a good time to sort it all out, and it’s that time of year to get some seedlings in ready for when the weather warms up, but to be honest it keeps changing each year and sporadic in the uk, the seasons sort of drift if you no what i mean, at the moment some parts are experiencing snow and we have storm Dennis hitting us this week, two storms in as much weeks weird but expected with this global warming and stuff :slight_smile:
going from stand alone to DIY which i think was worth it.
![FullSizeRender|690x386]

(upload://3kbAJCyHBrx9n5rbhOAbBzfQXcA.jpeg)

3 Likes