Garden Irrigation

maybe we should refrain from using online weather data, and use REAL data from outside?
something like this may work?

image

rain gauge on aliexpress

@iz3man That looks interesting. I can’t look now but does it ‘talk’ to HA?

it’s 433Mhz. so there may be some more tinkering involved. unfortunately it doesn’t look very well thought out - to me.

looks like it’s counting drops (or a multitude of those) by a swivel mechanism and a hall sensor. and it looks like there’s a wire attached to it - no idea where this goes to.

who’s like to be the guinea pig and order one? :slight_smile:

image

@klogg: did a lot of thinking over the last days. at the moment i’m irrigating every day. which is suboptimal.
regarding professional lawn shops it’s best to water ONCE A WEEK, in hot summer season TWICE a week.
in our region (center of europe) an estimate of 20-25 l/m2 per week is the optimal amount of water.
maybe we should rethink the algorithm in a way like: “set desired amount of water per area” and then water twice a week until you reach that amount.
so maybe water 10l on monday, then add the rain fall on mon, tue, wed, thu, and the expected rain for fri-son, and then water the difference left to 25l on friday. that way you could be quite sure to not overwater the lawn.
what do you think?

edit: it would also be cool to add something like: water used / today / this week etc …
i guess every household worldwide has a water meter where the water pipe enters the house. your irrigation setup won’t change a lot over time, so once setup it’s quite stable. so i took a stop watch, and counted liters/min for every zone activated. if i could enter this number in the package’s setup it could calculate liters used.

maybe openweathermap could make sense?
they have a value:

image

which could be used to sum up rainfall for the last 24h?
they should proivide a forecast for rain as well …

image

Look here :slight_smile:

ooops. sorry

sorry for the late reply, I’ve been rather busy. Because my code is based on using a MQTT switch it’s looking for feedback. Have you tried swapping the switch code for something else like a light or something to test with?

I’m away at the moment so cant test things but hope to have my system fully functioning some time next week when I’m back home

Unfortunately I’ve been busy and currently away so no progress on this so far

yep, I noticed this which can be fixed by removing the initial values for the starts times etc.

not sure why the second station isn’t switching off for you. I will look into all this when I get back home next week

I had a look through my code remotely and found some errors. I haven’t yet had a chance to even look at integrating the weather side of things unfortunately. That will come in time.

Here is the updated code:

reticulation.yaml (package)

########################################
#
#   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
#
#
########################################


sensor:
  - platform: darksky      #   Weather setup
    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_high


      

  - platform: template    # determine if today is selected as a watering day for program 1
    sensors:
      retic_program1_watering_day:
        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:
        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') }}

#   Calculations for rain to stop reticulation


















    
input_datetime:
  retic_program1_start_time:    # program start time control
    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:   # station run time control
    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_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_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_program1_enable:
    name: Enable
    
  retic_program2_enable:
    name: Enable


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.program1_retic_watering_days
      - input_datetime.retic_program1_start_time
      - group.retic_program1_watering_days
#      - input_number.retic_program1_station1_run_time
#      - input_number.retic_program1_station2_run_time
      - group.retic_program1_run_times
    
  retic_program2:
    control: hidden
    name: 'Program 2'
    entities:
      - input_boolean.retic_program2_enable
      - script.retic_program2_run
#      - input_select.program2_retic_watering_days
      - input_datetime.retic_program2_start_time
      - group.retic_program2_watering_days
#      - input_number.retic_program2_station1_run_time
#      - input_number.retic_program2_station2_run_time
      - 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
 
      
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: 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.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: sensor.retic_program1_watering_day
          state: 'true'
    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.state == (states.input_datetime.retic_program2_start_time.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'
    action:
      - service: script.turn_on
        entity_id: script.retic_program2_run


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:{{ 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_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:{{ 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_2_valve

hmm. it seems that this is still not keeping the states of some items on HA restart. I will try and figure out why and post an update, unless someone else can explain it… I know there are work-arounds using persistence but this seems rather annoying to me given that HA is supposed to support it out of the box. Currently my code is keeping the start times and watering days for me but losing the enable and run durations

EDIT: what gets kept and what gets lost during a restart seems pretty random… just an issue with HA, not my code. Hopefully this gets fixed with HA updates

1 Like

@klogg thanks for sharing I changed my irrigation control based on your input, hence it’s a greenhouse I don’t need to worry about the weather (removed it all). I have added my diy soil mosture sensors for each zone.

1 Like

@phdelodder I’m glad it was useful!

@iz3man Can you please list your parts including the bridge rectifier? Cheers

sure. it’s quite simple:

rectifier diodes, similar to those: i used one from a broken sonoff basic:

nodemcu

relay board

dc/dc step down converter

and some 5mm leds.

I really like this. Much cheaper and smaller than my setup but even if I had the electronics skills to build this I already had mine installed before you posted yours. And besides I don’t have a 3D printer!

I really must find some on-line resources to teach myself electronics. Got any pointers? :roll_eyes:

haha. no electronics involved. mostly. it’s the most simple setup you can have. there is just one pin for each relais. and the leds were removed from the relais board and replaced by wires with leds at the end. the dc/dc converter is also easy. 24v in 5v out, and with the little screw you can change the output voltage a bit to your likings. the only “more sophisticated” part is the bridge rectifier. that’s basically a diode network that “transforms” ac in dc so we can use the same powersupply used for the valves for the cpu board. you can just use a second 5v power supply if you prefer that.
but you’re right it’s a very cheap setup. can’t beat that price. great value for what you get.
i on the other hand understand maybe less than 10% of the code you wrote. no idea what’s really going on here :slight_smile:

1 Like

Hi all

Thanks for sharing your yaml config @klogg

I don’t understand where states.sensor.dark_sky_daily_high_temperature.state is taken from.

It’s in the script part of the garden_weather_calculations.yaml file, but I don’t find it.

My darksky config sensor is:

  - platform: darksky
    api_key: !secret darksky_api_key
    forecast:
      - 1
    update_interval: '00:30:00'
    monitored_conditions:
      - summary
      - icon
      - nearest_storm_distance
      - apparent_temperature
      - pressure
      - precip_intensity
      - precip_probability
      - precip_intensity_max
      - humidity
      - wind_speed
      - wind_bearing
      - temperature
      - cloud_cover
      - precip_type
      - daily_summary
      - temperature_high
      - temperature_low

But if I try to look at it in the States under Developer Tools I don’t find it.

Am I missing something?

Thanks

I bought one of those rain gauges a year ago.It works OK with ESPeasy and MQTT. I don’t remember the calculation, but I figured out how many tips per litres of water.