Help with Repeat Until automation?

Hopefully someone can help me work out where I’m going wrong.

I have an automation that when I turn on the outlet for my fan, it would wait for an hour, see if the temperature is below a set value, and if so it would turn off. However I can see in traces that the following error occurs:

Stopped because only a single execution is allowed

I’m thinking this might be down to the mode in the automation being single but I’m not sure what this should be set to, or if i’m going wrong elsewhere.

Some of the names are a bit odd I know. These were devices I added very early on. I also repurpose the outlet for some christmas lights later in the year, hence the condition.

alias: Auto Off Fan
description: ""
trigger:
  - platform: device
    type: turned_on
    device_id: d8918c0564cab0724fc6c519abcb9637
    entity_id: switch.bedside_lights
    domain: switch
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: state
    entity_id: input_select.is_it_christmas
    state: No 😞
action:
  - repeat:
      sequence:
        - delay:
            hours: 1
            minutes: 0
            seconds: 0
            milliseconds: 0
        - if:
            - condition: numeric_state
              entity_id: sensor.bedroom_temperature_sensor_temperature
              below: 23
          then:
            - type: turn_off
              device_id: d8918c0564cab0724fc6c519abcb9637
              entity_id: switch.bedside_lights
              domain: switch
      until:
        - condition: device
          type: is_off
          device_id: d8918c0564cab0724fc6c519abcb9637
          entity_id: 0a7c0d7d6466aa165d39fce8bf867c99
          domain: switch
mode: single

This is definitely what it is.

Why the loop is stopped when the automation re-triggers is (as far as I am concerned) a bug. The second trigger should just be ignored and the loop should continue if the automation is in single mode.

However having said that your automation is not the way to do it.

You should not be waiting in an automation for hours.

Turn the light on with one automation that triggers on your switch turning on.

Turn the light off with another automation that triggers on your bedroom temperature (numeric state trigger) falling below 23, or (state trigger) your switch turning off. So two triggers.

Also you would be wise to stop using device ids. See: Why and how to avoid device_ids in automations and scripts

Thanks for the feedback.

The main thing I’m trying to achieve is for the fan to have a timer, so it will turn off after an hour, but only if the temperature is below a set value (thinking of making this a variable with a helper). So then if it is above that value, it will stay on until the temperature drops.

Good point about using entity ID instead. I’ll look at switching that out too

You can still do this without waiting in the automation.

Turn on automation: as before.

Turn off automation:

trigger:
temp below 23 (numeric state trigger)
switch on for 1 hr (state trigger with ‘for’ time)

condition:
temp below 23 (numeric state condition)
switch on for 1 hr (state condition with ‘for’ time)

Ah, yes I see… I was thinking about the trigger only happening if the temp falls below rather than is below. The hour duration would solve that.

Forgive my ignorance, is there a need to have the condition, if it is the same as the trigger?

Yes, you need both conditions.

If the temperature drops below 23° (1st trigger) before the 1 hour is up you don’t want it turning off. The switch time condition will prevent this.

Also after the switch being on for 1 hour (2nd trigger) if the temperature is not below 23° you don’t want it turning off. The temperature condition will prevent this.

1 Like

Great. I’ll give this a try. Thanks for your help

Is this the sort of thing you mean? I was wondering if it should be the switch is on for an our as the trigger, and the condition as temperature. Rather than both as temperature?

alias: Auto Fan Off v2
description: ""
trigger:
  - platform: numeric_state
    entity_id:
      - sensor.bedroom_temperature_sensor_temperature
    below: input_number.bedroom_desired_temperature
    for:
      hours: 1
      minutes: 0
      seconds: 0
condition:
  - condition: state
    entity_id: sensor.bedroom_temperature_sensor_temperature
    for:
      hours: 1
      minutes: 0
      seconds: 0
    state: ""
action:
  - service: switch.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: switch.tp_switch
mode: single

What about using a climate entity?
This way you can set your target temperature and when the temperature is reached the climate will turn off the switch.
And to make sure the fan does not start again, the automation switch off the climate entity.

To restart it again you just start the climate entity.

Configuration.yaml

climate:
  - platform: generic_thermostat
    name: Bedroom
    unique_id: bedroom
    ac_mode: true
    heater: switch.tp_switch
    target_sensor: sensor.bedroom_temperature_sensor_temperature
    min_temp: 18
    max_temp: 27
    target_temp: 23
    min_cycle_duration:
      minutes: 60

Automation

alias: Thermostat off
description: ""
trigger:
  - platform: state
    entity_id: switch.tp_switch
    to: off
condition: []
action:
  - service: climate.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: climate.bedroom
mode: single

No you need both as triggers and both as conditions, like I wrote. If this is what you want: