Irrigation Custom Component with Custom Card

I had a working yaml based irrigation system, it worked but it was not easy to set up. So I bit the bullet and decided to educate myself in the arcane art of custom components.

I am now up to version 5 with config flow and a custom card and the component and related custom card are available on HACS.

Please visit the GITHUB repository for full details

All the inputs of the new platforms are Home Assistant entities for example the start time is provided via a input_datetime entity. The information is used to define a template internally that is evaluated to trigger the irrigate action according to the inputs provided.

Watering can occur in an Eco mode where a water/wait/repeat cycle is run to minimise run off by letting water soak as a by using several short watering cycles.

The rain sensor is implemented as a binary_sensor, this allows a practically any combination of sensors to suspend the irrigation. Additionally being implemented as a switch you can start a program or zone based manually or using an automation. There is also the ability to ignore the rain sensor at the program or zone level so sheltered areas can be watered even if the rain sensor has been activated.

8 Likes

Hi Peter, are you still maintaining this? It blows me away you haven’t gotten way more traction with this considering that irrigation control is consistently a top thread in the HA forums…

Hi Drew,

Thanks for the feedback I’m still using it. And your the first person to make contact so I haven’t had any changes for a while. It’s been very stable for my purposes.

I find it easier to maintain than loads of yaml.

I’m using esphome for the esp8266 and it works a treat.

Merry Christmas

3 Likes

Gosh. I only just stumbled across this whilst browsing the forums to kill time. This looks pretty great! Will fire it up and play around.

That’s it a very interesting project. I, myself just stumbled into it; this would be very useful to me. Thank you for sharing that.

First of thank you for your hard work on this. I just tried to play around with it and so far i’m not have any luck of passing the config check.
irrigation_error

this is how my config look like

irrigation:
  programs:
    - name: Morning
      template: "{{ state_attr('irrigation.morning', 'days_since') > 2 }}"
      icon: mdi:fountain
      start: "07:00"
      zones:
        - zone: irrigation_zone.zone_one
          water: 5
          wait: 5
          repeat: 2
        - zone: irrigation_zone.zone_two
          water: 5
          wait: 5
          repeat: 2
        - zone: irrigation_zone.zone_three
    - name: afternoon
      template: "{{  states('sensor.time') == '18:00' and now().strftime('%a') in ['Mon','Wed','Thu','Fri','Sun'] }}"
      start: "16:00"
      zones:
        - zone: irrigation_zone.zone_one
        - zone: irrigation_zone.zone_two
        - zone: irrigation_zone.zone_three
1 Like

Glad to help, an attempt to give back to the HA crowd. Sorry my example package is out of date.

remove the ‘start’ attribute and put the time you want to start in the template here are the examples:

irrigation:
  programs:
    - name: Morning
      template: "{{ states('sensor.time') == '07:00' and state_attr('irrigation.morning', 'days_since') > 2 }}"
      icon: mdi:fountain
      zones:
        - zone: irrigation_zone.zone_one
          water: 5
          wait: 5
          repeat: 2
        - zone: irrigation_zone.zone_two
          water: 5
          wait: 5
          repeat: 2
        - zone: irrigation_zone.zone_three
    - name: afternoon
      template: "{{ states('sensor.time') == '18:00' and now().strftime('%a') in ['Mon','Wed','Thu','Fri','Sun'] }}"
      zones:
        - zone: irrigation_zone.zone_one
        - zone: irrigation_zone.zone_two
        - zone: irrigation_zone.zone_three

You will also need to define the zones referenced to relate the zone to a switch entity you have already set up in HA. This is where you set up the default watering for each zone so you don’t have to set it in each program.

  zones:
  - name: zone_one
    water: 1
    switch_entity: switch.solenoid_01
    icon_off: 'mdi:carrot'
  - name: zone_two
    water: 1
    switch_entity: switch.solenoid_02
  - name: zone_three
    water: 1
    icon_off: 'mdi:flower'
    switch_entity: switch.solenoid_03
2 Likes

Irrigation is on my to do list before next summer. This looks like a good option.

Hope to be back here soon to try it out.

1 Like

I just want to say thank you this great project. It’s been 3 days so far and the the component is working as intended. My sprinklers kicked on at the exact time. Te configuration was very simple.
this is how mine look.

irrigation:
  programs:
    - name: Morning
      template: "{{ states('sensor.time') == '07:00' and state_attr('irrigation.morning', 'days_since') > 2 }}"
      icon: mdi:fountain
      zones:
        - zone: irrigation_zone.zone_one
          water: 5
          wait: 2
          repeat: 2
        - zone: irrigation_zone.zone_two
          water: 5
          wait: 2
          repeat: 2
        - zone: irrigation_zone.zone_three
    - name: afternoon
      template: "{{ states('sensor.time') == '16:00' and now().strftime('%a') in ['Mon','Wed','Thu','Fri','Sun'] }}"
      zones:
        - zone: irrigation_zone.zone_one
        - zone: irrigation_zone.zone_two
        - zone: irrigation_zone.zone_three

  zones:
    - name: zone_one
      water: 5
      switch_entity: switch.zone1_esp32
      icon_off: 'mdi:flower-outline'
    - name: zone_two
      water: 5
      icon_off: 'mdi:flower-poppy'
      switch_entity: switch.zone2_esp32
    - name: zone_three
      water: 5
      icon_off: 'mdi:flower-tulip'
      switch_entity: switch.zone3_esp32

Lovelace Card:

title: Sprinkler
icon: mdi:water-pump
#background: center / cover no-repeat url("/local/lovelace/bedrooms/sprinkler-wall.jpg") fixed
panel: false
path: sprinklersys
cards:
  - type: vertical-stack
    cards:
      - type: horizontal-stack
        cards:
          - type: 'custom:vertical-stack-in-card'
            cards:
              - type: entities
                title: Sprinkler System
                show_header_toggle: false
                entities:
                  - entity: irrigation.morning
                    name: Morning Schedule
                  - entity: irrigation.afternoon
                    name: Afternoon Schedule
              - type: custom:hui-horizontal-stack-card
                cards:
                  - type: custom:button-card
                    template: main-view
                    entity: irrigation_zone.zone_one
                    icon: 'mdi:flower-outline'
                    show_entity_picture: true
                    show_state: true
                    name: Zone One
                  - type: custom:button-card
                    template: main-view
                    entity: irrigation_zone.zone_two
                    icon: 'mdi:flower-poppy'
                    show_entity_picture: true
                    show_state: true
                    name: Zone Two
                  - type: custom:button-card
                    template: main-view
                    entity: irrigation_zone.zone_three
                    icon: 'mdi:flower-tulip'
                    show_entity_picture: true
                    show_state: true
                    name: Zone Three
1 Like

Thanks for your work on this, I’ve used some of it, and had to change some stuff as I have a slightly different setup. But it’s been really useful.

Merry Christmas to you to! (bit late now…)

Hi
Not sure if this is still maintained, but set it up and get this in the logs

Logger: homeassistant.setup
Source: custom_components/irrigation/init.py:213
First occurred: 14:51:25 (1 occurrences)
Last logged: 14:51:25

Error during setup of component irrigation
Traceback (most recent call last):
File “/usr/src/homeassistant/homeassistant/setup.py”, line 213, in _async_setup_component
result = await task
File “/config/custom_components/irrigation/init.py”, line 213, in async_setup
template_entity_ids = template.extract_entities()
AttributeError: ‘Template’ object has no attribute ‘extract_entities’

Hi Terence,
I am still using the addon myself. I have created a version 2 of the component.


I needed a more end user friendly version.

If you want to use the older version can you send me your yaml so I can check it.

1 Like

Peter
Thank for this I will give it a go.
Currently I have esphome onfigured with the automations on the esp. I then activate the the solenoids by a service call so that the logic runs on the esp. That way if the esp looses connection to the server or on the case of a power failure, the solenoids will close.

I still have not figured out how to have a running timer on home assistant to display the remaining time.

Peter

For reference here is the yaml from my v1 setup

programs:
  - name: Morning
    template: "{{ states('sensor.time') == '07:00' and state_attr('irrigation.morning', 'days_since') > 2 }}"
    icon: mdi:fountain
    zones:
      - zone: irrigation_zone.zone_one
        water: 5
        wait: 5
        repeat: 2
      - zone: irrigation_zone.zone_two
        water: 5
        wait: 5
        repeat: 2
      - zone: irrigation_zone.zone_three
  - name: afternoon
    template: "{{ states('sensor.time') == '18:00' and now().strftime('%a') in ['Mon','Wed','Thu','Fri','Sun'] }}"
    zones:
      - zone: irrigation_zone.zone_one
      - zone: irrigation_zone.zone_two
      - zone: irrigation_zone.zone_three

zones:
- name: zone_one
  water: 1
  switch_entity: switch.solenoid_01
  icon_off: 'mdi:carrot'
- name: zone_two
  water: 1
  switch_entity: switch.solenoid_02
- name: zone_three
  water: 1
  icon_off: 'mdi:flower'
  switch_entity: switch.solenoid_03

Peter

What happens if the solenoid controller looses connection with home assistant

In my new repository I have the yaml I use for ESPHOME. I have a max runtime setting that limits the time a solenoid can run as a catchall should the esp loose connection to HA.

let me know how you go with the new rep, no one else has picked this version up that I know of.

2 Likes

I see that now. I will do I need to reconfigure my esphome devices.
By the way when I first loaded I am getting a device not found for the program entity is this correct

Hi, Check your switches in the zones definition are correct for example:
zones:
- zone: switch.pot_plants
- zone: switch.front_lawn
these switches need to be defined and are typically those exposed by your ESP’s

I have updated my sample code to fix this if you copied my examples.

1 Like

Peter

It was more the switch.morning that I was concerned about switch.morning, that is a entity not found. The I am concerned that the irrigation program component did not run correctly?

The zone switches will be updated once I expose and connect the Esp

Logger: homeassistant.components.switch
Source: custom_components/irrigationprogram/switch.py:192 
Integration: Switch (documentation, issues) 
First occurred: 9:24:49 (3 occurrences) 
Last logged: 9:24:49

Error adding entities for domain switch with platform irrigationprogram
Error while setting up irrigationprogram platform for switch
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 315, in async_add_entities
    await asyncio.gather(*tasks)
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 506, in _async_add_entity
    await entity.add_to_platform_finish()
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 530, in add_to_platform_finish
    await self.async_added_to_hass()
  File "/config/custom_components/irrigationprogram/switch.py", line 192, in async_added_to_hass
    self._last_run     = state.attributes.get('last_ran')
AttributeError: 'NoneType' object has no attribute 'attributes'

Terence,

I have updated the irrigationprogram, switch.py. Can you copy it and try again. Thanks for working through this. This is the first time this has been installed from scratch from the github repository.