Automation needs to periodically check if conditions are met during time period

I am new to Home Assistant but I’ve been pleasantly surprised at how easy at has been to get all of my devices set up and automated.
I have a Home Assistant Green with OS version 15.2, Core 2025.4.3.

I have created many automations, scripts and scenes for various devices but I am stuck trying to automate my air conditioning system.

I have created automations for both heating and cooling that have start and end times and with conditions for the current temperature outside and inside to be met. I can make that part work.

The problem I have is where the conditions are not met at the start time, I need the automation to keep checking those conditions periodically so that the AC turns on when they are met.

I have searched the forum and google many times but I have struggled to find an answer that seemed relevant or that I could understand. At one point I found a reference to a Repeat Until variable that I have added to my automation but it doesn’t seem to have had any effect. Maybe I’m not using it correctly.

My preference is to use the UI to set up the automations and my understanding of YAML is close to zero, so that is also making it hard to find an answer I think.
This is my Automation for Cooling so far:

alias: AC Cooling
description: Turn on AC Cooling if Temp above 24
triggers:
  - event: start
    trigger: homeassistant
  - at: "12:00:00"
    trigger: time
  - at: "23:00:00"
    trigger: time
conditions:
  - type: is_temperature
    condition: device
    device_id: 4cfa8550e4cfad042f89d45a354147c1
    entity_id: b54ce541d02b7746d314f21b1cf303d4
    domain: sensor
    above: 26
  - condition: and
    conditions:
      - type: is_temperature
        condition: device
        device_id: 4cfa8550e4cfad042f89d45a354147c1
        entity_id: b54ce541d02b7746d314f21b1cf303d4
        domain: sensor
        above: 26
      - condition: or
        conditions:
          - condition: numeric_state
            entity_id: climate.ac_living_kitch
            above: 24.8
            attribute: current_temperature
          - condition: numeric_state
            entity_id: climate.ac_wayne_s_bed
            above: 24.8
            attribute: current_temperature
actions:
  - repeat:
      sequence:
        - choose:
            - conditions:
                - condition: time
                  after: "12:00:00"
                  before: "23:00:00"
              sequence:
                - action: scene.turn_on
                  metadata: {}
                  data: {}
                  target:
                    entity_id: scene.ac_cooling_default
          default:
            - device_id: 3f0c27a4da710809b6d2b5416976f33d
              domain: climate
              entity_id: 89ffbea87e57c381734e9568a6c5113b
              type: set_hvac_mode
              hvac_mode: "off"
      until:
        - condition: and
          conditions:
            - type: is_temperature
              condition: device
              device_id: 4cfa8550e4cfad042f89d45a354147c1
              entity_id: b54ce541d02b7746d314f21b1cf303d4
              domain: sensor
              above: 26
            - condition: or
              conditions:
                - condition: numeric_state
                  entity_id: climate.ac_living_kitch
                  above: 24.8
                  attribute: current_temperature
                - condition: numeric_state
                  entity_id: climate.ac_wayne_s_bed
                  above: 24.8
                  attribute: current_temperature
mode: single

To summarise what I’m trying to achieve:

Start time: 12:00
End Time: 23:00
If outside temperature is above 26
and either
climate.ac_living_kitch is above 24.8
climate.ac_wayne_s_bed is above 24.8
Then
Turn on Scene scene.ac_cooling_default

My current attempts result in either the cooling mode being activated at the start time if the conditions are met or else it never activates.

I’d really appreciate any help that can be offered. Thanks.

This looks massively over overcomplicated.

You just need to trigger on time and on temperature.
Then condition is also time and temperature.
That’s it.
No nesting or repeats.

Then set up a other to turn it off with the same principle

2 Likes

Hello Wayne,

So 2 suggestions…

Using device_id stuff can complicate your life long term. If a device fails and you need to replace it for instance. See: Why and how to avoid device_ids in automations and scripts

Also running Automatons for long periods of time, if there is an interruption for instance HA restarts or whatever, the Automation ends and doesn’t restart. The recommendation is to trigger the automation when things happen then let it end, then have another trigger or another automation when the next thing happens. Trying to run the automation to monitor some long term thing is prone to error because of this.
So for your specific question I rec adjust things so it acts on the triggered events as they occur.

Thanks for your reply. Your suggestions do make a lot of sense.
I agree what I had was overly complicated.

I’ve tried to come at it from a different direction, so the indoor temperature should be the primary trigger. This is what I’ve set up:

alias: AC Cooling Test
description: ""
triggers:
  - trigger: numeric_state
    entity_id:
      - climate.ac_living_kitch
    attribute: current_temperature
    above: 24.8
  - trigger: numeric_state
    entity_id:
      - climate.ac_wayne_s_bed
    attribute: current_temperature
    above: 24.8
conditions:
  - condition: and
    conditions:
      - condition: time
        after: "12:00:00"
        before: "23:00:00"
      - condition: numeric_state
        entity_id: sensor.viewbank_temp
        above: 26
actions:
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.ac_cooling_default
mode: single

With 2 triggers, (climate.ac_living_kitch) and (climate.ac_wayne_s_bed), would it activate if either of them are above 24.8 or only if both are?

With these kinds of automations it’s normally a good idea to have all conditions as triggers and all triggers as conditions. Thus, add one time trigger for 12:00 too, so that when 12:00 strikes and all other conditions are already met, then it will turn on.

It depends on whether you and or or them together. I’d rather make two automations, or make a blueprint if the automations are identical. Otherwise, you’ll need to have logic in your actions to see which ACs have met the conditions, leading to duplicated logic (what you already have in your conditions), with an additional check for which entity it’s true.

Although I’m posting YAML, I’m creating/editing my automations with the UI. I don’t know how to edit YAML correctly and I don’t see a way in the UI to insert and/or into the triggers.

Regardless of that, I’ve done some testing and the automation activates if either of the climate.ac triggers hit 24.8.
If I add a time trigger at 12:00 then nothing happens when they reach temperature.

So I’m thinking that I should create a secondary automation to trigger this one at 12:00 just to check if the temperature has already been reached at that time.

It should.
But it will only trigger when it’s 12:00:00, so if this has already passed then it won’t trigger.
All the suggestions above is good.
But there is one that is kind of left hanging.
Your outside temperature is listed as a condition only, it should be a trigger also.

1 Like
alias: AC Cooling Test
description: ""
triggers:
  - trigger: time 
    at: '12:00:00'
  - trigger: numeric_state
    entity_id:
      - climate.ac_living_kitch
    attribute: current_temperature
    above: 24.8
  - trigger: numeric_state
    entity_id:
      - climate.ac_wayne_s_bed
    attribute: current_temperature
    above: 24.8
  - trigger: numeric_state
    entity_id:
      - sensor.viewbank_temp
    above: 26
conditions:
  - condition: time
    after: "12:00:00"
    before: "23:00:00"
  - condition: numeric_state
    entity_id: sensor.viewbank_temp
    above: 26
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: climate.ac_living_kitch
        attribute: current_temperature
        above: 24.8
      - condition: numeric_state
        entity_id: climate.ac_wayne_s_bed
        attribute: current_temperature
        above: 24.8
actions:
  - action: scene.turn_on
    metadata: {}
    data: {}
    target:
      entity_id: scene.ac_cooling_default
mode: single
1 Like

You’ve been unintentionally misled.

all triggers are always ‘or’. UI or yaml makes no difference.

conditions can be either.

Thanks 123 Taras for spelling it out for me.

I’ve done some testing of this and so far it’s working exactly as I wanted. Much simpler than how I originally had it.

Thank you to everyone who helped to point me in the right direction.

One thing I’m still not entirely clear on is why all the variables should be triggers as well as conditions?

2 Likes

Because each of the triggers can happen, but you need to ensure that everything is as it should for the AC to turn on.
The temperature could go up during the night but then the time condition stops it from activating.

Make a binary sensor and then trigger of that.

Pros:

  • You only need one set of conditions
  • You see the overall state at any time
  • The condition will be more straightforward to write
  • Triggering on “condition is true for X minutes” is possible easily

Cons:

  • No GUI, you need to write it in template language

Remember, a trigger is a moment in time, so e.g. when the time comes (12:00), you want to check in the conditions whether the temperature is as required. But, if you trigger on temperature, you want to ensure the time condition holds true as well. Put differently: you want your conditions to all pass, whatever the trigger.

Thanks I think I understand now.

I added an if/then/else condition to the action of the automation so that at the end time the system would be switched off.
But without an 11:00pm trigger there was nothing to make sure the condition got checked at that time, so it didn’t turn off.

I’ve added that trigger now too.

alias: AC Cooling - Afternoon/Evening
description: Cooling if outside temp >26 and any zone >24.8 between 12:00 and 23:00
triggers:
  - trigger: time
    at: "12:00:00"
  - trigger: time
    at: "23:00:00"
  - trigger: numeric_state
    entity_id:
      - climate.ac_living_kitch
    attribute: current_temperature
    above: 24.8
  - trigger: numeric_state
    entity_id:
      - climate.ac_wayne_s_bed
    attribute: current_temperature
    above: 24.8
  - trigger: numeric_state
    entity_id:
      - sensor.viewbank_temp
    above: 26
  - trigger: homeassistant
    event: start
conditions:
  - condition: time
    after: "12:00:00"
    before: "23:00:00"
  - condition: numeric_state
    entity_id: sensor.viewbank_temp
    above: 26
  - condition: or
    conditions:
      - condition: numeric_state
        entity_id: climate.ac_living_kitch
        attribute: current_temperature
        above: 24.8
      - condition: numeric_state
        entity_id: climate.ac_wayne_s_bed
        attribute: current_temperature
        above: 24.8
actions:
  - if:
      - condition: time
        after: "12:00:00"
        before: "23:00:00"
    then:
      - action: scene.turn_on
        metadata: {}
        data: {}
        target:
          entity_id: scene.ac_cooling_default
    else:
      - action: climate.set_hvac_mode
        metadata: {}
        data:
          hvac_mode: "off"
        target:
          entity_id: climate.ac
mode: single

I think you should change your time trigger to 22:59, just to be sure

Thanks for your suggestion, but I’m not having much luck.

I’ve tried setting the end time trigger to 23:00, 22:59 and 23:01 and the AC system doesn’t turn off for any of them.
I’ve tried moving the 23:00 trigger to be the last trigger in the list with no improvement.
If I run the automation manually after the end time the AC system turns off, so it would seem to be a failure to trigger at the end time.

I have automations for switches that use the same if/then/else action but don’t have any conditions/triggers other than start/end times and these work perfectly.

I can’t figure out why this isn’t working.

Is there a trace available for ~23:00? If so, provide it here (you can download a JSON file of the full trace).

I created a version of the automation to run at different times for testing.
I found the trace in the UI but I don’t know how to find the JSON file.

I set the automation to run from 3:00pm to 3:05pm:

Executed: April 26, 2025 at 3:05:00 PM
Result:
after:
__type: <class ‘datetime.time’>
isoformat: ‘15:00:00’
now_time:
__type: <class ‘datetime.time’>
isoformat: ‘15:05:00.235635’
before:
__type: <class ‘datetime.time’>
isoformat: ‘15:05:00’
result: false

Triggered by the time at April 26, 2025 at 3:05:00 PM

Test If the time is after 3:00 PM and before 3:05 PM

Stopped because a condition failed at April 26, 2025 at 3:05:00 PM (runtime: 0.00 seconds)