Garden Irrigation

I would be interested to see the hardware solution. I have a greenhouse and looking for inspiration on how to improve.

@phdelodder have a look at this complete project (of raised garden). Electronics at the bottom of the pictures.

4 Likes

Nice job!

Where did you buy the valves?

An irrigation supply shop. (NZ based). But Amazon does them too. About NZ$35/piece, which is a steal.

They are the non-latching type. Again, if things go sour, they’ll close when power is cut, thus not flooding the garden.

Being 24VAC, it’s a bit of a pain. The OpenSprinkler system/board can control them from 5VDC due to some clever electronics design. In my case, I just used a step-down transformer.

1 Like

I think I’m gonna go even a bit smaller scale, there are similiar way smaller normally closed valves selling on ebay for 3usd. Also dunno if I should go with a dedicated software - https://github.com/Dan-in-CA/SIP

In any case I’d be interested in all your code :slight_smile: and yaml for this stuff :). Very nice! So you think that Sonoff 4CH Pro, would be a nice controller once Tasmota fw supports it :slight_smile: ?

I have finally got everything in hass to work as desired. Configuring the automation was “baptism by fire”, due to some undocumented quirks… Let’s say don’t use now() function as a trigger in automation… more on it in “Having Trouble with Template Trigger”.

For now as a teaser, I’ post a couple of pics from my “Garden Irrigation Dashboard” and when I get chance, I’ll post the code too. Hopefully, tonight.

All .yaml files. Names denoted at the top of each section.

configuration.yaml
- platform: template
    sensors:
      zone_1_timer:
        value_template: '{{ "{:02d}".format(states.input_slider.timer_hours_1.state|int) }}:{{ "{:02d}".format(states.input_slider.timer_minutes_1.state|int) }}'
        friendly_name: "Time"
      last_run_zone_1:
        friendly_name: "Last Run"
        value_template: '{{ (as_timestamp(states.switch.zone_1.last_changed)) |   timestamp_custom("%A, %d %h %H:%M") }}'
      next_run_zone_1:
        friendly_name: "Next Run"
        value_template: '{{states.sensor.zone_1_timer_reset_sensor.state}}'

      time_delta:
        friendly_name: "Zone 1 Timedelta"
        value_template: '{{states.input_slider.repeat_1.state|int * 3600}}'
      duration_1:
        value_template: '{{states.input_slider.duration_1.state | int}}mins'
        friendly_name: "Duration"
      repeat_1:
        value_template: '{{ "{:02d}".format(states.input_slider.repeat_1.state|int)}}hrs'
        friendly_name: "Repeat in"
      rain_sensor:
        friendly_name: "Rainfall Threshold Sensitivity"
        value_template: >-
          {% if states.sensor.pws_precip_1d.state <= states.input_slider.pws_precip_1d_sensitivity.state and states.sensor.pws_precip_today_metric.state <= states.input_slider.pws_precip_today_metric_sensitivity.state %}
            dry
          {% else %}
            too wet
          {% endif %}

switch mqtt:
  - platform: mqtt
    name: "Zone 1"
    state_topic: "stat/irrigation/POWER1"
    command_topic: "cmnd/irrigation/POWER1"
    payload_on: "ON"
    payload_off: "OFF"
    qos: 0
    retain: true

binary_sensor mqtt:
  - platform: mqtt
    name: "ZONE 1"
    device_class: moisture
    state_topic: "cmnd/irrigation/POWER1"
    payload_on: "ON"

sensor mqtt:
  - platform: mqtt
    name: "Zone 1 Timer Reset Sensor"
    state_topic: "cmnd/zone_1_control/TIMER"

input_boolean:
  reset_zone_1:
    name: Reset Next Run Timer
    initial: off
    icon: mdi:lock-reset

input_slider:
  timer_minutes_1:
    name: "Minutes"
    initial: 0
    min: 0
    max: 55
    step: 1
    icon: mdi:timer
  timer_hours_1:
    name: "Hour"
    initial: 6
    min: 0
    max: 23
    step: 1
    icon: mdi:timer
  duration_1:
    name: "Set Duration"
    initial: 3
    min: 0
    max: 15
    step: 1
    icon: mdi:camera-timer
  repeat_1:
    name: "Set Repeat"
    initial: 24
    min: 0
    max: 48
    icon: mdi:repeat
  pws_precip_today_metric_sensitivity:
    name: "Rainfall mm Sensitivity"
    initial: 0.1
    min: 0
    max: 2
    step: 0.1
    icon: mdi:contrast
  pws_precip_1d_sensitivity:
    name: "Rainfall Probability Sensitivity"
    initial: 40
    min: 0
    max: 100
    step: 10
    icon: mdi:contrast

groups.yaml
garden:
  view: yes
  control: hidden
  name: "Garden"
  entities:
   - group.solenoids
   - group.irrigation_timer_1
   - group.rain_sensor
   - sensor.pws_precip_today_metric
   - sensor.pws_precip_1d
   - binary_sensor.zone_1


solenoids:
  view: no
  name: "Back Garden Irrigation"
  icon: 'mdi:flower'
  entities:
    - switch.zone_1


rain_sensor:
  view: no
  name: "Rainfall Sensitivity"
  icon: mdi:contrast
  entities:
    - sensor.rain_sensor
    - input_slider.pws_precip_today_metric_sensitivity
    - input_slider.pws_precip_1d_sensitivity

irrigation_timer_1:
  view: no
  name: "Sprinklers Zone 1"
  icon: mdi:clock
  entities:
    - sensor.last_run_zone_1
    - sensor.next_run_zone_1
    - sensor.duration_1
    - sensor.repeat_1
    - group.setting_zone_1
    - automation.activate_zone_1_timer

setting_zone_1:
  view: no
  control: hidden
  name: "Settings"
  icon: mdi:settings
  entities:
    - sensor.zone_1_timer
    - input_slider.timer_hours_1
    - input_slider.timer_minutes_1
    - input_slider.duration_1
    - input_slider.repeat_1
    - input_boolean.reset_zone_1

automations.yaml
- id: "Activate_Zone_1_Timer"
  alias: "Activate Zone 1 Timer"
  trigger:
    - platform: time
      minutes: '/1'
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{(as_timestamp(now()) | timestamp_custom("%A, %d %h %H:%M"))  == states.sensor.next_run_zone_1.state}}'
    - condition: state
      entity_id: sensor.rain_sensor
      state: 'dry'
  action:
    - service: script.turn_on
      entity_id: script.activate_irrigation_zone_1


- id: "Zone_1_ON_Notification"
  alias: "Zone 1 Active Notification"
  hide_entity: False
  trigger:
    - platform: state
      entity_id: switch.zone_1
      from: 'off'
      to: 'on'
  action:
    - service: notify.pushbullet
      data:
        title: "Irrigation Zone 1"
        message: "Watering has started"
- id: "Zone_1_OFF_Notification"
  alias: "Zone 1 Completed Notification"
  hide_entity: False
  trigger:
    - platform: state
      entity_id: switch.zone_1
      from: 'on'
      to: 'off'
  action:
    - service: notify.pushbullet
      data:
        title: "Irrigation Zone 1"
        message: "Watering has completed"

- id: "Zone_1_Timer_Reset"
  alias: "Zone 1 Timer Reset"
  trigger:
    - platform: state
      entity_id: input_boolean.reset_zone_1
      from: 'off'
      to: 'on'
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/zone_1_control/TIMER"
        retain: 1
        payload_template: >-
          {%if now().strftime("%H:%M") > states.sensor.zone_1_timer.state %}
            {{(as_timestamp(now() )+24*3600 ) | timestamp_custom("%A, %d %h ")}}{{states.sensor.zone_1_timer.state}}
          {%else%}
            {{(as_timestamp(now() ) ) | timestamp_custom("%A, %d %h ")}}{{states.sensor.zone_1_timer.state}}
          {%endif%}
    - delay:
        seconds: 1
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.reset_zone_1
- id: "Extend_Zone_1_Timer_When_Wet"
  alias: "Extend Zone 1 Timer When Wet"
  trigger:
    - platform: time
      minutes: '/1'
  condition:
    condition: and
    conditions:
    - condition: template
      value_template: '{{(as_timestamp(now()) | timestamp_custom("%A, %d %h %H:%M"))  == states.sensor.next_run_zone_1.state}}'
    - condition: state
      entity_id: sensor.rain_sensor
      state: 'too wet'
  action:
    - service: mqtt.publish
      data:
        topic: "cmnd/zone_1_control/TIMER"
        retain: 1
        payload_template: '{{(as_timestamp(now() )+ states.sensor.time_delta.state | int) |   timestamp_custom("%A, %d %h %H:%M") }}'

scripts.yaml
activate_irrigation_zone_1:
  alias: "Activate Irrigation Zone 1"
  sequence:
    - alias: "Switch on Zone 1"
      service: switch.turn_on
      entity_id: switch.zone_1
    - delay: '00:{{ states.input_slider.duration_1.state | int }}:00'
    - alias: "Switch off Zone 1"
      service: switch.turn_off
      entity_id: switch.zone_1
    - alias: "Update Next Run Time"
      service: mqtt.publish
      data:
        topic: "cmnd/zone_1_control/TIMER"
        retain: 1
        payload_template: '{{ (as_timestamp(states.switch.zone_1.last_changed)+ states.sensor.time_delta.state | int) |   timestamp_custom("%A, %d %h %H:%M") }}'

All settings are shown for a single Zone. In pictures you can see multiple zones… just copy all settings, like there’s no tomorrow :smiley:

12 Likes

@marksev1 there was something about those smaller valves that my irrigation shop told me that made me pass on them… if I could just remember…hmmm At any rate the obvious considerations are water pressure, driving voltage, size, connection to your pipes…etc.

That Sonoff product looks very nice. Had I found that earlier, I’d probably not had bothered with my project :joy:

I’ve just noticed that TASMOTA now supports it!

Very nice set up. So you have a “rain sensor”? What about integration with an online meteo-api? That it would also take that into account?

It’s a pretend rain sensor… I’m using a local WU station… about 2km as the crow flies. So far it’s been fairly spot on.

Petr why is it turning the system on and off so much times during the day, based on the red lines in the history thing? Wouldnt that fatigue the system, shouldn’t the grass need irrigation less times a day.

That’s just me testing the automation rules, as I pointed out, there is a quirk that took me a while to crack.

Also, that history is not really the irrigation switching on/off, but me pressing the “Reset Next Run Timer” button. This also shows a bit of a limitation of HA and an unusual phenomenon, I’ll call “ghosting”. Which ever element is listed last in the group, will be reflected at the top of this modal window. Including the state of the element. So if it’s a switch, as in my case, it keeps showing on/off state. In the upper screen in the view “Sprinklers Zone 1” > Settings, you can also see the state of the switch. It would be nice to be able to specify your own text, but I can live with that.

Ideally, the whole sprinkler Zone should be an “installable” component. The whole premise is fairly simple, flexible and universal, provided your controller supports MQTT.

I might order myself the Sonoff 4CH PRO, just for fun and once it’s flashed with TASMOTA it should work without any further tweaks. Thinking about it, it’s pretty much exactly the same thing I built. :smiley: Hand on my heart, I had not known about the Sonoff 4CH PRO.

Hi. Just FYI - latest model of Sonoff might have some “improvements” that require additional steps when flashing. I’ve just received Sonoff Dual. It has one more microchip onboard. That’s why regular procedure does not work. Possible solution explained in this video https://youtu.be/8naMP_OpBuY?t=3m25s. Keep it in mind when taking final decision.

Hello,
can you tell me which provider use for weather or what to change to make work with weatherundergroud.

Thanks.

Using the hard work of @petr I have managed a zone irrigation system. I made a few small changes:

  • Include a boolean to disable/enable the rain sensor
  • Save the next run in a different format
  • Small changes

The configuration can be found here

4 Likes

It is working with WU. You need to setup the backend, activate sensors you’re interested in, in my case it was today’s precipitation chance %, and today’s precipitation mm, which I use for establishing if it has rained and if it is going to rain.

It’s good to have a look for a local weather station, just to improve the accuracy of local predictions and observations.

Just a word of warning, there are times when a proper soil moisture sensor beats any external data. You could find that the day before it rained so hard that the soil is still waterlogged, yet “today’s” predictions and observations, might let the sprinkler water your garden.

You could improve that further by capturing and storing a variable from the day before, i.e. capture it today and use it tomorrow… someone correct me, but I’m not sure if WU provides historical data through the API used. If so, then just look a day back, set a slider for sensitivity of the wetness, so you can dynamically change it later (similar to current observations).

This amazing!
Thanks guys!!! This is what brought me to home assistant in the first place.

It took me a long time to get this to show up in HA; many ‘check configs’ we pressed, but I finally got it to work… I think it does…

I was hoping you could walk me through some of the basic requirements to get this up and running.
What I did was copy anything related to “Greenhouse” “zone_1” "serre ":

config.yaml

#wunderground

sensors.yaml

“# temperature serre”
“# humidity serre”
#Greenhouse
#Greenhouse zone 1”
platform: mqtt “Zone 1 Timer Sensor”
platform: mqtt “Soil Moisture Zone 1”

automations.yaml:

id: Activate_Greenhouse_Zone_1_Button
id: Activate_Greenhouse_Zone_1_Timer
id: Greenhouse_Zone_1_Timer_Reset
id: Greenhouse_Zone_1_Set_Rain_Sensor

groups.yaml

GreenhouseSensors:
GreenhouseDevices:
IrrigationZones:
IrrigationButtons:
IrrigationTimer1:
SettingsZone1:
SerreView:
rain_sensor:

scripts.yaml

activate_irrigation_greenhouse_zone_1:
extend_greenhouse_zone_1_when_wet:

binary_sensors.yaml

name: “greenhouse button 1”
name: “greenhouse button 2”
name: “greenhouse button 3”
name: “greenhouse button 4”
name: “include rain sensor 1”
name: “Greenhouse_Control_1_Status”
name: “Greenhouse_Control_2_Status”
name: “Greenhouse_Control_3_Status”

input_boolean.yaml

reset_zone_1:
include_rain_sensor_1:

input_number.yaml

#Rain
#Zone_1

Did I miss anything?

The errors i’m getting are:
Template error: UndefinesError: ‘value_jason’ is undefined
Unable to find service sensor/turn_off
Unable to find service input_number/turn_off
Unable to find service binary_sensor/turn_off

If these errors are simply because I don’t have the sensors yet, I can live with that for now (they’re in the mail).
I have a weather underground account setup in the config with the api key, but I do not have the hygrometers yet. While I have a sonoff basic with tasmota and an dht-22, i’m not quite sure how to get the sonoff to report back to the script. (I don’t want to futz around with your code since it took me this long to get it up, but would prefer to change the name of my sonoff to match -at least until I can grasp this beast of an automation).

Thanks for helping if you can, any advice is much appreciated!

I see you mention template error, maybe you can validate the template with the develop tool?

Unfortunately this is beyond my scope of understanding. How would I validate the template with the develop tool?
I just copy pasted what you have on your github.

Thanks

Is there more information in the home-assistant log? perhapse a trace.

Hi, were you able to get the water flow meter working, with the sonoff’s if yes do you mind sharing the code.
I’m battling, from what I understand the sonoffs has a counter option if flashed with tasmota. How on earth do I get accurate readings to display in litres on HA.

Any form of help will be much appreciated.