Smart Irrigation Controller with Tasmota and Home Assistant

I've recently been working on a smart, wifi-enabled irrigation or watering controller for my garden, and have finally got it up and running. I'll start with a picture of the finished product, so you know where this is heading.


I had a few ideas for how to achieve this, and over the last few months I've been examining different options, and recently took the plunge and purchased some hardware. I've been doing a number of projects with ESP8266 based hardware, Tasmota firmware, and Home Assistant and so it was inevitable any solution I put in place would feature those elements.

We have an existing Holman irrigation system, which can control up to 6 stations. It is connected to a set of 4 solenoids that require a 24 Vac signal to open a solenoid and allow the water to flow. You can see some images of the existing system below.



My plan was to use a set of 4 relays to control the 24 Vac signal to the solenoids, ideally with the relays connected to an ESP8266 module. I eventually came across this 4 channel relay board made by LCTech, similar to this. This device uses an ESP-01 module, with an ESP8266 chip. You can see some images below, with and without the ESP module attached.



The relays, and the board, require 12 Vdc power. I wanted to run this off the same 24 Vac power supply used by the Holman watering controller, and required by the solenoids, so I also needed to find a power converter that would let me convert 24 Vac to 12 Vdc. I ended up finding this module from a seller on eBay, which uses an LM2596HV DC-DC step down regulator, and a bridge rectifier for AC-DC conversion. You can see an image below:


Strangely I was only able to find this module from a single eBay seller, and it is no longer available. I think I now understand the reason for this, and will explain further later.

I configured the power converter to supply 12 Vdc.



I wanted to flash the ESP-01 with Tasmota, so I connected it to my CH340G USB to serial adaptor, following these instructions. It's worth noting that the 3V3 and EN pins on the ESP-01 both need to be connected to the 3V3 signal from the CH340G. Also, GND and IO0 on the ESP-01 both need to be connected to GND on the CH340G, the latter so that the device will enter flash mode. You can see my setup below, using duPont cables and a breadboard. I flashed Tasmota 8.1.0 using NodeMCU-pyFlasher.


I then hooked up the power supply and the relay module. You can see both devices here.


Then I completed the configuration of Tasmota. In addition to my usual Tasmota configuration, it was necessary to do some specific configuration for the relay modules. The relay module has a secondary micro-controller which the ESP-01 communicates with via serial. As usual, there was some excellent information in the Tasmota documentation to help with the configuration.

The template I used is here.

 {"NAME":"LCTech 4CH Rel","GPIO":[52,255,17,255,255,255,255,255,21,22,23,24,255],"FLAG":0,"BASE":18}

And the template configuration in the Tasmota GUI can be seen here.


The template just seems to involve setting up dummy buttons and relays that can be used to execute serial commands using rules. 

The rules that I applied were as follows.

 Rule1 
  on System#Boot do Backlog Baudrate 115200; SerialSend5 0 endon
  on Power1#State=1 do SerialSend5 A00101A2 endon
  on Power1#State=0 do SerialSend5 A00100A1 endon
  on Power2#State=1 do SerialSend5 A00201A3 endon
  on Power2#State=0 do SerialSend5 A00200A2 endon
  on Power3#State=1 do SerialSend5 A00301A4 endon
  on Power3#State=0 do SerialSend5 A00300A3 endon
  on Power4#State=1 do SerialSend5 A00401A5 endon
  on Power4#State=0 do SerialSend5 A00400A4 endon

The first line of the rule involves setting the baud rate on startup. I actually had some issues with this as the instructions I mentioned earlier proposed setting the baud rate to 9600. I found that when the baud rate was set to 9600 the serial commands did not work after MQTT was enabled. But, setting the baud rate to 115200 seemed to resolve that issue.

The remaining lines send serial commands to the secondary micro-controller for the change in state of each dummy button.

After this, I could successfully switch the relays on and off using the Tasmota web GUI, as shown below.


The next step was to get the hardware into an enclosure so that I could install it outside. I decided on this sealed enclosure, which you can see below. I figured this would give me enough space to install the components and manipulate any cabling.



I obtained some cable glands and solid core CAT6 cable to allow me to establish connections in and out of the enclosure. I also obtained some nylon spacers and screws to allow me to attached the modules to the enclosure.

I drilled holes for the cable glands, and firstly used hot glue to attach the nylon spacers to the enclosure. I later found that the hot glue was inadequate, and switched to using clear Gorilla glue, which seems to to be working so far.




One of the problems I needed to solve was how to get power into the enclosure. The 24 Vac power adaptor I had used for testing was not suitable for use outside. The power supply in the Holman irrigation controller would have been suitable, but it would have been necessary to sacrifice the Holman controller to install that power supply in my new controller, which I was reluctant to do until I knew it was going to work.

The solution I eventually came up with, was to piggy-back on the power supply in the existing Holman irrigation controller, but leave the Holman unit operating. I also realised that if I connected the two controllers up cleverly, I could leave them both functional, meaning that I could control the solenoids through either controller. This required me to wire up the solenoids such that the controllers acted as parallel switches. I needed 7 separate connections between the controllers to do this, and fortunately the CAT6 cable I was using had 8.

So, then I was ready to start connecting the new controller. I ran the CAT6 cable between the two controllers, and connected the cable from the solenoids to the new controller.




After I turned on the power, everything seemed to work as expected. I was able to turn on the 4 solenoids using either the Holman or new controller. After a few moments of self-congratulation, I commenced the necessary setup in Home Assistant.

As these were basically simple Tasmota switches, I added the necessary entities into my configuration.yaml file, following the instructions in the Tasmota documentation. You can see an example for one switch below.

 switch: 
   - platform: mqtt
     name: "Water Beds"
     state_topic: "stat/re_lct_01/RESULT"
     value_template: "{{ value_json.POWER1 }}"
     command_topic: "cmnd/re_lct_01/POWER1"
     availability_topic: "tele/re_lct_01/LWT"
     qos: 1
     payload_on: "ON"
     payload_off: "OFF"
     payload_available: "Online"
     payload_not_available: "Offline"
     retain: false

I then added the entities into my lovelace configuration in Home Assistant.


For scheduling of the irrigation controller, I had a few different ideas, but the one I moved forward with was to use the Google Calendar integration in Home Assistant to allow turning the switches on and off based on appropriately named calendar entries in Google Calendar. I have a Google account I use specifically for Home Assistant related tasks (such as this one), and I used it again here. After obtaining the necessary credentials by following the instructions in the Home Assistant documentation, I added the following to my configuration.yaml file.

 google:
  client_id: XXXXXXXXXXXXXXXXXXXXXXXX
  client_secret: XXXXXXXXXXXXXXXXXXXXXXXXX

After restarting Home Assistant, a google_calendars.yaml file was created, which I edited as follows, so that it had a calendar entity for each switch, with the same name as each switch, and which searches for calendar entries with the same name.

 - cal_id: XXXXXXX@XXXXXXX.com
   entities:
   - device_id: all
     ignore_availability: true
     name: All
     track: true
   - device_id: water_beds
     ignore_availability: true
     name: Water Beds
     track: true  
     search: "Water Beds"
   - device_id: water_trees
     ignore_availability: true
     name: Water Trees
     track: true  
     search: "Water Trees"
   - device_id: water_front
     ignore_availability: true
     name: Water Front
     track: true  
     search: "Water Front"
   - device_id: water_pots
     ignore_availability: true
     name: Water Pots
     track: true  
     search: "Water Pots"

Then I set up automations to turn on the switches when calendar entries started and stopped. I needed one for each switch. You can see an example below.

 automation:
   - id: water_beds_calendar
     alias: Water Beds Calendar
     trigger:  
       - platform: state
         entity_id: calendar.water_beds
     action:
       - service_template: "switch.turn_{{ states('calendar.water_beds') }}"
         data:
           entity_id: switch.water_beds

And here are some sample recurring calendar entries in the Google calendar that are being used to control the irrigation system.



One thing to watch out for is that the Google calendar gets read by Home Assistant every 15 minutes, so I can't reliably schedule a watering event less than 15 mins in advance. That's fine though.

Anyway, just as I was about to commend myself again for setting this up, I checked back on the switches in Home Assistant, and found that they had all become unavailable. My new controller had failed... damn.

Further investigation showed that the power converter that was converting 24 Vac to 12 Vdc was now only providing about 0.3 Vdc to the relay module; that was not going to be enough.

My first thought was that something was wrong with my wiring, and that I was inadvertently sending 24 Vac somewhere it wasn't meant to be, and had damaged a component. So, I disassembled everything and got the power supply and relay module running again on my bench. Although the ESP-01 had lost its configuration and needed to be reconfigured, everything was working fine.

A few days later I install the new controller outside again, paying extra careful attention to the wiring this time. Again, everything worked fine for about half a day, and then it failed again.

My best guess at the cause was that the power converter was overheating, or failing in some way. However, it had been hard to find a suitable power converter the first time, and there didn't seem to be many all-in-one options available. I also wasn't able to repurchase another from the seller of the original item, so I suspect there may have been problems with the design that meant they had stopped selling it.

Eventually I came across this power converter that is intended for CCTV applications. It looked a bit more robust. Unfortunately it was also more expensive, but I took the plunge and purchased it.


You can see it set installed in the enclosure here.


Again, I went through the process of installing the new controller, alongside the existing Holman controller. The end result is here.




You can also see a wiring diagram below. I suspect it's unlikely anyone else will implement a setup identical to this, but perhaps it will help to provide a few ideas.


The system has now been running successfully for a few weeks, and appears to have been stable in that time. Our garden beds are being adequately watered, and the system is now much easier to schedule. Further, if we are away and see some hot or wet weather coming up, we can change the schedule accordingly. So, overall I think it's been a success. 

Further, as I have my Home Assistant entities exposed to Google Home, I can also control the irrigation system with voice commands, which is cool, but not actually that useful. 

There are also plenty of options for improvement in future. Next I'm planning to set up some smarter scheduling to alter watering durations based on temperature and humidity sensors I have installed around the house, or weather forecasts, and potentially I'll install a rainfall sensor to inform this as well.



Comments

  1. Thanks for sharing. I'll be using the relay board out of an old controller I salvaged to do something similar. This has given me lots of food for thought.

    ReplyDelete
    Replies
    1. Cool. Glad you found it useful. Good luck with your project.

      Delete
  2. Excellent work , Did u succeeded to combine it with sensors ? Humidity and Temperature ?

    ReplyDelete
    Replies
    1. I'm still working on it, but I haven't converged to a solution yet. I think any algorithm would need to consider both the historical and forecast conditions. I have a number of temperature and humidity sensors around the house, and I've been looking at the data from them to see if I could use it to make rules to alter the watering times, but a clear approach hasn't jumped out at me. I also have darksky forecasts in Home Assistant. But I don't have any actual rainfall data yet, which would be useful. There is some good discussion about different approaches on the Home Assistant forums here.

      Delete
  3. So it not a problem to control 24v solenoid valve with 12v onboard relay?

    ReplyDelete
    Replies
    1. Ok i see, it is 30v Dc also

      Delete
    2. The relay is powered by 12 Vdc, but can switch up to 240 Vac or 30 Vdc at 10 A.

      Delete
  4. Thank you for sharing. What a great project. I'm working on a similar project myself and this inspired me.

    ReplyDelete
    Replies
    1. Hi Davy. Glad you found it useful. Good luck with your project!

      Delete
  5. Hello, I am trying to do the same thing basicaly but I am got stuck badly at using the Google Calendar event for the automation.
    I would like to use the Calendar event just to trigger the watering, and then use a delay to turn off the pump, as I want to water only some small pots I don't need to run the pump more than 30 seconds.
    Could you share your automations.yaml?
    Thanks!

    ReplyDelete
    Replies
    1. Hi akmon, my automation that links the calendar and the switches is in the blog post above. However, it could easily be modified so that it only fires the switch when the calendar turns on, and then have another automation that turns the switch off after a delay. I can probably help with that if you're stuck.

      Delete
    2. Hi, yes I managed to just start an automation that would activate a pin for 30s when it read a calendar event.
      It took some time to debug it but finally it is working.

      Delete
  6. Insane attention to detail.
    I am planning a setup using a Sonoff 4ch Pro. but on it's own.
    The Google Calendar is a great idea, the power supply and converter are what I was thinking.
    Now I can proceed with a bit of confidence!
    Thanks

    ReplyDelete
    Replies
    1. Glad you found the post useful. I also considered using a Sonoff, 4ch Pro but from memory I couldn't find a 24vac suitable power supply that met the required voltage range for the Sonoff. Good luck with your project.

      Delete
  7. Great blog. I was planning to Post A Blog about my Sonoff 4cg Pro Tasmota version but you have covered it all here. I used a 24vdc Power Plug it controls the 4ch Pro and 24v for the solenoids.
    I am going to use the Google Calendar intergration plus am looking into Acu-Rite weather station data.
    Thanks for the great blog!

    ReplyDelete
    Replies
    1. There's always room for more blog posts! You should go ahead and write yours anyway. Good luck with the integrations.

      Delete
  8. This article inspired me to do something very simple that effectively produced two single channel "smart controllers". I needed two irrigation circuits, so I used two esp8266 based plug-in modules, loaded tasmota, and then plugged a wall wart style 24VAC transformer into each. That's it. I mounted a power strip inside my garage on the wall so there was no need for an enclosure.
    A/C -> esp8266 plug switch #1 -> 24v wall wart #1 -> valve #1
    A/C -> esp8266 plug switch #2 -> 24v wall wart #2 -> valve #2

    Total cost was low ($5 power strip, 2 x $6 esp8266 plug modules, 2 x $12 transformers, $10 of cable, $10 PVC conduit/parts to go through exterior wall). What took the most time was running the cable from the valves through the exterior garage wall. The hardware part of the project took ~3 hours.

    I can control it from Home Assistant and have a fail safe rules script in the devices so they won't run beyond a maximum number of minutes. Each can be operated manually at the plug when checking for leaks etc. It doesn't "look" anything like an irrigation controller, but it's worked flawlessly for several months. If a plug-in module or transformer fails, it only affects one valve and it's very easy to fix.

    ReplyDelete
    Replies
    1. Hi Zeric, that sounds like a clever solution. Glad it's working well.

      Delete
  9. Great Post! Thanks for sharing such beautiful information with us. Please keep sharing.

    Please visit reticulation supplies rockingham

    ReplyDelete
  10. Your attention to details in this post is top notch, has inspired me do a similar setup but using the esp32_relay_x8 board, I also have set it up to run parallel with my existing rain dail controller.

    Would it be possible to have the same setup as in this, but leave the solenoids connected to the rain dail and have the relay board trigger through the controller?

    ReplyDelete

Post a Comment

Popular posts from this blog

Controlling Samsung Air Conditioner from Home Assistant

PIR Sensor with Wemos D1 Mini and Tasmota