Automation stopped working - trace says "Stopped because only a single execution is allowed"

I have an automation that stopped functioning lately. The trace states “Stopped because only a single execution is allowed.” No changes were made to the automation. I assume the issue is with the wait_for_trigger which I found/hobbled together from other automations here on the forum. The idea of the wait_for_trigger is to have the shades reopen once the sun’s elevation is high enough to not blind my eyes while sitting here at my desk. Any advice to resolve this?

- id: '22028368334373038'
  alias: entry blinds blinding sun so close the shade
  trigger:
  - platform: time
    at: 08:30:00
  - platform: time
    at: 08:45:00
  - platform: time
    at: 09:00:00
  - platform: time
    at: 09:15:00
  - platform: time
    at: 09:30:00
  - platform: time
    at: 09:45:00
  - platform: time
    at: '10:00:00'
  condition:
  - condition: and
    conditions:
    - condition: numeric_state
      entity_id: sun.sun
      attribute: azimuth
      above: '120'
      below: '137'
    - condition: numeric_state
      entity_id: sun.sun
      attribute: elevation
      below: '29'
      above: '10'
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
    - condition: numeric_state
      entity_id: sensor.lightlevel_entryway
      above: 60
  action:
  - service: scene.turn_on
    target:
      entity_id: scene.closedentry
  - wait_for_trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: '30'
    continue_on_timeout: false
  - service: scene.turn_on
    target:
      entity_id: scene.daytimeentry

Don’t you use the mode of the automation?
I mean, I did not read and understand your automation thoroughly, sorry, I’m giving a hint (that might be not appropriate, sorry again)
Mode is described here, maybe you should select one or another?

2 Likes

I assumed that single, which it defaults to if not defined, is the accurate need here. Maybe I’m still too ignorant with this stuff?

1 Like

If you need single, it is perfectly fine.
But then, if the automation is triggered again while the previous execution is still waiting on one of the actions, like the wait_for_trigger, you’ll get the exception you described “Stopped because only a single execution is allowed.”

I’m always confused by the continue_on_timeout set to false because it is meant to abort the script but on the other hand, if true what does that mean? Execute the remaining actions?

I believe also that reaching 30 as elevation could take more or less time depending on the season and where you live. Might be the reason why the automation is triggered while the previous occurrence is still running?

The question is “Is it possible that waiting for the elevation to get to 30 is taking more than the 15 minutes before your next time platform trigger?”

Looking at your actions, I feel like restart should be fine, hear me out:

  - service: scene.turn_on
    target:
      entity_id: scene.closedentry

If it was done by the previous run, it should be fine to do it again, right (if your scene doesn’t include toggle service call)?

  - wait_for_trigger:
    - platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: '30'
    continue_on_timeout: false

Interrupting that one, if it was hanging in the previous run, is not important as this new run will restart and continue the waiting time.

 - service: scene.turn_on
    target:
      entity_id: scene.daytimeentry

This one will be executed, one day or another by one of the triggered instances (and if the elevation reach 30).

Why does the automation trigger at specific times instead of triggering based on the sun’s elevation and azimuth?

@Olivier1974 I think restart makes sense from what you describe.

@123 my ignorance. I tried to do that but it wasn’t working with two items as triggers. How best should I do that?

When you put more than one trigger, the automation starts if any of the trigger condition is met. See it as an or, not an and

Not sure about your exact requirements but this should give you an idea of how to structure it without relying on wait_for_trigger or the mode.

- id: '22028368334373038'
  alias: entry blinds blinding sun so close the shade
  trigger:
    - id: 'closedentry'
      platform: template 
      value_template: >
        {% set a = state_attr('sun.sun', 'azimuth') | int(0) %}
        {% set e = state_attr('sun.sun', 'elevation') | int(0) %}
        {% set l = states('sensor.lightlevel_entryway') | int(0) %}
        {{ 120 < a < 137 and 10 < e < 29 and l > 60 }}
    - id: 'daytimeentry'
      platform: numeric_state
      entity_id: sun.sun
      attribute: elevation
      above: '30'
  condition:
    - condition: time
      weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
  action:
    - service: scene.turn_on
      target:
        entity_id: 'scene.{{ trigger.id }}'
1 Like

Thank you both. I’ll play with it over the weekend and come back w/ any questions or to mark solutions, etc.

The solution of Taras is the best as it is replacing multiple events by one.
But template triggers is not always easy for beginners, don’t know your level in coding (btw, if you are wondering, this is Jinja2 language) and you can always test your code in

Developer Tools > Template

I have same situation, but i cannot see why this stops. I have carshelter lights on/off based on sun, and then i made this another automation to check motion and brighten carshelter lights for 2 minutes.

alias: CarShelter Brightness change
description: Change brightness when motion detetcted at night
triggers:
  - trigger: state
    entity_id:
      - select.autokatos_motion_detection
conditions:
  - condition: state
    entity_id: light.carshelter
    state: "on"
    enabled: false
  - condition: and
    conditions:
      - condition: device
        type: is_on
        device_id: 4b95cd43e600497cad970f5a92700d30
        entity_id: 7848b64cbdf32c8be41a42fd098341f9
        domain: light
actions:
  - action: light.turn_on
    metadata: {}
    data:
      brightness_step_pct: 50
    target:
      entity_id: light.carshelter
  - delay:
      hours: 0
      minutes: 2
      seconds: 0
      milliseconds: 0
  - action: light.turn_on
    metadata: {}
    data:
      brightness_pct: 1
    target:
      entity_id: light.carshelter
mode: single

You really should have created a new thread instead of replying to a 2 year old thread, but anyway.

You’re getting the error because you’re triggering on every state change of your motion detector, but your automation has a delay of 2 minutes.

Chances are, your motion detector is going back to not detecting motion before those 2 minutes are over.
This causes the automation to retrigger while it’s running

1 Like

Also you are using the and condition the wrong way. All things you want to and need to be inside it. But you do not need it here anyway. Multiple conditions are and by default.

Yeah, there is only one condition, another one is not enabled. I was just testing around so i left it disabled there.

What i understood, conditions are not AND by default, but OR, if one condition is fullfilled, it will continue. Here i have selected AND condition from the pull down(not the default one). I know, its not needed here because there is only one condition, but i was testing out.

Now, how can i get this working then, i presume i need some sort of counter that reset everytime movement is detected and keeps the light litted ?

No.
Triggers are OR by default (and cannot be changed to AND)
Conditions are AND by default (but can be changed to OR)

Under the conditions block, there’s a list of conditions. If one succeeds, it will proceed… to test the next condition. If it fails, the whole automation stops and nothing below is evaluated.

So you only need an and condition if you are inside an or condition.

And the other thing I meant, an and or an or condition applies to all the conditions in it. An and or or is not placed between conditions, but above them, with all the conditions that are anded or orred below, indented more. So in pseudocode: A and (B or C and D) is written as:

conditions:
  - condition: A
  - condition: or
    conditions:
      - condition: B
      - condition: and
        conditions:
          - condition: C
          - condition: D
1 Like

Confusing, as i can still select AND condition from building blocks menu, why, if its default anyways ?

See the code in Edwin’s last reply and you’ll see why AND is still shown.

Everything is also explained in the docs. I strongly suggest you give them a good read

1 Like