Grass watering based on season

Hi.

Is there a better approach than having to create one automation for each season when automating the grass watering?

Currently, I need to adjust frequency and duration (two zones). My grass requires to be watered differently in summer, fall, winter, and spring. My first thought was: 4 automation triggered by sunrise which weekly frequency and minutes vary per station, but probably there’s a better approach.

Thanks.

Post the automation you are currently using.

What exactly changes each season? Just the days of the week and duration?
Post the details of how the schedule changes each season.

Currently, I need to adjust the frequency and duration of each zone manually. Zone 1 runs for 10 minutes and zone 2 for 15 minutes, with a 15 delay between each.

Here’s the code:

- id: '1607725857757'
  alias: Riego Zona 1 y 2
  description: ''
  trigger:
  - platform: sun
    event: sunrise
    offset: '0'
  condition: []
  action:
  - type: turn_on
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.bomba_riego
    domain: switch
  - type: turn_on
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.riego_zona_1
    domain: switch
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.riego_zona_1
    domain: switch
  - type: turn_off
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.bomba_riego
    domain: switch
  - delay:
      hours: 0
      minutes: 10
      seconds: 0
      milliseconds: 0
  - type: turn_on
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.bomba_riego
    domain: switch
  - type: turn_on
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.riego_zona_2
    domain: switch
  - delay:
      hours: 0
      minutes: 15
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.riego_zona_2
    domain: switch
  - type: turn_off
    device_id: 9309c89658599876e59084eccf87e6a9
    entity_id: switch.bomba_riego
    domain: switch
  mode: single

I’d like this to work as follows:

  • Trigger: sunrise
  • Summer:
    • Days: all
    • Zone 1: 10 min
    • Zone 2: 15 min
  • Fall:
    • Days: mon, wed, friday
    • Zone 1: 8 min
    • Zone 2: 10 min
  • Winter
    • Days: mon, thu
    • Zone 1: 5 min
    • Zone 2: 8 min
  • Spring
    • Days: mon, wed, friday
    • Zone 1: 8 min
    • Zone 2: 10 min

There are several ways to do it. Here’s one:

For the zone duration, simply template the delay. The template sets the number of minutes based on the season.

For the schedule, use a Template Condition that checks the season and the current day.

1 Like

Thank you @123 !

Personal note: RTFM for Templates

I guess that something like this should do the trick

Variables:

{% set delay = {
  "summer": {
    "zone1": "12",
    "zone2": "15"
  },
  "fall": {
    "zone1": "8",
    "zone2": "10"
  },
  "winter": {
    "zone1": "8",
    "zone2": "8"
  },
  "spring": {
    "zone1": "8",
    "zone2": "10"
  }
}%}

Logic

Season: {{ states('sensor.season') }}
Day # is: {{ now().isoweekday() }}

{% if my_test_json.season == "summer" -%}
Delay zone 1: {{ delay['summer']['zone1'] }} minutes
Delay zone 2: {{ delay['summer']['zone2'] }} minutes  
{%- elif my_test_json.season == "fall" -%}
  {%- if now().isoweekday() in [1, 3, 6] -%}
    Water zone 1 for {{ delay['fall']['zone1'] }} minutes
    Water zone 2 for {{ delay['fall']['zone2'] }} minutes  
  {%- endif -%}
{%- elif my_test_json.season == "winter" -%}
  {%- if now().isoweekday() in [1, 4] -%}
    Water zone 1 for {{ delay['winter']['zone1'] }} minutes
    Water zone 2 for {{ delay['winter']['zone2'] }} minutes  
  {%- endif -%}
{%- else -%}
  Water zone 1 for {{ delay['spring']['zone1'] }} minutes
  Water zone 1 for {{ delay['spring']['zone2'] }} minutes
{%- endif %}

Should this be a script or part of the automation? :thinking:

you know about this one?

Create a Season Sensor. It reports the season as spring, summer, autumn, and winter.

Here is an automation that adjusts the watering duration and schedule based on the current season.

- id: '1607725857757'
  alias: Riego Zona 1 y 2
  description: ''
  variables:
    season: "{{ states('sensor.season') }}"
    seasons:
      spring: [1,3,5]
      summer: [1,2,3,4,5,6,7]
      autumn: [1,3,5]
      winter: [1,4]
  trigger:
  - platform: sun
    event: sunrise
    offset: '0'
  condition: '{{ now().isoweekday() in seasons[season] }}'
  action:
  - variables:
      zona_1:
        - switch.bomba_riego
        - switch.riego_zona_1
      zona_2:
        - switch.bomba_riego
        - switch.riego_zona_2
      seasons:
        spring:
          z1: 8
          z2: 10
        summer:
          z1: 10
          z2: 15
        autumn:
          z1: 8
          z2: 10
        winter:
          z1: 5
          z2: 8
  - service: switch.turn_on
    target:
      entity_id: '{{ zona_1 }}'
  - delay:
      minutes: '{{ seasons[season].z1 }}'
  - service: switch.turn_off
    target:
      entity_id: '{{ zona_1 }}'
  - delay:
      minutes: 10
  - service: switch.turn_on
    target:
      entity_id: '{{ zona_2 }}'
  - delay:
      minutes: '{{ seasons[season].z2 }}'
  - service: switch.turn_on
    target:
      entity_id: '{{ zona_2 }}'
  mode: single

How it works

The day of the week is reported by now().isoweekday() where Monday is 1 and Sunday is 7.

The scheduling is handled by this dictionary contained by the variable seasons

    seasons:
      spring: [1,3,5]
      summer: [1,2,3,4,5,6,7]
      autumn: [1,3,5]
      winter: [1,4]

The watering duration for each zone is handled by a slightly more complex dictionary contained by the variable seasons (the same variable name is used and its value is redefined)

    seasons:
      spring:
        z1: 8
        z2: 10
      summer:
        z1: 10
        z2: 15
      autumn:
        z1: 8
        z2: 10
      winter:
        z1: 5
        z2: 8

Let me know if you need more information about how it works.

1 Like

Thanks, man. It is super clear!

I’m re-building this automation and when I save the YAML file, I get this error message:

Message malformed: expected dictionary

This is how it looks after being saved in the UI :tired_face:

alias: Riego por estacion
description: ''
trigger:
  - platform: sun
    event: sunrise
    offset: 0
condition: []
action:
  - variables:
      zona_1:
        - switch.bomba_riego
        - switch.riego_zona_1
      zona_2:
        - switch.bomba_riego
        - switch.riego_zona_2
      seasons:
        spring:
          z1: 8
          z2: 10
        summer:
          z1: 10
          z2: 15
        autumn:
          z1: 8
          z2: 10
        winter:
          z1: 5
          z2: 8
  - service: switch.turn_on
    target:
      entity_id: '{{ zona_1 }}'
  - delay:
      minutes: '{{ seasons[season].z1 }}'
  - service: switch.turn_off
    target:
      entity_id: '{{ zona_1 }}'
  - delay:
      minutes: 20
  - service: switch.turn_on
    target:
      entity_id: '{{ zona_2 }}'
  - delay:
      minutes: '{{ seasons[season].z2 }}'
  - service: switch.turn_off
    target:
      entity_id: '{{ zona_2 }}'
variables:
  season: '{{ states(''sensor.season'') }}'
  seasons:
    spring:
      - 1
      - 3
      - 5
    summer:
      - 1
      - 2
      - 3
      - 4
      - 5
      - 6
      - 7
    autumn:
      - 1
      - 3
      - 5
    winter:
      - 1
      - 4
mode: single

Conseguiste hacerlo funcionar?

I really like the template posted above. To reduce confusion I replaced the multiple definitions of “seasons” with separate variable names (“wateringdays” and “duration”). I also added a weather condition. Final result:

alias: Water the lawn
description: ""
trigger:
  - platform: sun
    event: sunrise
    offset: "0"
condition:
  - condition: template
    value_template: "{{ (now().isoweekday() in wateringdays[season]) and (precipation<0.1) }}"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.sonoff_10004c1399_1
    data: {}
  - delay:
      minutes: "{{ duration[season].z1 }}"
  - service: switch.turn_off
    target:
      entity_id: switch.sonoff_10004c1399_1
    data: {}
  - delay:
      minutes: 1
  - service: switch.turn_on
    target:
      entity_id: switch.sonoff_10004c1399_2
    data: {}
  - delay:
      minutes: "{{ duration[season].z2 }}"
  - service: switch.turn_off
    target:
      entity_id: switch.sonoff_10004c1399_2
    data: {}
variables:
  season: "{{ states('sensor.season') }}"
  wateringdays:
    spring: [1,3,5]
    summer: [1,2,3,4,5,6,7]
    autumn: [1,3,5]
    winter: []
  duration:
    spring:
      z1: 8
      z2: 10
    summer:
      z1: 10
      z2: 15
    autumn:
      z1: 8
      z2: 10
    winter:
      z1: 1
      z2: 1
  precipation: "{{ states('sensor.home_precipitation') | float }}"
mode: single