Simple irrigation automation

Hello,

I would like to create a simple irrigation automation that will:

  1. turn the pump ( switch.irrigationbalcony ) on :
  • 30 min before sunrise
  • at 09:00
  • at 15:00
  • 100 min after sunset
  1. for N minutes (N should be a variable that can be changed via UI widget like a scroll, “+/-”, arrows or similar).

(a). What is the best way to write this? Preferably It should be one automation (instead of 4) that can be enabled/disabled at once. Maybe with scripts somehow?
(b) What is the best place in UI for widget configuring N (if it is possible to choose a place for it at all)?

Thank you very much in advance!

Input Number:

input_number:
  minute_delay:
    name: Delay in Minutes
    min: 0
    max: 35
    step: 1

Automation:

trigger:
  - platform: sun
    event: sunrise
    offset: "-00:30:00"
  - platform: time
    at:
      - "09:00:00"
      - "15:00:00"
  - platform: sun
    event: sunset
    offset: "01:40:00"
action:
  - service: switch.turn_on
    target:
      entity_id: switch.irrigationbalcony
  - delay: "{{ states('input_number.minute_delay') | multiply(60) | int }}"
  - service: switch.turn_off
    target:
      entity_id: switch.irrigationbalcony

Put the input number in an entities card in the Lovelace frontend.

2 Likes

Worked perfectly. Exactly as I wanted! And I learned a couple of new things. Thank you very much!

1 Like

Beware that restarting home assistant while the automation is waiting in the delay will prevent this turning off.

1 Like

What is the proper solution to this problem?

Define another automation that will trigger at

"09:00:00 + 'input_number.minute_delay'"

?

Another automation:

trigger:
  - platform: state
    entity_id: switch.irrigationbalcony
    to: 'on'
    for: "{{ states('input_number.minute_delay') | multiply(60) | int }}"
action:
  - service: switch.turn_off
    target:
      entity_id: switch.irrigationbalcony

Worst case is running for double the time - If the delay was just about to expire when you restarted.

There are other options that use timers that can be restored with a bit of work:

1 Like

Shouldn’t this “cut off” automation fire even if I turn on the switch.irrigationbalcony manually? - Which is actually a great thing if one turns on the irrigation manually and forgets about it… this automation should turn it off after input_number.minute_delay minutes… The problem - it doesn’t seem to launch if I turn irrigation manually… what is wrong?

Yes it should. Do you have the correct switch entity_id?

Works great, as expected. Didn’t change anything. Don’t know why id didn’t work before… Thank you!