Delay Cancelled without next step

hi, i have a big problem with automation and delay. The delay did not happen to me several times and let the automation run without another step. In the “trace timeline” it will show me the delay “Canceled”. Sometimes this is done fine, but there is a problem if the irrigation runs instead of 25 minutes for a total of 3 hours.

Please help

- id: '1619296190021'
  alias: Zavlažování
  description: ''
  trigger:
  - platform: sun
    event: sunrise
    offset: -01:30:00
  condition:
  - condition: template
    value_template: '{{states.sensor.vlhkost_pudy.state <= ''35'' }}'
  - condition: state
    entity_id: sensor.rainy_day
    state: Ne
  - type: is_value
    condition: device
    device_id: fefbafb2444d6ee64d4986fe51ddb1c1
    entity_id: sensor.water_tank_volume
    domain: sensor
    above: 1000
    below: 7100
  action:
  - type: turn_on
    device_id: 94421a54b6f1f392f151eff2b67f4681
    entity_id: switch.zavlaha_1
    domain: switch
  - wait_template: ''
    continue_on_timeout: true
    timeout: 00:25:00
  - type: turn_off
    device_id: 94421a54b6f1f392f151eff2b67f4681
    entity_id: switch.zavlaha_1
    domain: switch
  - type: turn_on
    device_id: 94421a54b6f1f392f151eff2b67f4681
    entity_id: switch.zavlaha_2
    domain: switch
  - wait_template: ''
    continue_on_timeout: true
    timeout: 00:10:00
  - type: turn_off
    device_id: 94421a54b6f1f392f151eff2b67f4681
    entity_id: switch.zavlaha_2
    domain: switch
  - type: turn_on
    device_id: 94421a54b6f1f392f151eff2b67f4681
    entity_id: switch.zavlaha_4
    domain: switch
  - wait_template: ''
    continue_on_timeout: true
    timeout: 00:15:00
  - type: turn_off
    device_id: 94421a54b6f1f392f151eff2b67f4681
    entity_id: switch.zavlaha_4
    domain: switch
  mode: single

Rather than using wait_template with a blank template to introduce a delay you may be better off using delay

Because automations stop running when you restart HA or reload automations (this includes editing them from the UI!) I would use a timer or store the time.

Timer is in my opinion the easiest but only is resilient to reloading of the automations. A timer is stopped if HA is restarted.

So for something critical as this I would store the time (and date, to cover midnight) (into a input_datetime) when I turned it on. Then have a second automation that triggers when the time has passed ([start_time] + [run_time} >= now()). And to handle the situation that HA is just restarting when they should turn off, add HA start as trigger and add the time check as trigger and condition.

I have a similar problem when starting recuperation. But I have a delay everywhere. The strange thing is that if it fails, it’s always on the 99s runtime.
Both devices work on ESPhome, recuperation and watering.



- id: '1545648219485'
  alias: Rekuperace - automatické zapínání v čase
  trigger:
  - at: 03:00
    platform: time
  - at: 06:00
    platform: time
  - at: 09:00
    platform: time
  - at: '13:00'
    platform: time
  - at: '16:30'
    platform: time
  - at: '20:00'
    platform: time
  - at: '23:30'
    platform: time
  condition: []
  action:
  - service: light.turn_on
    data:
      brightness: 100
    target:
      entity_id:
      - light.rekuperace
      - light.rekuperace_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - service: light.turn_on
    data:
      brightness: 150
    target:
      entity_id:
      - light.rekuperace
      - light.rekuperace_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - service: light.turn_on
    data:
      brightness: 180
    target:
      entity_id:
      - light.rekuperace
      - light.rekuperace_2
  - delay:
      hours: 0
      minutes: 0
      seconds: 15
      milliseconds: 0
  - service: light.turn_on
    data:
      brightness: 210
    target:
      entity_id:
      - light.rekuperace
      - light.rekuperace_2
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: light.turn_on
    data:
      brightness: 130
    target:
      entity_id:
      - light.rekuperace
      - light.rekuperace_2
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: light.turn_on
    data:
      brightness: 30
    target:
      entity_id:
      - light.rekuperace
      - light.rekuperace_2
  - choose:
    - conditions:
      - condition: numeric_state
        entity_id: sensor.ble_temperature_bed_room
        attribute: median
        below: '24'
      sequence:
      - service: light.turn_on
        data:
          brightness: 0
        target:
          entity_id:
          - light.rekuperace
          - light.rekuperace_2
    default: []
  mode: single

Ok, something wrong with my automation. Almost every five minutes, all automations restart for me. Sometimes not, mostly yes. Is it possible to trace what causes this?

Well, the problem is probably in this automation, the time corresponds to the automation restart time. I changed the code, removed “none”, restarted the device, reloaded the updates, but it still shows the same error, “none” simply no longer exists in automation!
Some idea?

What does the configuration checker tell you?

Hello,
I tried to change all those automations that have a state of None, but that didn’t help. In the end, it was probably because one of those automations was completely inoperable. I completely restored the backup from the days when it was fine and now it seems ok.
But it’s weird that it wrote the mistake, even though she wasn’t there physically.

Hi,

I have the same problem in several of my automations, i.e. the delay is canceled and the automation stops there silently. No error logged, nothing.

I’m thinking of opening an issue on github unless someone has a better idea of what might be causing this.

All automations were running well at least a couple of core versions back.

1 Like

You’re doing something wrong. You have to figure out what it is. This is only happening to you and OP and OP figured out that it was a mistake he made.

Typically if a delay is canceled, your automation restarted (I.E. triggered again) and your mode is set to restart. Or in OPs case, the automations were partially loaded due to an error in his configuration.

If only that was it, it would be so nice, it would be so easy to fix.

Halas the automation is only triggered by time, runs every day at 6:35 AM, so unless Marty and Doc Brown are up to something, I really can’t see how this automation can trigger again while running.

Any other ideas?

No because the amount of information you’ve given is “something changed, but I don’t know what”. Help me help you, post your automations, post your logs, post what you have done.

I’ve got some good news.

I saw there was a new core version available (core-2021.5.2), so as a preparation for creating a bug report I installed it and re-ran the automation in question.

Manually calling the automation it went fine, Finished at May 11, 2021, 2:08:26 PM (runtime: 4503.12 seconds), so unless there is something specific about the time of day when it runs alone triggered by time, whatever was the problem seems to have been fixed in this last core version.

As to “something changed”, well it wasn’t on my side, the automation was the same all the time, and suddenly it stopped working, so most probably some bug in the recent core code, who knows.

If I don’t come here tomorrow you can assume it ran well in the morning, if again it gets cancelled instead I will return here to post more details… not that there is much to post anyhow… run zwave command, wait 5 minutes, run another zwave command, wait 5 minutes and so on for 1h15.

Let’s wait and see how it goes tomorrow.
Thanks for your interest.

Doubt that… Not seen the code of the automation nor a trace log so that would be a good start :slight_smile:

Automation ran fine today, so whatever it was, it was solved by the new core version.

Case closed.

Thanks Tom for the hint, does this still hold for the current version? I run the latest HA version and wondered, why the f*ck my delays are cancelled. Until I read you hint.

To be honest, I would expect a totally different behaviour.

I had an automation move past a 3-hour delay in 1 second this evening. It’s been working for a couple weeks prior. HAOS 2021.12.9.

Sorry to hijack this thread (I know this one is about the next step not running). In my case, the next step runs, but after only 1 second, rather than waiting 3 hours as expected. The system was not restarted during that time.

alias: Front of house evenings
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '0'
condition: []
action:
  - scene: scene.front_of_house_on
  - delay:
      hours: 3
      minutes: 0
      seconds: 0
      milliseconds: 0
  - scene: scene.front_of_house_off
mode: single

Here’s the trace

{
  "trace": {
    "last_step": "action/1",
    "run_id": "ddd0b9a55e27baf363e5c6f59ade8925",
    "state": "running",
    "script_execution": null,
    "timestamp": {
      "start": "2022-02-03T01:24:01.243921+00:00",
      "finish": null
    },
    "domain": "automation",
    "item_id": "1642215159370",
    "trigger": "sunset",
    "trace": {
      "trigger/0": [
        {
          "path": "trigger/0",
          "timestamp": "2022-02-03T01:24:01.244090+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.front_of_house_on_evenings",
              "state": "on",
              "attributes": {
                "last_triggered": "2022-02-02T01:23:04.361797+00:00",
                "mode": "single",
                "current": 0,
                "id": "1642215159370",
                "friendly_name": "Front of house evenings"
              },
              "last_changed": "2022-02-02T19:02:19.967001+00:00",
              "last_updated": "2022-02-02T19:02:19.967001+00:00",
              "context": {
                "id": "e226c0b04619032cb28086239fea502b",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "0",
              "idx": "0",
              "platform": "sun",
              "event": "sunset",
              "offset": {
                "__type": "<class 'datetime.timedelta'>",
                "total_seconds": 0
              },
              "description": "sunset"
            }
          }
        }
      ],
      "action/0": [
        {
          "path": "action/0",
          "timestamp": "2022-02-03T01:24:01.245913+00:00",
          "changed_variables": {
            "context": {
              "id": "c8707539441570e4874511135f62fbfa",
              "parent_id": null,
              "user_id": null
            }
          },
          "result": {
            "scene": "scene.front_of_house_on"
          }
        }
      ],
      "action/1": [
        {
          "path": "action/1",
          "timestamp": "2022-02-03T01:24:01.322538+00:00",
          "result": {
            "delay": 10800,
            "done": false
          }
        }
      ]
    },
    "config": {
      "id": "1642215159370",
      "alias": "Front of house evenings",
      "description": "",
      "trigger": [
        {
          "platform": "sun",
          "event": "sunset",
          "offset": "0"
        }
      ],
      "condition": [],
      "action": [
        {
          "scene": "scene.front_of_house_on"
        },
        {
          "delay": {
            "hours": 3,
            "minutes": 0,
            "seconds": 0,
            "milliseconds": 0
          }
        },
        {
          "scene": "scene.front_of_house_off"
        }
      ],
      "mode": "single"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "c8707539441570e4874511135f62fbfa",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": [
    {
      "name": "Front of house evenings",
      "message": "has been triggered by sunset",
      "source": "sunset",
      "entity_id": "automation.front_of_house_on_evenings",
      "context_id": "c8707539441570e4874511135f62fbfa",
      "when": "2022-02-03T01:24:01.244458+00:00",
      "domain": "automation"
    },
    {
      "when": "2022-02-03T01:24:01.318991+00:00",
      "name": "Front Door light",
      "state": "on",
      "entity_id": "switch.in_wall_smart_switch",
      "context_entity_id": "automation.front_of_house_on_evenings",
      "context_entity_id_name": "Front of house evenings",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Front of house evenings",
      "message": "turned on"
    },
    {
      "when": "2022-02-03T01:24:02.429480+00:00",
      "name": "Front Door light",
      "state": "off",
      "entity_id": "switch.in_wall_smart_switch",
      "context_entity_id": "automation.front_of_house_on_evenings",
      "context_entity_id_name": "Front of house evenings",
      "context_event_type": "automation_triggered",
      "context_domain": "automation",
      "context_name": "Front of house evenings",
      "message": "turned off"
    }
  ]
}

That is just asking for problems.

Change the automation to something else instead because that is not a good way to do an automation.

You could add another trigger with sunset + 3 hours offset and use this as the “off”.
You could set a datetime to a timestamp three hours ahead and trigger on that.

You should be getting errors on those service calls because you have the field written as scene not service, this is what your automation should look like

alias: Front of house evenings
description: ''
trigger:
  - platform: sun
    event: sunset
    offset: '0'
condition: []
action:
  - service: scene.front_of_house_on
  - delay:
      hours: 3
      minutes: 0
      seconds: 0
      milliseconds: 0
  - service: scene.front_of_house_off
mode: single

Hi,

Does anyone have a solution to this cancelled delay timer? I have the same issues as you described. My automation is very simple – A switch is turned on at 6PM everyday, then after 2 hours delay, the switch is turned off. It worked just fine for long time, but recently, I realized it does not work reliably any more. e.g. in today’s run , the delay is cancelled and yesterday was just working fine, but the day before yesterday is not working. It is quite annoying that such a basic, simple function cannot work reliably, and even worse, the trace does not tell me why the delay is cancelled, nor any log entry… I come to think whether this should be classified as bug or not.

I am running HA core 2022.10.1 on HA O/S 9.0. and below is my automation:

Appreciate any help.