Garden Irrigation

Sorry. My fault. The most obvious was not my first thought. :wink:

I guess I’m making progress, but i have no clue what value to enter here:
m_temp_celsius: 26 #fill from here https://www.holiday-weather.com/[your location]/averages/
m_temp_hours: 12 #fill from here https://www.holiday-weather.com/[your location]/averages/

If i enter VIENNA for example, it give 19C for July and -1C for January. Same goes for sunshing which is 2h in January and 9h on July. Should i sum up all monthes and divide by 12? Or take the hottest only? Or …

Did i mention that i totally LOVE that component and i really appreciate your work and your effort of posting it here!!

Btw: I’m also struggeling with the automation stuff. I saw you’re using appdaemon and apps. I don’t use appdaemon at all. So how can i still use the automation stuff - as far as i understand it that’s the BRAIN behind all of it?!

You should take the August average day temperatures (the hottest for Vienna and Israel) - in your case it is 26 and 11 hours of day light. It is used to calculate the maximum evaporation.
The total week time of irrigation (automation yaml) should match this period of time (August) - in my case for p2 it is 60 min in August.

If you already have a working AppDaemon, it shouldn’t be a problem to copy the automation code and YAML and make it work.

Let me know what does not work you

Since so many things have changed from my initial configuration post, from July 2017 Garden Irrigation I thought I’d post an update for those who want to configure their irrigation timers.

Significant changes affected:

  • Front end with the intruduction of Lovelace UI
  • New input_datetime component
  • WUnderground that I updated to DarkSky

Withput much further ado here is the final look of the timer component in the standard view

and in a config view, after clicking the Config Timer button.

clicking on Next Run opens up a modal view of the input_datetime component, such as this

For the UI, I’m using Lovelace yaml config.

configuration.yaml

lovelace:
  mode: yaml

ui-lovelace.yaml

title: Home
views:
  - type: vertical-stack
    cards:
    - type: entities
      title: Sprinklers Front Shrubs
      show_header_toggle: false
      entities:
        - sensor.last_run_front_shrubs
        - sensor.next_run_front_shrubs
        - sensor.duration_front_shrubs
        - sensor.repeat_front_shrubs
        - input_boolean.config_front_shrubs
        - automation.activate_front_shrubs_timer
  - type: conditional
    conditions:
      - entity: input_boolean.config_front_shrubs
        state: "on"
    card:
      type: entities
      title: Settings Front Shubs
      show_header_toggle: false
      entities:
        - input_datetime.next_run_front_shrubs
        - input_number.duration_front_shrubs
        - input_number.repeat_front_shrubs

There are a few sensor components that are not strictly needed. But I prefer to have a non-editable sensors on the day-to-day view screens, showing the next run and last run, rather than exposing their input_datetime and input_number components. These sensors purely mirror their editable counterparts.

and this is the config for these sensors (please note they need to be indented under a sensor component)

configuration.yaml

- platform: template
    sensors:
## Front Shrubs
      next_run_front_shrubs_time:
        value_template: '{{as_timestamp(states.input_datetime.next_run_front_shrubs.state) | timestamp_custom("%H:%M")}}'
        friendly_name: "Time"
      next_run_front_shrubs:
        friendly_name: "Next Run"
        value_template: '{{as_timestamp(states.input_datetime.next_run_front_shrubs.state) | timestamp_custom("%A, %d %h %H:%M")}}'
      last_run_front_shrubs:
        friendly_name: "Next Run"
        value_template: '{{as_timestamp(states.input_datetime.last_run_front_shrubs.state) | timestamp_custom("%A, %d %h %H:%M")}}'
      time_delta_front_shrubs:
        friendly_name: "Front Shrubs Timedelta"
        value_template: '{{states.input_number.repeat_front_shrubs.state|int * 3600}}'
      duration_front_shrubs:
        value_template: '{{states.input_number.duration_front_shrubs.state | int}}mins'
        friendly_name: "Duration"
      repeat_front_shrubs:
        value_template: '{{ "{:02d}".format(states.input_number.repeat_front_shrubs.state|int)}}hrs'
        friendly_name: "Repeat in"

For completeness here are input_number components that I keep in

input_numbers/front_shrubs.yaml

duration_front_shrubs:
  name: "Set Duration"
  initial: 3
  min: 0
  max: 15
  step: 1
  icon: mdi:camera-timer
repeat_front_shrubs:
  name: "Set Repeat"
  initial: 48
  min: 0
  max: 48
  icon: mdi:repeat

And the new input_datetime components.

input_datetime/front_shrubs.yaml

next_run_front_shrubs:
  name: Next Run
  has_date: true
  has_time: true
last_run_front_shrubs:
  name: Last Run
  has_date: true
  has_time: true

There’s one more sensor that I use to modify wet or dry condition that will show later in automation. It takes rain probability and rain intensity from DarkSky and allows me to override it. Setting hard values has not worked for me, as sun intensity after a brief shower dried up the ground quickly, yet my sensor was still in “too wet” condition. So I can manually tweak it, so on the next scheduled irrigation, that can be on the same day the irrigation does kick in.

The view is:

UI code in ui-lovelace.yaml

- type: entities
  title: Rainfall Sensitivity
  show_header_toggle: false
  entities:
    - sensor.rain_sensor
    - input_number.dark_sky_precip_probability_sensitivity
    - input_number.dark_sky_precip_intensity_sensitivity

The code for the logic (I’m not showing the darksky component)

input_number:    
  dark_sky_precip_intensity_sensitivity:
    name: "Rainfall mm Sensitivity"
    initial: 0.1
    min: 0
    max: 5
    step: 0.1
    icon: mdi:contrast
  dark_sky_precip_probability_sensitivity:
    name: "Rainfall Probability Sensitivity"
    initial: 40
    min: 0
    max: 100
    step: 10
    icon: mdi:contrast

sensor:
  - platform: template
      sensors:
        rain_sensor:
          friendly_name: "Rainfall Threshold Sensitivity"
          value_template: >-
            {% if (states.sensor.dark_sky_precip_probability.state | float) <= (states.input_number.dark_sky_precip_probability_sensitivity.state | float) and (states.sensor.dark_sky_precip_intensity_0.state | float) <= (states.input_number.dark_sky_precip_intensity_sensitivity.state | float) %}
              dry
            {% else %}
              too wet
            {% endif %}

Automations and scripts.
In automation we are converting all values to timestamps, so we can calculate future, past or equality conditions. This part is quite tricky, as there’s very strict requirement for the values to be in a particular format. Please see https://www.home-assistant.io/components/input_datetime/ for details. Also very good article that covers datetime calculations is at The EPIC Time Conversion and Manipulation Thread!

automation:
  - alias: "Activate Front Shrubs Timer"
    trigger:
      - platform: time_pattern
        minutes: '/1'
    condition:
      condition: and
      conditions:
      - condition: template
        value_template: '{{as_timestamp(now().strftime("%Y-%m-%d %H:%M")) == as_timestamp(states.input_datetime.next_run_front_shrubs.state)}}'
      - condition: state
        entity_id: sensor.rain_sensor
        state: 'dry'
    action:
      - service: script.turn_on
        entity_id: script.activate_irrigation_front_shrubs


  - alias: "Extend Front Shrubs Timer When Wet"
    trigger:
      - platform: time_pattern
        minutes: '/1'
    condition:
      condition: or
      conditions:
        - condition: template
          value_template: '{{as_timestamp(now().strftime("%Y-%m-%d %H:%M")) > as_timestamp(states.input_datetime.next_run_front_shrubs.state)}}'
        - condition: and
          conditions:
            - condition: template
              value_template: '{{as_timestamp(now().strftime("%Y-%m-%d %H:%M")) == as_timestamp(states.input_datetime.next_run_front_shrubs.state)}}'
            - condition: state
              entity_id: sensor.rain_sensor
              state: 'too wet'
    action:
      - service: script.turn_on
        entity_id: script.update_front_shrubs_next_run_timer

And lastly my script part.

script:
  activate_irrigation_front_shrubs:
    alias: "Activate Irrigation Front Shrubs"
    sequence:
      - service: script.turn_on
        entity_id: script.update_front_shrubs_next_run_timer
      - service: script.turn_on
        entity_id: script.update_front_shrubs_last_run_timer
      - service: switch.turn_on
        entity_id: switch.front_shrubs_switch
      - delay: 
          minutes: "{{ (states.input_number.duration_front_shrubs.state | int) }}"
      - service: switch.turn_off
        entity_id: switch.front_shrubs_switch

  update_front_shrubs_next_run_timer:
    alias: "Update Front Shrubs Next Run Timer"
    sequence:
    - service: input_datetime.set_datetime
      entity_id: input_datetime.next_run_front_shrubs
      data_template:
        date: >
          {{(as_timestamp(now())+(states.sensor.time_delta_front_shrubs.state)|int) | timestamp_custom("%Y-%m-%d", true)}}
        time: >
          {{(as_timestamp(now())+(states.sensor.time_delta_front_shrubs.state)|int) | timestamp_custom("%H:%M:%S", true)}}

  update_front_shrubs_last_run_timer:
    alias: "Update Front Shrubs Last Run Timer"
    sequence:
    - service: input_datetime.set_datetime
      entity_id: input_datetime.last_run_front_shrubs
      data_template:
        date: >
          {{(as_timestamp(now())) | timestamp_custom("%Y-%m-%d", true)}}
        time: >
          {{(as_timestamp(now())) | timestamp_custom("%H:%M:%S", true)}}

That should be about all that’s to it. As it stands it should work for you.
I’m still hoping to work on the scripts to pass variables programatically, as I have about eight irrigation timers and don’t wish to have eight copies of near duplicate code.

If you copy and paste, please make sure you have your indentations right depending how you keep your components separated or not. Indentations tend to be the most common problem when the logs are full of errors.

Any questions, please ask.

8 Likes

Am just in the process of redoing my garden and patios, and am planning on adding some raised beds for herbs/vegetables. I have read this thread with interest, as I would like to create a smart irrigation system for the beds.

Current thoughts based on reading:

An ezyvalve 4 valve box: https://www.easygardenirrigation.co.uk/products/ezyvalve-4-solenoid-valve-box-24v - with 24v AC power supply.
Sonoff 4Ch Pro to control the solenoids.
A drip irrigation system (I have some old hozelok kit that I can add to).
Miflora moisture sensors to prevent irrigation when the soil is wet.

One thing that I am stuck with, is that I would like to be able to switch between different water sources. I have a number of large water butts that I would like to use out of preference, only switching to tap water when they are empty. Sensing empty/full can be achieved with a simple water or moisture sensor. In terms of controlling inflow, I am guessing that it is not possible to reverse one of the Ezyvalve 4s to control 4 inputs to one output? Otherwise I would need a valve for each water source?

Thanks for sharing!

Is this last post complete, or is a modification of another post?

I tried to find another post from you in this thread, but I haven’t found.

This is exactly what I have done, see here - My Garden Irrigation. I even got mine from that exact supplier and I found them very helpful.

As for using an Ezyvalve box in reverse, I can’t see why you couldn’t do that, unless of course the internals won’t like the water flowing through it in reverse???

Looks great! As per the other thread, using a 4Ch pro means I will only need a single 24v AC transformer as the relays are isolated from the mains side.

I think reversing depends on the valve type. The rainbird ones that I have seen would definitely not work in reverse - see https://www.youtube.com/watch?v=5rokXHhxRSw

Would be good if anyone has any experience?

It is a complete setup for times, as mentioned in my intro. My original post is from July 2017. Over here I describe the timers first Garden Irrigation

For clarity I use irrigation boards based on the Wemos D1 mini, as per my post from Jul’17 Garden Irrigation . Messaging with the board is via MQTT. But that is immaterial to the timer setup, as you simply call switch.turn_on and switch.turn_off on the entity_id of your device. So, the timer is universally applicable.

If you see my initial post I was using a lot of input_number sliders for hour and minute settings. The input_datetime component makes this heck easier. Hope it helps.

Ok, thanks, this is for one sprinkler, then I have to duplicate it since I have four sprinkler, right?

I will try to use it and move the automation/script in NodeRed.

I hope to have some spare time to do it…

Thanks!

Yep. That’s why I mention generalising some scripts and passing variables to them in future versions.

So I recently bought my first house, and of course slowly making it a smart home. Anyway the house was built in 2003, and came with a Hunter Pro-C sprinkler system, and after talking to the orginal owner it was only used for one year then they never used it again that was 7/8 years ago - mainly because of the water rates in my town… (I’m single and live by myself, take showers do landry/dishes and my bill is around $60 USD a month.)

Anyway i after looking at this thread, i got the idea to modify the existing system so that it can work with Home Assistant. Anyone have any suggestions on how I might do this?

thanks.

hi
can you share /config/configuration.yaml ?
I have error when check config

    Invalid config for [automation]: required key not provided @ data['action']. Got None
    required key not provided @ data['trigger']. Got None. (See ?, line ?). Please check the docs at https://home-assistant.io/components/automation/

Hey Mate, do you use this with lovelace? and do you somehow call the entire retic.yaml file or do you split it out into different yaml files (ie. switch, automation etc.)

Still a bit of a newb at this :slight_smile:

Cheers,
Cam

I do use Lovelace. The retic.yaml is a package, saved under config/packages which gets called in the config.yaml as packages: or something similar. I’m away at the moment so can’t post the code but will update with a new reply in a few days for you. The retic.yaml has all components within it, such as sensor: switch: automation: etc. Look up packages in the HA docs, they are definitely the best way to keep all of your code nicely organised

Ahhh, I see yeah that makes more sense, I am still getting weird errors though:
in “/config/packages/reticulation.yaml”, line 14, column 1 expected <block end>, but found ‘<block mapping start>’

might wait until you get back :slight_smile:

Cam

Not sure exactly what you’re trying to accomplish, but I have a similar controller and wanted to implement a way to shut off watering in the case of rain (or forecast rain). There are certainly new controllers (e.g. Rachio) available that can implement this, so one option is just replace the controller. If I were starting this project today, this is probably what I would do. This would also give me the option to change the watering schedule automatically as well.

However, I implemented this solution four or five years ago, when internet-connected irrigation controllers were still hugely expensive (because they were used in commercial settings). So, here’s what I did.

Most sprinkler controllers (including the Hunter Pro-C) have a connection for a rain sensor. These sensors are really simple devices. They have various different methods of operation, but in the end all they are is a switch. The switch opens or closes based on whether they have been rained on recently.

All I wanted to be able to do is prevent watering when rain had happened recently or was forecast, so I purchased z-wave dry contact relay (today you could use a sonoff, I guess) and wired it up to the rain sensor contacts in my controller. With everything wired up, I can now control whether the scheduled watering program in the controller actually executes.

I wrote a simple automation in HA to detect whether rain is forecast or occurring and use this to drive the switch. Formerly I had a really cool automation using the accumulated rain totals that we provided by WUnderground, but this service is now a paid one, so I’m just using the probability or rain. I’m looking for more elegant solutions (evapotranspiration?), but the solution I have seems to work OK for now. I also have a manual override function (input boolean) that allows me to manually interrupt all watering regardless of the weather forecast.

Not sure if any of this is helpful, but maybe it gives you an idea how to integrate an old irrigation controller with some kind of modern technology.

Hi Cam,

Looking at line 14 I think the issue is that you don’t have the same entities as me. That section of my file is about customising some entities that are created using ESPhome and brought into HA via the ESPhome integration. Your system will no doubt be different in this respect. What you will need to do is create the switch entities for your solenoids. You can do this within the reticulation.yaml file if to keep things neat. Just create a component heading switch: and list your solenoid switch entities.

Here is my latest version which now includes two starts times per Program so that I can have more flexibility with the timing and it’s more like a commercial system.

I do plan to make another change to it this week to convert the use of delays to timers so that I can display time remaining in the GUI.

reticulation.yaml

########################################
#
#   This is a full reticulation
#   control package using ESPHOMEYAML
#   as the soleniod control via a NodeMCU
#
########################################

homeassistant:
  customize:
    switch.retic_station_1_valve:
      icon: mdi:water-pump
    switch.retic_station_2_valve:
      icon: mdi:water-pump
    input_boolean.retic_program1_enable:
      icon: mdi:traffic-light
    input_boolean.retic_program2_enable:
      icon: mdi:traffic-light



      
sensor:
  - platform: template    # determine if today is selected as a watering day for program 1
    sensors:
      retic_program1_watering_day:
        entity_id: input_boolean.retic_program1_monday, input_boolean.retic_program1_tuesday, input_boolean.retic_program1_wednesday, input_boolean.retic_program1_thursday, input_boolean.retic_program1_friday, input_boolean.retic_program1_saturday, input_boolean.retic_program1_sunday, sensor.time
        value_template:  >
          {% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
          {% set today_name = sensor_names[now().weekday()] %}
          {% set entity_id = 'input_boolean.retic_program1_'+today_name %}
          {{ is_state(entity_id, 'on') }}

      retic_program2_watering_day:
        entity_id: input_boolean.retic_program2_monday, input_boolean.retic_program2_tuesday, input_boolean.retic_program2_wednesday, input_boolean.retic_program2_thursday, input_boolean.retic_program2_friday, input_boolean.retic_program2_saturday, input_boolean.retic_program2_sunday, sensor.time
        value_template:  >
          {% set sensor_names = [ 'monday', 'tuesday', 'wednesday','thursday','friday','saturday','sunday'] %}
          {% set today_name = sensor_names[now().weekday()] %}
          {% set entity_id = 'input_boolean.retic_program2_'+today_name %}
          {{ is_state(entity_id, 'on') }}

    
input_datetime:
  retic_program1_start_time_1:    # program start time control
    name: Program 1 Start Time 1
    has_date: false
    has_time: true

  retic_program1_start_time_2:
    name: Program 1 Start Time 2
    has_date: false
    has_time: true

  retic_program2_start_time_1:
    name: Program 2 Start Time 1
    has_date: false
    has_time: true

  retic_program2_start_time_2:
    name: Program 2 Start Time 2
    has_date: false
    has_time: true


input_number:
  retic_program1_station1_run_time:   # station run time control
    name: Station 1 Run Time
    min: 0
    max: 30
    step: 1
    icon: mdi:camera-timer

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

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

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

  allowable_rain_quantity:
    name: 'Allowable Rain (mm)'
    min: 0
    max: 5
    step: 0.1
    icon: mdi:cup-water

  allowable_rain_percentage:
    name: 'Allowable Rain (%)'
    min: 0
    max: 100
    step: 1
    icon: mdi:water-percent

input_boolean:
  retic_program1_monday:   # watering day selections for program 1
    name: Monday

  retic_program1_tuesday:
    name: Tuesday

  retic_program1_wednesday:
    name: Wednesday

  retic_program1_thursday:
    name: Thursday
    
  retic_program1_friday:
    name: Friday

  retic_program1_saturday:
    name: Saturday
    
  retic_program1_sunday:
    name: Sunday

  retic_program2_monday:   # watering day selections for program 2
    name: Monday

  retic_program2_tuesday:
    name: Tuesday

  retic_program2_wednesday:
    name: Wednesday

  retic_program2_thursday:
    name: Thursday
    
  retic_program2_friday:
    name: Friday

  retic_program2_saturday:
    name: Saturday
    
  retic_program2_sunday:
    name: Sunday


  retic_program1_enable:   # enable program to run
    name: Enable
    
  retic_program2_enable:
    name: Enable


  retic_station_1_run:
    name: Station 1 Run
  
  retic_station_2_run:
    name: Station 2 Run


  retic_rain_parameters_met:   # set to ON if rain today values are below levels set in input_numbers
    name: Rain Parameters Met
    icon: mdi:water
  retic_rain_override:         # set to ON to run retic even if rain parameters are not met
    name: Rain Override
    icon: mdi:water

group:                  # frontend interface setup
  retic_manual:
    control: hidden
    name: 'Manual Control'
    entities:
      - switch.retic_station_1_valve
      - switch.retic_station_2_valve
  
  retic_program1:
    control: hidden
    name: 'Program 1'
    entities:
      - input_boolean.retic_program1_enable
      - script.retic_program1_run
      - input_datetime.retic_program1_start_time_1
      - group.retic_program1_watering_days
      - group.retic_program1_run_times
    
  retic_program2:
    control: hidden
    name: 'Program 2'
    entities:
      - input_boolean.retic_program2_enable
      - script.retic_program2_run
      - input_datetime.retic_program2_start_time_1
      - group.retic_program2_watering_days
      - group.retic_program2_run_times

  retic_program1_watering_days:
    control: hidden
    name: 'Watering days'
    icon: mdi:calendar-multiple-check
    entities:
      - input_boolean.retic_program1_monday
      - input_boolean.retic_program1_tuesday
      - input_boolean.retic_program1_wednesday
      - input_boolean.retic_program1_thursday
      - input_boolean.retic_program1_friday
      - input_boolean.retic_program1_saturday
      - input_boolean.retic_program1_sunday

  retic_program2_watering_days:
    control: hidden
    name: 'Watering days'
    icon: mdi:calendar-multiple-check
    entities:
      - input_boolean.retic_program2_monday
      - input_boolean.retic_program2_tuesday
      - input_boolean.retic_program2_wednesday
      - input_boolean.retic_program2_thursday
      - input_boolean.retic_program2_friday
      - input_boolean.retic_program2_saturday
      - input_boolean.retic_program2_sunday

  retic_program1_run_times:
    control: hidden
    name: 'Run times'
    icon: mdi:camera-timer
    entities:
      - input_number.retic_program1_station1_run_time
      - input_number.retic_program1_station2_run_time

  retic_program2_run_times:
    control: hidden
    name: 'Run times'
    icon: mdi:camera-timer
    entities:
      - input_number.retic_program2_station1_run_time
      - input_number.retic_program2_station2_run_time


automation:
  - alias: Check rain parameters     # check that todays rain doesnt need to disable the retic from running
    initial_state: 'on'
    trigger:
      - platform: template
        value_template: "{{ states('sensor.time') == ((states.input_datetime.retic_program1_start_time_1.attributes.timestamp - 600) | int | timestamp_custom('%H:%M', False)) }}"
      - platform: template
        value_template: "{{ states('sensor.time') == ((states.input_datetime.retic_program1_start_time_2.attributes.timestamp - 600) | int | timestamp_custom('%H:%M', False)) }}"
      - platform: template
        value_template: "{{ states('sensor.time') == ((states.input_datetime.retic_program2_start_time_1.attributes.timestamp - 600) | int | timestamp_custom('%H:%M', False)) }}"
      - platform: template
        value_template: "{{ states('sensor.time') == ((states.input_datetime.retic_program2_start_time_2.attributes.timestamp - 600) | int | timestamp_custom('%H:%M', False)) }}"
      - platform: state
        entity_id: input_number.allowable_rain_quantity
      - platform: state
        entity_id: input_number.allowable_rain_percentage

    action:
      - service_template: >
          input_boolean.turn_{{'on' if states('sensor.bom_perth_rain_today') <= states('input_number.allowable_rain_quantity') and 
                                       states('sensor.bom_perth_forecast_chance_of_rain_0') <= states('input_number.allowable_rain_percentage')  else 'off'}}
        entity_id: input_boolean.retic_rain_parameters_met



  - alias: Reticulation Run Program 1     # start program 1 at designated time if it is enabled and today is selected as a watering day
    initial_state: 'on'
    trigger:
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program1_start_time_1.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program1_start_time_2.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: sensor.retic_program1_watering_day
          state: 'True'
        - condition: or
          conditions:
            - condition: state
              entity_id: input_boolean.retic_rain_parameters_met
              state: 'on'
            - condition: state
              entity_id: input_boolean.retic_rain_override
              state: 'on'
    action:
      - service: script.turn_on
        entity_id: script.retic_program1_run

  - alias: Reticulation Run Program 2     # start program 2 at designated time if it is enabled and today is selected as a watering day
    initial_state: 'on'
    trigger:
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program2_start_time_1.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.retic_program2_start_time_2.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
    condition:
      condition: and
      conditions:
        - condition: state
          entity_id: input_boolean.retic_program2_enable
          state: 'on'
        - condition: state
          entity_id: sensor.retic_program2_watering_day
          state: 'True'
        - condition: or
          conditions:
            - condition: state
              entity_id: input_boolean.retic_rain_parameters_met
              state: 'on'
            - condition: state
              entity_id: input_boolean.retic_rain_override
              state: 'on'
    action:
      - service: script.turn_on
        entity_id: script.retic_program2_run

  - alias: Reticulation Station 1 Run
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: input_boolean.retic_station_1_run
    action:
      - service_template: >
          {% if is_state('input_boolean.retic_station_1_run', 'on') %}
            script.retic_station_1_run
          {% else %}
            script.retic_station_1_stop
          {% endif %}
      
  - alias: Reticulation Station 2 Run
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: input_boolean.retic_station_2_run
    action:
      - service_template: >
          {% if is_state('input_boolean.retic_station_2_run', 'on') %}
            script.retic_station_2_run
          {% else %}
            script.retic_station_2_stop
          {% endif %}

  - alias: Reticulation Controller Offline Alert
    initial_state: 'on'
    trigger:
      platform: state
      entity_id: binary_sensor.retic_controller_status
      to: 'off'
      for:
        minutes: 5
    action:
      - service: notify.pushbullet
        data:
          message: 'Retic Controller Offline!'


script:
  retic_program1_run:             #run retic program 1 through each station for selected time
    alias: Program 1 Run
    sequence:
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_1_valve
      - delay: "00:00:01"
      - service: switch.turn_on
        data:
          entity_id: switch.retic_bore_control
      - 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_bore_control
      - delay: "00:00:01"
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_2_valve
      
  retic_program2_run:             #run retic program 2 through each station for selected time
    alias: Program 2 Run
    sequence:
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_1_valve
      - delay: "00:00:01"
      - service: switch.turn_on
        data:
          entity_id: switch.retic_bore_control
      - 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_bore_control
      - delay: "00:00:01"
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_2_valve

  retic_station_1_run:
    alias: Station 1 Run
    sequence:
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_1_valve
      - delay: "00:00:01"
      - condition: state
        entity_id: switch.retic_station_1_valve
        state: 'on'
      - service: switch.turn_on
        data:
          entity_id: switch.retic_bore_control
  
  retic_station_1_stop:
    alias: Station 1 Stop
    sequence:
      - service: switch.turn_off
        data:
          entity_id: switch.retic_bore_control
      - delay: "00:00:01"
      - condition: state
        entity_id: switch.retic_bore_control
        state: 'off'
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_1_valve

  retic_station_2_run:
    alias: Station 2 Run
    sequence:
      - service: switch.turn_on
        data:
          entity_id: switch.retic_station_2_valve
      - delay: "00:00:01"
      - condition: state
        entity_id: switch.retic_station_2_valve
        state: 'on'
      - service: switch.turn_on
        data:
          entity_id: switch.retic_bore_control
  
  retic_station_2_stop:
    alias: Station 2 Stop
    sequence:
      - service: switch.turn_off
        data:
          entity_id: switch.retic_bore_control
      - delay: "00:00:01"
      - condition: state
        entity_id: switch.retic_bore_control
        state: 'off'
      - service: switch.turn_off
        data:
          entity_id: switch.retic_station_2_valve

lovelace

  - title: Retic
    icon: 'mdi:water-pump'
    background: center / cover no-repeat url("/local/images/back_garden_1.jpg") fixed
    cards:
      - type: entities
        show_header_toggle: false
        title: Program 1
        entities:
          - input_boolean.retic_program1_enable
          - script.retic_program1_run
          - input_datetime.retic_program1_start_time_1
          - input_datetime.retic_program1_start_time_2
          - group.retic_program1_watering_days
          - group.retic_program1_run_times
      - type: entities
        show_header_toggle: false
        title: Program 2
        entities:
          - input_boolean.retic_program2_enable
          - script.retic_program2_run
          - input_datetime.retic_program2_start_time_1
          - input_datetime.retic_program2_start_time_2
          - group.retic_program2_watering_days
          - group.retic_program2_run_times
      - type: entities
        show_header_toggle: false
        title: Manual Control
        entities:
          - input_boolean.retic_station_1_run
          - input_boolean.retic_station_2_run
      - type: entities
        title: Rain Settings
        entities:
          - input_number.allowable_rain_percentage
          - input_number.allowable_rain_quantity
          - input_boolean.retic_rain_parameters_met
          - input_boolean.retic_rain_override
        show_header_toggle: false
      - type: entities
        show_header_toggle: false
        title: Status
        entities:
          - entity: binary_sensor.retic_controller_status
            secondary_info: last-changed
          - entity: switch.retic_station_1_valve
            secondary_info: last-changed
          - entity: switch.retic_station_2_valve
            secondary_info: last-changed
          - entity: switch.retic_bore_control
            secondary_info: last-changed
          - binary_sensor.retic_bore_running

3 Likes

Can you help explaining how you are wiring your Sonoff 4ch?

Are you powering your sonoff with the same 24v converter as used to supply the valves?

That helps SO much, I have most of it working, how have you got esp home setup?

I am using a sonoff 4ch with esp home :slight_smile:

I am planning on running the solenoids with a 24vac transformer (i dunno if i will have to mod the relays… i dont think so as they all have com-no-nc connections, and then a little ac-dc converter that ill hopefully be able to fit inside the 4ch to run the logic stuff :slight_smile: