Garden Irrigation

Hmmm. I thought it would be correct. Will check when I’m back home next week. Thank you.

Hi there,

There’s been either some breaking change or perhaps something is wrong with my initial code. After many months working perfectly I now have only 1 of 6 zones resetting to next run correctly.

I’ll look at the code, as soon as I’ve finished on my other projects… Perhaps a week or so.

Hello
I’m new to homeassistant, i have copied you code to my yaml files (on a fresh installation) and hass reports me this error :

RROR:homeassistant.util.yaml:mapping values are not allowed here

in “/home/homeassistant/.homeassistant/configuration.yaml”, line 70, column 12
Failed config
General Errors:
- Error loading /home/homeassistant/.homeassistant/configuration.yaml: mapping values are not allowed here
in “/home/homeassistant/.homeassistant/configuration.yaml”, line 70, column 12

Successful config (partial)

Could you help me please ?

Hi @accarien, without seeing your config - in the exact way it is in your configuration.yaml file - it’s going to be hard for anybody to help you.

Please paste the code for the element in/around line 70 and make sure you use the formatting option for ‘Preformatted text’.

Hi guys,

I’m building my greenhouse soon and starting on getting ideas for automating it. Did you see Irrigatia? I’m wondering if something exist where I could connect it to HA

Thanks

Hi all,
I’ve enjoyed reading and learning what others have done in the area of irrigation, so thought I should share my latest project which included both irrigation and controlling of a water feature pump. The project had three objectives:

  1. Water Feature pump control: Turn on in the morning and off at night. Turn off the water feature when no one is home (i.e. alarm is set).
  2. Automatically top up the Water Feature pond when the water level is low and the pump motor is no longer submerged (the water falls from the top bowl to the bottom reservoir pond, but on windy days so much water gets blown away that the reservoir water level drops quickly).
  3. Build garden and lawn irrigation system capable of being controlled from HA.
    WaterFeature

The first objective was easily managed with a Sonoff Basic Wifi switch which was purchased along with their IP66 waterproof case. I replaced the default Sonoff software with custom ESP8266 code to control and report the switch state via MQTT. The new code included a web server so that there is a simple web page to monitor and control the switch, plus it provides the Over The Air (OTA) software update functionality. A few simple HA automations now turn the water feature pump off whenever the Alarm is set and back on when someone returns home and disables the alarm. Another script switches the pump on at 7am each morning (if the alarm is not set, i.e. we are away for an extended period) and off an hour after sunset. Note that I wrote my own HA Alarm system for our home so integration with setting and clearing of the alarm is very easy.

Achieving the second objective took a bit longer! First the pond water level needed to be monitored and because a lot of water tends to get splashed around in the pond I didn’t think an ultrasonic sensor would be a good long-term solution. Nor any sort of float arrangement so I decided to 3D print a bracket that would hold a few copper probes and simply measure the conductivity between them.
PondLevelProbe
Next task was to control water flow for topping up the pond. Thanks to Petr Faitl of Tauranga, New Zealand, for the recommendation of Hunter PGV valves from Irrigation Express (we live in Lower Hutt, New Zealand). I ordered 4 of the valves so that I could add garden and lawn irrigation at the same time.


So now to put it all together and the requirements were shaping up as follows:
• Controller: I’d been experimenting with ESP8266 (in the Sonoff switches and NodeMCU guise) and had ordered some bare ESP-12 modules for just such a project so these seemed ideal.
• Software: While I could use the very good Tasmota code or ESPurna code, it’s so easy to write for the ESP8266 and there are plenty of examples of how to include MQTT, Web server, etc. so I decided to cut my own code, extending what I’d done for the Sonoff switch.
• Water Valve Control: 4 relays are required to switch 24VAC to the 4 water valves. Did briefly consider some form of solid state switching but settled on 5V relays (similar to what is used in Sonoff switches).
• Power Supply: A 24VAC supply is required to drive the valves so to avoid using another power supply it would be best to derive the 5V and 3.3V supplies from the 24VAC.
• Real world interface to water level probes, i.e. filtering and input protection.

Rather than patching this all together with bits of Veroboard and various shields I decided to layout a custom circuit board - especially as I’d come across EasyEDA (https://easyeda.com). If you have not used this site before I think it is very good! Circuit diagram and board layout all within your browser – no download of software onto your PC is required. The software works well and when the layout is complete you can click “get a quote”. Minimum order quantity is 5 boards and my double-sided boards with solder resist and component screen came in as US$2 each! US$10 for my circuit boards, made in a few days then couriered to NZ for a further SU$19 (yes courier costs were more than the board costs). And the boards are fantastic quality. Can highly recommend this service.

Anyway, back to the project. The final circuit includes a rectifier and switch mode regulator to generate the 5VDC and 3.3VDC supplies from the 24VAC, mounting of the ESP12 module, input filtering and protection for level probes, relays and drivers for valve control. And the obligatory programming push button that all ESP8266 boards require. Also threw in a 4 pin header to provide power and serial interface to the ESP8266 although after the initial boot all software updates are done via OTA.
IrrigationControllerBoard
As with all projects the mechanical aspects need a lot of attention. For this I found a waterproof case designed to hold a mains power distribution board and with enough space inside to take both my irrigation controller and the Sonoff Wifi switch. (Note that I deliberately choose not to integrate the function of the Sonoff mains switch into the irrigation controller so as to keep all 230V mains separated from the irrigation controller). A quickly designed and 3D printed bracket mounts the irrigation controller board in the case. Provision for cable clamps was included on this bracket but I never did get around to designing\printing the clamps.


And of course, digging up the lawn and running the water and electrical cables, etc. all take a lot of time. Not to mention flak from the wife for digging up the garden around the water feature. But then you can’t make a pond filler system without breaking a few hedge plants.

Putting it together: The irrigation controller is responsible for monitoring the water level and switching on the pond filler valve when the water level drops. The controller reports the water level and the state of the 4 relays into HA via MQTT. All relays can be controlled from HA or directly via a web page provided by the ESP8266 code. This web page includes the link for performing OTA software updates plus some monitoring\diagnosis. If the pond level falls to zero, then HA sends me a Slack notification that the pond is out of water - although that should be a thing of the past now that the pond is automatically replenished.
HAIrrigationTab


That just leaves me with Objective 3. There are three spare water valves available for garden\lawn irrigation but so far only one is hooked up to a sprinkler. I need to run the additional irrigation lines and then write the HA irrigation controls – which is what brought me to this post initially – looking to see what garden irrigation controls are available. During the summer in our city garden watering is limited by house numbering; even numbered houses can use irrigation on even days of the month, odd house numbers on odd days of the month. That is not seem to be a common rule in most irrigation controls and generally will require some custom coding. But its autumn now in NZ so irrigation is not so critical as it occurs naturally every few days. That gives me until next Spring to finish the irrigation part of the project. For now, I love looking at the water feature without the angst of seeing that it’s about to run out of water.
Regards
Garry

6 Likes

Hi Gary,

Nice write-up! I am currently trying to code my reticulation system into HA with the plan to use a NodeMCU (ESP8266 based) board to control the valves via relays. I wanted the interface to somewhat replicate the settings you get in most commercial retic controllers.

If it helps at all I have posted what I have coded so far, but I only started yesterday so the main smarts of it isnt there yet. At this stage I’m only coding for 2 stations but the way I am doing it allows for easy expansion as far as you need.

i have created it as a package:
reticulation.yaml

########################################
#
#   This is a full reticulation
#   control package using DarkSky
#   weather prediction to 
#   prevent watering if rain 
#   is expected, or occured recently
#   with local moisture sensor data
#   as well
#
########################################

#   Weather prediction setup
sensor:
  - platform: darksky
    api_key: !secret darksky_api_key
    name: Reticulation Weather
    forecast:
      - 1
    update_interval: '00:30:00'
    monitored_conditions:
      - precip_intensity
      - precip_probability
      - precip_intensity_max
#      - summary
#      - icon
#      - temperature
#      - apparent_temperature
#      - wind_speed
#      - wind_bearing
#      - cloud_cover
#      - humidity
#      - hourly_summary
#      - daily_summary
#      - temperature_max
#      - temperature_min
#      - apparent_temperature_max


#   Calculations for rain to stop reticulation








#   Reticulation control panel setup

input_select:
  retic_watering_days:
    name: Retic Watering Days
    options:
      - 'Daily'
      - 'Alternate'
      - '1 Wed / Sat'     # Western Australian allowed watering days based on last digit of house number
      - '2 Sun / Thurs'
      - '3 Mon / Fri'
      - '4 Tue / Sat'
      - '5 Sun / Wed'
      - '6 Mon / Thurs'
      - '7 Tue / Fri'
      - '8 Wed / Sat'
      - '9 Sun / Thurs'
      - '0 Mon / Fri'
    icon: mdi:calendar
    
input_datetime:
  retic_program1_start_time:
name: Program 1 Start Time
has_date: false
has_time: true
initial: '04:00'

  retic_program2_start_time:
name: Program 2 Start Time
has_date: false
has_time: true
initial: '18:00'


input_number:
  retic_program1_station1_run_time:
name: Station 1 Run Time
initial: 10
min: 0
max: 30
step: 1
icon: mdi:camera-timer

  retic_program1_station2_run_time:
name: Station 2 Run Time
initial: 10
min: 0
max: 30
step: 1
icon: mdi:camera-timer

  retic_program2_station1_run_time:
name: Station 1 Run Time
initial: 10
min: 0
max: 30
step: 1
icon: mdi:camera-timer

  retic_program2_station2_run_time:
name: Station 2 Run Time
initial: 10
min: 0
max: 30
step: 1
icon: mdi:camera-timer  

input_boolean:
  retic_watering_day:

  retic_station1_manual_run:
name: ON Manual
icon: mdi:arrow-right-drop-circle

  retic_station2_manual_run:
name: ON Manual
icon: mdi:arrow-right-drop-circle

  retic_station1_auto_run:

  retic_station2_auto_run:

  retic_program1_enable:
name: Enable

#  retic_program1_station1:
#    name: Station 1
#    icon: mdi:play-protected-content

#  retic_program1_station2:
#    name: Station 2
#    icon: mdi:play-protected-content

  retic_program2_enable:
name: Enable

#  retic_program2_station1:
#    name: Station 1
#    icon: mdi:play-protected-content

#  retic_program2_station2:
#    name: Station 2
#    icon: mdi:play-protected-content


group:                  # frontend interface setup
  retic_manual:
control: hidden
name: 'Manual Control'
entities:
  - input_boolean.retic_station1_manual_run
  - input_boolean.retic_station2_manual_run
  
  retic_program1:
    control: hidden
    name: 'Program 1'
    entities:
      - input_boolean.retic_program1_enable
      - input_select.retic_watering_days
      - input_datetime.retic_program1_start_time
      - input_number.retic_program1_station1_run_time
      - input_number.retic_program1_station2_run_time
    
  retic_program2:
    control: hidden
    name: 'Program 2'
    entities:
      - input_boolean.retic_program2_enable
      - input_select.retic_watering_days
      - input_datetime.retic_program2_start_time
      - input_number.retic_program2_station1_run_time
      - input_number.retic_program2_station2_run_time
  
switch:                      # Solenoid control (will be signals to NodeMCU)
  - platform: mqtt
name: "Retic Station 1 Valve"
state_topic: "retic/station1/state"
command_topic: "retic/station1/cmd"
payload_on: "1"
payload_off: "0"
optimistic: false
qos: 0
retain: true

  - platform: mqtt
name: "Retic Station 2 Valve"
state_topic: "retic/station2/state"
command_topic: "retic/station2/cmd"
payload_on: "1"
payload_off: "0"
optimistic: false
qos: 0
retain: true


#automation:
#  - alias: Check watering day
#    initial_state: 'on'
#    trigger:
#      - platform: time
#        at: '00:00:00'
#    condition:
#      condition: or
#      conditions:
#        - condition: state
#          entity_id: input_select.retic_watering_days
#          state: 'Daily'


#  - alias: Reticulation Run Program 1
#    initial_state: 'on'
#    trigger:
#      - platform: template
#        value_template: '{{ states.sensor.time.state == (states.input_datetime.retic_program1_start_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'
#    condition:
#      condition: and
#      conditions:
#        - condition: state
#          entity_id: input_boolean.retic_program1_enable
#          state: 'on'
#        - condition: state
#          entity_id: input_boolean.retic_watering_day
#          state: 'on'
#    action:

As you can see its not complete but it will give you the interface to see how it will come together. I will try to work on getting all the automation side of it coded over the next week.

Thanks Dave,
That’s a great start to irrigation controls! I’ve dropped your code into my dev system and it looks good. Exactly what I was looking for.

Let me know when you get it finished or further along the way.

Cheers
Garry

no problem, hopefully you got the latest version because I made a couple of edits and updated my post. I will certainly post the full version here once I finish it. At the end of the day, I wouldn’t have gotten to where I am with coding this stuff without this forum so it’s nice to give something back!

Not sure why but for some reason if I run a config check on the below code, it spits out the below error. It passes the config check if I # out the automation “Reticulation Run Program 1” but I can’t see how that relates to the error I’m getting… any ideas?
image

reticulation.yaml

########################################
#
#   This is a full reticulation
#   control package using DarkSky
#   weather prediction to 
#   prevent watering if rain 
#   is expected, or occured recently
#   with local moisture sensor data
#   as well
#
########################################

#   Weather prediction setup
sensor:
  - platform: darksky
    api_key: !secret darksky_api_key
    name: Reticulation Weather
    forecast:
      - 1
    update_interval: '00:30:00'
    monitored_conditions:
      - precip_intensity
      - precip_probability
      - precip_intensity_max
#      - summary
#      - icon
#      - temperature
#      - apparent_temperature
#      - wind_speed
#      - wind_bearing
#      - cloud_cover
#      - humidity
#      - hourly_summary
#      - daily_summary
#      - temperature_max
#      - temperature_min
#      - apparent_temperature_max


#   Calculations for rain to stop reticulation

















#   Reticulation control panel setup

input_select:
  retic_watering_days:
    name: Retic Watering Days
    options:
      - 'Daily'
      - 'Alternate'
      - '1 Wed / Sat'     # Western Australian allowed watering days based on last digit of house number
      - '2 Sun / Thurs'
      - '3 Mon / Fri'
      - '4 Tue / Sat'
      - '5 Sun / Wed'
      - '6 Mon / Thurs'
      - '7 Tue / Fri'
      - '8 Wed / Sat'
      - '9 Sun / Thurs'
      - '0 Mon / Fri'
    icon: mdi:calendar
    
input_datetime:
  retic_program1_start_time:
    name: Program 1 Start Time
    has_date: false
    has_time: true
    initial: '04:00'

  retic_program2_start_time:
    name: Program 2 Start Time
    has_date: false
    has_time: true
    initial: '18:00'


input_number:
  retic_program1_station1_run_time:
    name: Station 1 Run Time
    initial: 10
    min: 0
    max: 30
    step: 1
    icon: mdi:camera-timer

  retic_program1_station2_run_time:
    name: Station 2 Run Time
    initial: 10
    min: 0
    max: 30
    step: 1
    icon: mdi:camera-timer

  retic_program2_station1_run_time:
    name: Station 1 Run Time
    initial: 10
    min: 0
    max: 30
    step: 1
    icon: mdi:camera-timer

  retic_program2_station2_run_time:
    name: Station 2 Run Time
    initial: 10
    min: 0
    max: 30
    step: 1
    icon: mdi:camera-timer  

input_boolean:
  retic_watering_day:

  retic_station1_manual_run:
    name: Station 1 ON Manual
    icon: mdi:arrow-right-drop-circle

  retic_station2_manual_run:
    name: Station 2 ON Manual
    icon: mdi:arrow-right-drop-circle

  retic_station1_auto_run:

  retic_station2_auto_run:

  retic_program1_enable:
    name: Enable
    
#  retic_program1_station1:
#    name: Station 1
#    icon: mdi:play-protected-content

#  retic_program1_station2:
#    name: Station 2
#    icon: mdi:play-protected-content

  retic_program2_enable:
    name: Enable

#  retic_program2_station1:
#    name: Station 1
#    icon: mdi:play-protected-content

#  retic_program2_station2:
#    name: Station 2
#    icon: mdi:play-protected-content


group:                  # frontend interface setup
  retic_manual:
    control: hidden
    name: 'Manual Control'
    entities:
      - input_boolean.retic_station1_manual_run
      - input_boolean.retic_station2_manual_run
  
  retic_program1:
    control: hidden
    name: 'Program 1'
    entities:
      - input_boolean.retic_program1_enable
      - script.retic_program1_run
      - input_select.retic_watering_days
      - input_datetime.retic_program1_start_time
      - input_number.retic_program1_station1_run_time
      - input_number.retic_program1_station2_run_time
    
  retic_program2:
    control: hidden
    name: 'Program 2'
    entities:
      - input_boolean.retic_program2_enable
      - script.retic_program2_run
      - input_select.retic_watering_days
      - input_datetime.retic_program2_start_time
      - input_number.retic_program2_station1_run_time
      - input_number.retic_program2_station2_run_time
      
      
switch:                      # Solenoid control (will be signals to NodeMCU)
  - platform: mqtt
    name: "Retic Station 1 Valve"
    state_topic: "retic/station1/state"
    command_topic: "retic/station1/cmd"
    payload_on: "1"
    payload_off: "0"
    optimistic: false
    qos: 0
    retain: true
    
  - platform: mqtt
    name: "Retic Station 2 Valve"
    state_topic: "retic/station2/state"
    command_topic: "retic/station2/cmd"
    payload_on: "1"
    payload_off: "0"
    optimistic: false
    qos: 0
    retain: true


#automation:
#  - alias: Check watering day
#    initial_state: 'on'
#    trigger:
#      - platform: time
#        at: '00:00:00'
#    condition:
#      condition: or
#      conditions:
#        - condition: state
#          entity_id: input_select.retic_watering_days
#          state: 'Daily'


#  - alias: Reticulation Run Program 1
#    initial_state: 'on'
#    trigger:
#      - platform: template
#        value_template: '{{ states.sensor.time.state == (states.input_datetime.retic_program1_start_time.attributes.timestamp | int | timestamp_custom("%H:%M", False)) }}'
#    condition:
#      condition: and
#      conditions:
#        - condition: state
#          entity_id: input_boolean.retic_program1_enable
#          state: 'on'
#        - condition: state
#          entity_id: input_boolean.retic_watering_day
#          state: 'on'
#    action:
#      - service: script.turn_on
#        entity_id: script.retic_program1_run


script:             #run retic program 1 through each station for selected time
  retic_program1_run:
    alias: Program 1 Run
    sequence:
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_1_valve
      - delay: "00:{{ states('input_number.retic_program1_station1_run_time')|int }}:00"
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_1_valve
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_2_valve
      - delay: "00:{{ states('input_number.retic_program1_station2_run_time')|int }}:00"
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_1_valve
      
  retic_program2_run:
    alias: Program 2 Run
    sequence:
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_1_valve
      - delay: "00:{{ states('input_number.retic_program2_station1_run_time')|int }}:00"
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_1_valve
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_2_valve
      - delay: "00:{{ states('input_number.retic_program2_station2_run_time')|int }}:00"
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_1_valve

groups.yaml #for completeness I have included a segment of this file

retic:
  name: Retic
  view: yes
  icon: mdi:barley
  entities:
    - group.retic_program1
    - group.retic_program2
    - group.retic_manual

So the interface looks like this so far:

But if someone can help with the error I’m getting I’ll be very appreciative!

1 Like

Hi, these projects seem awesome for home automation!

Just chiming in here because I think a project of mine, esphomeyaml could, I hope, make setup easier. It’s basically software that creates custom firmwares for ESP8266/ESP32 boards from YAML configuration files as Home Assistant. :see_no_evil:

1 Like

I already had your thread about that bookmarked for when I put together the hardware side of my project!

1 Like

@sparkydave You don’t seem to have an action for the automation ‘Check watering day’.

Yeah, that part is incomplete hence its #'d out. It’s just the other automation that causes the error.
Edit:sorry, I forgot that both automations were #'d out! But it’s only the second one that causes trouble, the first is simply incomplete because it’s a work in progress

In that case my guess is it is something simple like spacing because it validates the config ok for me. I have changed a few things like some names but nothing really else that I think would make a difference (he says knowing that that means nothing when writing code!). I’m sorry that is probably not very helpful.

I am though very interested in this especially if anyone gets any algorithms designed that decide when to irrigate. I spent a long time working on an irrigation system when I first discovered HA a few weeks ago but it was using a Gardena Zone Distributor which has a slightly idiosyncratic way of working. The Chief Gardener here though changed her mind and now just wants separate zones so this looks like a great starting point for my system! :slight_smile:

EDIT: I just remembered I did swap in ALL my code for the switches (I’m using a sonoff 4 channel) so your error might be in that area?

Hi Otto,
I like your esphomeyaml project. Very impressive, well done.
I do wonder if there is a market for an ESP32 based I\O board interfacing via MQTT. I based my HA system around a couple of PiFace IO cards but they have their limitations, most notably not being suitable for real world applications - fine for school or lab workbench but not production environments.
What sort of hardware do most people run your software on?

Yeah, the error suggests switch, but the section of code that causes the issue doesn’t reference switch at all! I don’t understand

I’m planning on using Otto’s software on a couple of NodeMCU’s that I have (ESP8266 chip) to create the hardware side of my code above. The outputs are wired to a relay board to control the solenoids. That’s all there is to it other than a power supply

I have since updated the code to include separate watering day selectors for each program which gives a lot more control. I can post it tomorrow, it’s bed time here!

That’d be great, Thanks!
I’m hoping some of my original bits will be reusable and useful here, if they are I will post them too.

Goodnight.