Irrigation Unlimited

repository·master·Indexed 19 days ago

https://github.com/rgc99/irrigation_unlimited

A Home Assistant integration for managing complex irrigation systems. It supports unlimited controllers, zones, and schedules with hardware-agnostic valve control. Key features include advanced scheduling via absolute time, sun events, and cron expressions, as well as sequencing for ordered zone operation. It provides a hierarchical structure of Controllers, Zones, and Schedules, and includes specialized tools like a Check Back object for state synchronization and a Volume object for flow rate calculation.

Tokens
23.1K
Snippets
49
Records
70
Agent score
65%

What's inside Irrigation Unlimited

  1. Irrigation Unlimited core features

    master

    Irrigation Unlimited provides a hardware-independent, software-independent way to manage complex irrigation needs:

    • Unlimited Scaling: Supports unlimited controllers, zones, schedules, and sequences.
    • Flexible Scheduling: Schedule by absolute time, sun events (sunrise/sunset), days of the week, days of the month (including odd/even), months of the year, or via cron expressions.
    • Sequencing: Run zones in a specific order (a 'playlist') with delays.
    • Hardware Agnostic: Works with any Home Assistant entity that can turn on/off (switches, lights, etc.).
    • Master/Zone Control: Controllers can have 'pre' and 'post'amble periods to manage system warm-up (e.g., starting a pump or master valve) before zones activate.
  2. Targeting controllers, sequences, and zones with service calls

    master

    Irrigation Unlimited uses a hierarchical targeting system for its service calls. To manipulate specific parts of your configuration, you use a combination of entity_id, sequence_id, and zones.

    • entity_id: The primary target, which can be a controller or a specific zone entity.
    • sequence_id: Used when the entity_id is a controller. It targets a specific sequence.
      • Use a number (e.g., 1) to refer to the position (1st, 2nd, etc.).
      • Use a string to refer to the sequence_id.
      • A shortcut to target all sequences under a controller is to use sequence_id: 0 (or simply omit it if the service allows, though 0 is explicitly mentioned for pause/resume).
    • zones: Used when targeting a sequence. It targets zone references within that sequence.
      • Use a number (e.g., 1) for the position.
      • Use a string for the zone_id.
      • A shortcut to target all zones within a sequence is zones: 0.
      • You can also provide a list, e.g., zones: [1, 3, 5].

    Note on Entity IDs:

    • If targeting a sequence or a controller's master state, the entity_id must be the controller's master entity (e.g., binary_sensor.irrigation_unlimited_c1_m).
    • If targeting a specific zone, use that zone's entity (e.g., binary_sensor.irrigation_unlimited_c1_z1).
  3. How Sequence Objects work

    master

    Sequences allow zones to run one at a time in a specific order with a delay in between (a watering 'playlist').

    Key Behaviors:

    • Sequences descend from a controller and connect to zones via zone_id.
    • If a schedule.duration is specified for a sequence, all zones in that sequence are proportionally adjusted to fit that total duration. For example, if zones are set for 10, 20, and 30 minutes (total 60m) and the schedule duration is 30m, the zones will run for 5, 10, and 15 minutes respectively.
    • If using a pump or master valve, consider setting the controller's postamble to the largest delay in your sequence to prevent unnecessary pump on/off operations.
    | Name | Type | Default | Description |
    | ---- | -----| ------- | ----------- |
    | `schedules` | list | _[Schedule Objects](#55-schedule-objects)_ | Schedule details (Optional). Note: `duration` if specified is the total run time for the sequence, see below for more details |
    | `zones` | list | _[Sequence Zone Objects](#57-sequence-zone-objects)_ | Zone details (Must have at least one) |
    | `delay` | [duration](#142-duration-time-period) | | Delay between zones. This value is a default for all _[Sequence Zone Objects](#57-sequence-zone-objects)_. Can be negative to make the next zone on _before_ the current zone has finished |
    | `duration` | [duration](#142-duration-time-period) | | The length of time to run each zone. This value is a default for all _[Sequence Zone Objects](#57-sequence-zone-objects) |
    | `repeat` | number | 1 | Number of times to repeat the sequence |
    | `name` | string | Run _N_ | Friendly name for the sequence |
    | `sequence_id` | string | _N_ | Sequence reference. This must be in [snake_case](#13-snake-case) style with the exception the first character _can_ be a number |
    | `enabled` | bool | true | Enable/disable the sequence |
  4. Naming identifiers using snake_case

    master

    All identifiers, including controller_id, zone_id, and schedule_id, must follow snake_case format.

    Rules for snake_case in this project:

    • Use only lowercase alphabet, numerals, and underscores (_).
    • Underscores cannot be leading or trailing.
    • Do not use consecutive underscores.

    Examples: my_garden, vege_patch, rose_bed, front_lawn, before_dawn.

  5. Understand the Irrigation Unlimited hierarchy

    master

    Irrigation Unlimited uses a tree-like structure to organize irrigation logic. The hierarchy flows from Controllers down to Schedules:

    • Controller: The top-level entity. A controller can manage multiple zones and sequences. It has an associated master binary sensor (binary_sensor.irrigation_unlimited_cN_m).
    • Zone: A child of a controller. Each zone has its own binary sensor (binary_sensor.irrigation_unlimited_cN_zN) and can have multiple schedules.
    • Schedule: Defines when a zone should run (e.g., absolute time, sun events, cron).
    • Sequence: A 'playlist' of zones that operate one at a time in a specific order with delays between them. Sequences are children of a Controller.

    Entity Naming Convention:

    • Controller Master Sensor: binary_sensor.irrigation_unlimited_cN_m (where cN is the controller index).
    • Zone Sensor: binary_sensor.irrigation_unlimited_cN_zN (where cN is the controller index and zN is the zone index).
  6. Use sequences to manage multiple zones

    master

    Sequences allow you to group multiple zones and define a specific execution order, delays between zones, and shared schedules. In a sequence, you define zones with a zone_id that maps to the index of the zones defined in the controllers section. If a duration is provided at the sequence level, it represents the total duration of the sequence, and individual zone durations are adjusted accordingly if specified in the schedule.

    irrigation_unlimited:
      controllers:
        zones:
          - name: "Front lawn"
            entity_id: "switch.my_switch_1"
          - name: "Vege patch"
            entity_id: "switch.my_switch_2"
          - name: "Flower bed"
            entity_id: "switch.my_switch_3"
        sequences:
          - delay: "00:01"
            schedules:
              - name: "Sunrise"
                time:
                  sun: "sunrise"
              - name: "After sunset"
                time:
                  sun: "sunset"
                  after: "00:30"
            zones:
              - zone_id: 1
                duration: "00:10"
              - zone_id: 2
                duration: "00:02"
              - zone_id: 3
                duration: "00:01"
  7. Monitor valve state changes and water volume

    master

    The events irrigation_unlimited_valve_on and irrigation_unlimited_valve_off are fired whenever a valve changes state. These are useful for monitoring real-time flow and detecting issues like blockages (too little water) or burst pipes (too much water).

    To implement volume monitoring:

    1. Ensure you have set up volume monitoring as described in the Volume Object documentation.
    2. Use the irrigation_unlimited_valve_off event to trigger a check against your expected volume thresholds.
    3. Use the trigger.event.data.volume field to compare the actual volume against your min and max limits.
    alias: Irrigation volume checker
    description: Irrigation Unlimited Volume Checker
    triggers:
      - trigger: event
        event_type:
          - irrigation_unlimited_valve_off
    conditions:
      - condition: template
        value_template: >-
          {{ id in volumes and (vol < volumes[id]['min'] or vol >
          volumes[id]['max']) }}
    actions:
      - action: notify.NOTIFIER_NAME # Make sure this matches the "NOTIFIER_NAME" in the smtp setup
        data:
          title: Irrigation Volume Error
          message: >
            Time: {{ as_local(trigger.event.time_fired).strftime('%c') }}
            Controller: {{ trigger.event.data.controller.index + 1 }} {{ trigger.event.data.controller.name }}
            Zone: {{ trigger.event.data.zone.index + 1 }} {{ trigger.event.data.zone.name }}
            Volume: {{ vol }}
    mode: queued
    variables:
      id: "{{ trigger.event.data.iu_id }}"
      vol: "{{ trigger.event.data.volume | float(0) }}"
      # Fill in this table of zones and their minimum and maximum volumes
      volumes: |
        {{ dict([
          ('c1_z1', {'min': 5, 'max': 25}),
          ('c1_z3', {'min': 10, 'max': 80}),
          ('c1_z4', {'min': 10, 'max': 100}),
        ]) }}
  8. Adjust irrigation run times via automation

    master

    Irrigation Unlimited does not include built-in auto-adjustment for weather. Instead, you achieve run-time adjustment by creating Home Assistant automations that call the irrigation_unlimited.adjust_time service. This service allows you to modify watering durations based on external sensors (rainfall, temperature, soil moisture, etc.).

    service: irrigation_unlimited.adjust_time
    data:
      entity_id: binary_sensor.irrigation_unlimited_c1_m
      percentage: 50
  9. Integrate with HAsmartirrigation

    master

    To use HAsmartirrigation with Irrigation Unlimited, you need two automations:

    1. Adjustment: Triggered when the smart_irrigation sensor state changes. It calls irrigation_unlimited.adjust_time using the actual parameter (converted from seconds to a timedelta).
    2. Reset: Triggered by the irrigation_unlimited_finish event to reset the HAsmartirrigation bucket after watering is complete.

    Note: You must replace [zone_name] and binary_sensor.irrigation_unlimited_c1_s1 with your actual entity IDs.

    # Example automation for HAsmartirrigation integration
    automation:
      - alias: Smart Irrigation adjustment
        id: "IU1653097957047"
        description: Adjust watering times based on smart irrigation calculations
        mode: single
        triggers:
          - trigger: state
            entity_id: sensor.smart_irrigation_[zone_name] # <== Change this
            to: null
        actions:
          - action: irrigation_unlimited.adjust_time
            data:
              actual: "{{ timedelta(seconds=trigger.to_state.state | int(0)) }}"
              entity_id: binary_sensor.irrigation_unlimited_c1_s1 # <== Change this
    
      - alias: Smart Irrigation reset bucket
        id: "IU1653098247170"
        description: Resets the Smart Irrigation bucket after watering
        mode: single
        triggers:
          - trigger: event
            event_type: irrigation_unlimited_finish
        condition:
          - "{{ trigger.event.data.schedule.index is not none }}"
          - "{{ trigger.event.data.entity_id == 'binary_sensor.irrigation_unlimited_c1_s1' }}" # <== Change this
        actions:
          - action: smart_irrigation.reset_bucket
            entity_id: sensor.smart_irrigation_[zone_name] # <== Change this
            data: {}
  10. Configure Irrigation Unlimited via YAML

    master

    Irrigation Unlimited is configured using YAML. Configuration can be reloaded without restarting Home Assistant.

    Note on Precedence: If a yaml configuration is present, it takes precedence over any settings made through the Home Assistant UI. UI configuration is optional.

  11. Configure controllers, zones, sequences, and schedules via the UI

    master

    The Home Assistant UI allows you to manage the following core components:

    • Controllers: Set the name and master valve entity.
    • Zones: Set the name, switch entity, and default duration.
    • Sequences: Set the name and zone order.
    • Schedules: Set the start time, duration, and frequency (days of week or every N days).

    Limitations: The UI is an experimental subset of the full feature set. Advanced features like sun events, cron expressions, adjustments, history, check-back, and advanced sequence options require YAML configuration.