Why did part of my irrigation automation not execute?

I have an automation for irrigating my garden. When the level of a soil moisture sensor gets too low, it’s supposed to open a valve for 30 min then close it. Here is the YAML:

alias: Garden Irrigation
description: ""
triggers:
  - type: humidity
    device_id: 2e973d8f812a29b0c67148e21fe923d5
    entity_id: 996b089adb801311519d048501e555ed
    domain: sensor
    trigger: device
    below: 75
conditions: []
actions:
  - type: turn_on
    device_id: 403255d471db7a0291c49472312c738b
    entity_id: e00e2b8696609b936d2421c77c973acf
    domain: switch
  - action: notify.mobile_app_pixel_9_pro_xl
    metadata: {}
    data:
      message: Garden irrigation start
  - action: assist_satellite.announce
    metadata: {}
    data:
      message: Garden irrigation start
  - delay:
      hours: 0
      minutes: 30
      seconds: 0
      milliseconds: 0
  - type: turn_off
    device_id: 403255d471db7a0291c49472312c738b
    entity_id: e00e2b8696609b936d2421c77c973acf
    domain: switch
mode: single

So this triggered yesterday morning, and I went out this morning and the irrigation was still running. I checked the switch for that relay on the card, and it was still in the on position.

So then I looked at the logs. There was an event for when the relay was turned on by the automation, but there was no event for it being turned off 30 min later. Have I done something wrong with the configuration?

For timed action I use trigger ids

That allows you to have trigger for humidity and second trigger for when switch has been ON for xx min

You would then have action for ON and OFF determined by trigger ID.

This is safer than “wait” since it survives HA reboots and automation restarts

Use trace to determine why it’s not turning on. Could be wrong trigger or could be your device not available.

Actually you need a condition for if it’s been ON in last xx minutes to prevent a constant ON triggering.

I never use delays or waits longer than 5 minutes for almost anything. and if it’s critical I don’t use delays at all. I use a datetime trigger.

have your first automation set a datetime helper when the valve is turned on and then when the desired time has expired (datetime helper + 30 minutes in your case) trigger an automation to close the valve.

also for something like this that can cause serious negative consequences (flooding) you should also have a notification to tell you if the valve has been on longer than expected.

Hello dryheat122,

So while it is possible to wait long periods of time in a wait or delay, it is generally not recommended. This is because HA restarts and many other possible things can happen which interrupt this 'wait’ and then it hangs as you describe.

The suggested method is have a trigger or an automation for turning it on, and another trigger or another automation for turning it off.