Sunday, November 10, 2019

Connected Irrigation Controller

Well, the cheap sprinkler controller that I got with my house breathed its final breath on Tuesday.  It wasn't going to do to live without one.  I've been adding all kinds of fun to the smart house, so now was the time for the sprinklers!

After keeping an eye out for available smart irrigation controllers for a few years and now feeling a rush to get the water scheduled again, I decided to go with a Sonoff 4ch Pro with ESP home installed.



Pros:
- Wifi connection to Home Assistant for automation
- Node Red automation through Home Assistant
- Home Assistant services allow one message to enable start and duration
- Web server page available outside of Home Assistant
- Physical button and indicating light at the controller to manually start and stop watering cycles
- Programmable maximum water cycle times
- Fits in the housing of the old sprinkler controller
- Uses the 120V to 24VAC transformer from the old sprinkler controller
- Hardware and software interlocks available so only one zone is active at a time
- Captive portal Hotspot created when programmed access point not available (new owners)

Cons:
- Need to fabricate mounting adapter plate (3D printer simplifies this)
- More programming needed for dynamically changing watering times based on weather/seasons
- No visible indicator of time remaining in current watering cycle

I thought it was worth it, so I went for it.  I used the following yaml for ESPHome:
esphome:
  name: irrigation
  platform: ESP8266
  board: esp01_1m
wifi:
  ssid: !secret mywifissid
  password: !secret mywifipw
  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Irrigation Fallback Hotspot"
    password: "S3crEt_P@$$w0rD"
captive_portal:
# Enable web server
web_server:
  port: 80
# Enable logging
logger:
# Enable Home Assistant API
api:
  services:
    - service: run_time_1
      variables:
        run_minutes: int
      then:
        - switch.turn_on: switch1
        - delay: !lambda 'return run_minutes*1000*60;'
        - switch.turn_off: switch1
    - service: run_time_2
      variables:
        run_minutes: int
      then:
        - switch.turn_on: switch2
        - delay: !lambda 'return run_minutes*1000*60;'
        - switch.turn_off: switch2
    - service: run_time_3
      variables:
        run_minutes: int
      then:
        - switch.turn_on: switch3
        - delay: !lambda 'return run_minutes*1000*60;'
        - switch.turn_off: switch3
    - service: run_time_4
      variables:
        run_minutes: int
      then:
        - switch.turn_on: switch4
        - delay: !lambda 'return run_minutes*1000*60;'
        - switch.turn_off: switch4
# Enable Over The Air updates
ota:
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sprinkler Button 1"
    internal: true
    on_release:
      then:
        - switch.toggle: switch1
  - platform: gpio
    pin:
      number: GPIO9
      mode: INPUT_PULLUP
      inverted: True
    name: "Sprinkler Button 2"
    internal: true
    on_release:
      then:
        - switch.toggle: switch2
  - platform: gpio
    pin:
      number: GPIO10
      mode: INPUT_PULLUP
      inverted: True
    name: "Sprinkler Button 3"
    internal: true
    on_release:
      then:
        - switch.toggle: switch3
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: True
    name: "Sprinkler Button 4"
    internal: true
    on_release:
      then:
        - switch.toggle: switch4
  - platform: status
    name: "Sprinkler Status"
switch:
  - platform: gpio
    name: "Sprinkler Relay 1"
    icon: "mdi:sprinkler"
    pin: GPIO12
    id: switch1
    interlock: &interlockgroup [switch1, switch2, switch3, switch4]
    on_turn_on:
      then:
        - delay: 4hours
        - switch.turn_off: switch1
  - platform: gpio
    name: "Sprinkler Relay 2"
    icon: "mdi:sprinkler"
    pin: GPIO5
    id: switch2
    interlock: *interlockgroup
    on_turn_on:
      then:
        - delay: 30minutes
        - switch.turn_off: switch2
  - platform: gpio
    name: "Sprinkler Relay 3"
    icon: "mdi:sprinkler"
    pin: GPIO4
    id: switch3
    interlock: *interlockgroup
    on_turn_on:
      then:
        - delay: 30minutes
        - switch.turn_off: switch3
  - platform: gpio
    name: "Sprinkler Relay 4"
    icon: "mdi:sprinkler"
    pin: GPIO15
    id: switch4
    interlock: *interlockgroup
    on_turn_on:
      then:
        - delay: 12hours
        - switch.turn_off: switch4
status_led:
  pin: GPIO13

No comments:

Post a Comment