Lawn Sprinkler project

 Lawn Sprinkler Project

    This post describes a lawn sprinkler project I recently built here in The Villages.  For ease of reference, I am going to refer to this homebuilt controller as Sprinkler1.

    This is the first draft and may contain mistakes.  If you are a beginner, be careful about implementing this device.


Introduction

    Like many of you, I have relied on the builder-supplied commercially available sprinkle controller.  In my case, it is the Hunter Pro C Sprinkler Controller.  It works quite well  It includes a component called the Solar Sync. The Solar Sync Sensor is an evapotranspiration (ET) system that calculates plant-watering requirements and adjusts the sprinkling times set in the controller to match the environment.  It seems to work very well for me, but some neighbors have complained that it does not work well.  Some even stated that the landscaping people recommended that it be removed from their controller.

    One thing I don't like about the Hunter is having to go into the garage to change the settings, or even to see what the current settings are.  If it rains a good bit today, the controller might have tomorrow on the schedule, but I wouldn't want it to sprinkle, or remember if it is enabled.

   So my initial idea was to build a Wi-Fi controlled relay board with which I could "disconnect" the Hunter sprinkler controller remotely.  That way, I could set the controller to sprinkle more than I might really want, but have the ability to disable it from here in my study.  So I examined the installation and wiring of the controller and drew it on my whiteboard to study the project.  The photo below shows the whiteboard with the schematic of the controller wiring and the disconnector relay.


Whiteboard drawing


Hardware


    I built the simple disconnector board on a perf board and hooked it up.  It worked as expected.

 

The Disconnector board,
constructed on a perf board
  
The disconnector installed
in the garage cabinet


    We had recently added some plants to our landscaping which needed extra watering, so I was back to going to the Hunter controller to change the configuration if I wanted to irrigate just the landscaping.  So naturally, the next thought was to build a sprinkler controller which could be programmed, started, and stopped remotely. I had a Four channel relay board from Marlin P. Jones company and a spare ESP8266, so I started in earnest to build a new sprinkler.  Since the disconnector I just built had an unused set of inputs, I decided to connect the new controller, the Sprinkler1,  to the disconnector so I could switch between the original Hunter controller and my new controller.

   That was much easier than I thought it would be.  Starting below is a block diagram, followed by  some circuit information.


    

    Construction  pictures of the ESP8266 and its perf board: Yes, it is tie-wrapped to a stick.  Long story there....

   Construction is somewhat complicated by the requirement to have the ESP8266 "outside" the shielding effect of the metal box the sprinkler is built in.  The other components are inside the cabinet as seen in the next photo.





      This photo shows the disconnector board and the quad relay board tie-wrapped to a piece of cardboard.  This simple method allows the two boards to be stable in relation to each other and within the cabinet also. That way, no accidental shorting of components. 






     



Controller Software

    The ESP8266 is loaded with ESP Mega version mega-20180914.  The output devices are configured as :


    This provides the 5 outputs used to switch from Hunter Pro C to Sprinkler1 controller, and to control the four sprinkler zones.  You will want to go into the Hardware tab in ESP Easy and disable the I2C function.

    The mapping between Dx and GPIOx is as follows:

D1    GPIO5
D2   GPIO4
D6    GPIO12
D7   GPIO13
D5    GPIO14


   On the config tab, name the unit as sprinkler1.

   Next, in Rules Set 1, load this text:

On System#Boot do
   publish %sysname%/uptime,%uptime%
   timerSet,8,300           // set timer for 300 seconds
   publish sprinkler1/state,OFF
   gpio,5,0    // disconnector
   timerSet,7,10
endon

on Rules#Timer=8 do
   publish %sysname%/uptime,%uptime%
   timerSet,8,300           // set timer for 300 seconds
endon

On sprdiscon do
  publish %sysname%/state,event,sprdiscon
  publish sprinkler1/state,ON
  gpio,5,1    // disconnector
endon

On sprdiscoff do
  publish %sysname%/state,event,sprdiscoff
  publish sprinkler1/state,OFF
  gpio,5,0    // disconnector
endon

In Rules set 2:

On zone1on do
  gpio,12,0
  gpio,13,0
  gpio,14,0
  publish %sysname%/state,event,zone2off
  publish %sysname%/state,event,zone3off
  publish %sysname%/state,event,zone4off
  timerSet,1,2
endon

on Rules#Timer=1 do
  publish %sysname%/state,event,zone1on
  gpio,4,1
  timerSet,7,2000
endon


On zone1off do
  publish %sysname%/state,event,zone1off
  gpio,4,0
endon

On zone2on do
  gpio,4,0
  gpio,13,0
  gpio,14,0
  publish %sysname%/state,event,zone1off
  publish %sysname%/state,event,zone3off
  publish %sysname%/state,event,zone4off
  timerSet,2,2
endon

on Rules#Timer=2 do
  publish %sysname%/state,event,zone2on
  gpio,12,1
  timerSet,7,2000
endon

On zone2off do
  publish %sysname%/state,event,zone2off
  gpio,12,0
endon

On zone3on do
  gpio,4,0
  gpio,12,0
  gpio,14,0
  publish %sysname%/state,event,zone1off
  publish %sysname%/state,event,zone2off
  publish %sysname%/state,event,zone4off
  timerSet,3,2
endon

on Rules#Timer=3 do
  publish %sysname%/state,event,zone3on
  gpio,13,1
  timerSet,7,2000
endon

On zone3off do
  publish %sysname%/state,event,zone3off
  gpio,13,0
endon

On zone4on do
  gpio,4,0
  gpio,12,0
  gpio,13,0
  publish %sysname%/state,event,zone1off
  publish %sysname%/state,event,zone2off
  publish %sysname%/state,event,zone3off
  timerSet,4,2
endon

on Rules#Timer=4 do
  publish %sysname%/state,event,zone4on
  gpio,14,1
  timerSet,7,2000
endon

On zone4off do
  publish %sysname%/state,event,zone4off
  gpio,14,0
endon


on Rules#Timer=7 do
  publish %sysname%/state,event,zone1off
  publish %sysname%/state,event,zone2off
  publish %sysname%/state,event,zone3off
  publish %sysname%/state,event,zone4off
  gpio,4,0
  gpio,12,0
  gpio,13,0
  gpio,14,0
endon

    Don't forget to press "Submit" as you enter the two sets of rules.

     This set of rules provides for switching between zones with a short delay and also provides a watchdog timer to prevent a zone from being left on accidentally.  Anytime a zone is turned on, a 2000 second timer is started which, when it expires, will turn off all zones.

 

Automation Software

    This section describes how the new sprinkler is added into Home Assistant to give a "control panel" to allow you to monitor and control the new sprinkler controller.  Below are additions to the various Home Assistant files.  I use version 0.72 so if yours is different you may not see the same results.  Make sure you back up your HA server before starting on this!

Add to the end of configuration.yaml if not already present:

input_datetime: !include input_datetimes.yaml
input_boolean: !include input_booleans.yaml
input_number: !include input_numbers.yaml

New file input_datetimes.yaml:

start_time:
  name: start time
  has_date: false
  has_time: true
  initial: '04:30'


New file input_booleans:

cycle1_mon:
  name: Monday
  icon: mdi:calendar

cycle1_tue:
  name: Tuesday
  icon: mdi:calendar

cycle1_wed:
  name: Wednesday
  icon: mdi:calendar

cycle1_thu:
  name: Thursday
  icon: mdi:calendar

cycle1_fri:
  name: Friday
  icon: mdi:calendar

cycle1_sat:
  name: Saturday
  icon: mdi:calendar

cycle1_sun:
  name: Sunday
  icon: mdi:calendar


New file: input_numbers.yaml:

slider1:
  name: zone1
  initial: 4
  min: 1
  max: 60
  step: 1
slider2:
  name: zone2
  initial: 3
  min: 1
  max: 60
  step: 1
slider3:
  name: zone3
  initial: 2
  min: 1
  max: 60
  step: 1
slider4:
  name: zone4
  initial: 1
  min: 1
  max: 60
  step: 1

Add to sensors.yaml:

# used in sprinkler control
- platform: time_date
  display_options:
    - 'time'

Add to switches.yaml:
#*****************************************
- platform: mqtt
  name: Sprinkler disconnector
  state_topic: "sprinkler1/state"
  command_topic: "sprinkler1/cmd"
  qos: 0
  payload_on: "event,sprdiscon"
  payload_off: "event,sprdiscoff"
  optimistic: false
  retain: true

- platform: mqtt
  name: Hunter ProC
  state_topic: "sprinkler1/state"
  command_topic: "sprinkler1/cmd"
  qos: 0
  payload_on: "event,sprdiscoff"
  payload_off: "event,sprdiscon"
  optimistic: false
  retain: true

- platform: mqtt
  name: zone1
  state_topic: "sprinkler1/state"
  command_topic: "sprinkler1/cmd"
  qos: 0
  payload_on:  "event,zone1on"
  payload_off: "event,zone1off"
  optimistic: false
  retain: true

- platform: mqtt
  name: zone2
  state_topic: "sprinkler1/state"
  command_topic: "sprinkler1/cmd"
  qos: 0
  payload_on: "event,zone2on"
  payload_off: "event,zone2off"
  optimistic: false
  retain: true

- platform: mqtt
  name: zone3
  state_topic: "sprinkler1/state"
  command_topic: "sprinkler1/cmd"
  qos: 0
  payload_on: "event,zone3on"
  payload_off: "event,zone3off"
  optimistic: false
  retain: true

- platform: mqtt
  name: zone4
  state_topic: "sprinkler1/state"
  command_topic: "sprinkler1/cmd"
  qos: 0
  payload_on: "event,zone4on"
  payload_off: "event,zone4off"
  optimistic: false
  retain: true

- platform: mqtt
  name: manual cycle start
  state_topic: "sprinkler1/manual_start"
  command_topic: "sprinkler1/manual_start"
  qos: 0
  payload_on: "on"
  payload_off: "off"
  optimistic: true
  retain: true

- platform: mqtt
  name: auto cycle enable
  state_topic: "sprinkler1/cycle_enable"
  command_topic: "sprinkler1/cycle_enable"
  qos: 0
  payload_on: "on"
  payload_off: "off"
  optimistic: true
  retain: true


Add to automations.yaml:
#***************************************************
# sprinkler cycle
- id: cycle1
  alias: Sprinkler cycle
  trigger:
    platform: state
    entity_id: switch.manual_cycle_start
    to: 'on'
  action:
    - service: switch.turn_on
      entity_id: switch.zone1
    - delay:  "00:{{ states('input_number.slider1') | int }}:00"
    - service: switch.turn_off
      entity_id: switch.zone1

    - service: switch.turn_on
      entity_id: switch.zone2
    - delay:  "00:{{ states('input_number.slider2') | int }}:00"
    - service: switch.turn_off
      entity_id: switch.zone2

    - service: switch.turn_on
      entity_id: switch.zone3
    - delay:  "00:{{ states('input_number.slider3') | int }}:00"
    - service: switch.turn_off
      entity_id: switch.zone3

    - service: switch.turn_on
      entity_id: switch.zone4
    - delay:  "00:{{ states('input_number.slider4') | int }}:00"
    - service: switch.turn_off
      entity_id: switch.zone4

    - delay:  "00:00:02"
    - service: switch.turn_off
      entity_id: switch.manual_cycle_start

    - service: notify.pushbullet
      data:
        title: Sprinkler status
        message: "Sprinkler cycle has ended"

#**********************************************
- id: auto_cycle
  alias: auto cycle
  trigger:
    platform: template
    value_template: '{{ states.sensor.time.state == states.input_datetime.start_time.state[0:5] }}'
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: switch.auto_cycle_enable
        state: 'on'
      - condition: or
        conditions:
          - condition: and
            conditions:
              - condition: time
                weekday:
                   mon
              - condition: state
                entity_id: input_boolean.cycle1_mon
                state: 'on'
          - condition: and
            conditions:
              - condition: time
                weekday:
                  tue
              - condition: state
                entity_id: input_boolean.cycle1_tue
                state: 'on'
          - condition: and
            conditions:
              - condition: time
                weekday:
                  wed
              - condition: state
                entity_id: input_boolean.cycle1_wed
                state: 'on'
          - condition: and
            conditions:
              - condition: time
                weekday:
                  thu
              - condition: state
                entity_id: input_boolean.cycle1_thu
                state: 'on'
          - condition: and
            conditions:
              - condition: time
                weekday:
                  fri
              - condition: state
                entity_id: input_boolean.cycle1_fri
                state: 'on'
          - condition: and
            conditions:
              - condition: time
                weekday:
                  sat
              - condition: state
                entity_id: input_boolean.cycle1_sat
                state: 'on'
          - condition: and
            conditions:
              - condition: time
                weekday:
                  sun
              - condition: state
                entity_id: input_boolean.cycle1_sun
                state: 'on'
  action:
    - service: switch.turn_on
      entity_id: switch.manual_cycle_start
    - service: notify.pushbullet
      data:
        title: Sprinkler status
        message: "Sprinkler cycle has started"


    These rules use the Pushbullet notification to signal my cell phone when the cycles are started or ended. 


Control


If all goes well, you should have a control panel in Home Assistant that looks like this:




    In the first box, Sprinkler System control, I have a Sonoff switch to control my hardware.  This can be used to turn it off if there is a problem.  Since the default connection of the Disconnector relay is to the original controller, it will be enabled and the new controller disabled.

   The next two switches  Sprinkler disconnector and Hunter ProC allow you to select the active controller.

   The Sprinkler Manual Control  lets you turn on any zone manually.  You must remember to turn it off.

    The Start time box does this:
  1. manual cycle start - lets you run through all 4 zones sequentially.
  2. start time - the clock time that an automatic cycle will start at
  3. auto cycle enable - allows the controller to start a 4 zone sequence at the start time, for the days selected in Watering days. It does this by starting the manual cycle start.
    The Run times are slider controls that let you set the length of time each zone is run for, in either of the manual cycle or auto cycle.

    Watering days are those days that an auto cycle can be started on.

   If you use Hunter ProC button to select the original controller, you can test all of the functions of the Sprinkler1 controller without actually spraying any water.



Summary


    This was a quick and easy project for the hardware portion.  The software was somewhat more challenging but I think it works pretty well.

    In the future, I plan to add some functionality that will allow environmental conditions to  affect what Sprinkler1 does on any given day.

Gerald Swann
The Villages
October 2020

























Comments

Popular posts from this blog

UPS Project

Lighting Detection and Surge Mitigation