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

I finally found it

{
  "trace": {
    "last_step": "condition/0",
    "run_id": "131303b0f4fcc18e615d2365315fa00d",
    "state": "stopped",
    "script_execution": "failed_conditions",
    "timestamp": {
      "start": "2025-04-26T05:05:00.235275+00:00",
      "finish": "2025-04-26T05:05:00.235739+00:00"
    },
    "domain": "automation",
    "item_id": "1745642984249",
    "trigger": "time",
    "trace": {
      "trigger/1": [
        {
          "path": "trigger/1",
          "timestamp": "2025-04-26T05:05:00.235492+00:00",
          "changed_variables": {
            "this": {
              "entity_id": "automation.ac_cooling_test_2",
              "state": "on",
              "attributes": {
                "id": "1745642984249",
                "last_triggered": "2025-04-26T05:00:00.398496+00:00",
                "mode": "single",
                "current": 0,
                "friendly_name": "AC Cooling Test"
              },
              "last_changed": "2025-04-26T04:50:17.678045+00:00",
              "last_reported": "2025-04-26T05:00:00.750461+00:00",
              "last_updated": "2025-04-26T05:00:00.750461+00:00",
              "context": {
                "id": "01JSR7EYGDBNMM2Q2000KSGVQY",
                "parent_id": null,
                "user_id": null
              }
            },
            "trigger": {
              "id": "1",
              "idx": "1",
              "alias": null,
              "platform": "time",
              "now": "2025-04-26T15:05:00.234635+10:00",
              "description": "time",
              "entity_id": null
            }
          }
        }
      ],
      "condition/0": [
        {
          "path": "condition/0",
          "timestamp": "2025-04-26T05:05:00.235592+00:00",
          "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
          }
        }
      ]
    },
    "config": {
      "id": "1745642984249",
      "alias": "AC Cooling Test",
      "description": "Cooling Test",
      "triggers": [
        {
          "trigger": "time",
          "at": "15:00:00"
        },
        {
          "trigger": "time",
          "at": "15:05: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": 20
        },
        {
          "trigger": "numeric_state",
          "entity_id": [
            "sensor.viewbank_temp"
          ],
          "above": 17
        },
        {
          "trigger": "homeassistant",
          "event": "start"
        }
      ],
      "conditions": [
        {
          "condition": "time",
          "after": "15:00:00",
          "before": "15:05:00"
        },
        {
          "condition": "numeric_state",
          "entity_id": "sensor.viewbank_temp",
          "above": 17
        },
        {
          "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": 20
            }
          ]
        }
      ],
      "actions": [
        {
          "if": [
            {
              "condition": "time",
              "after": "15:00:00",
              "before": "15:05: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"
    },
    "blueprint_inputs": null,
    "context": {
      "id": "01JSR7R3AB92JXCGVT80Q5VZ4P",
      "parent_id": null,
      "user_id": null
    }
  },
  "logbookEntries": []
}

That’s the 05:00 trace.
But the issue is the temperature conditions.
It requires it to be hot for the AC to turn off.

Move all the temperature conditions from the “main” conditions and place them in the “if-then-else” condition.

Thanks that was my problem.
Moving all of the conditions to the if-then-else condition solved the problem of the AC system not turning off.

I also found that I needed to put them all into an ‘and’ condition to make sure the automation for AC cooling didn’t turn off the system when a heating automation was running with an overlapping time period.

Now it all seems to be working as expected.

This is my fully working AC Cooling automation:

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:01: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: []
actions:
  - if:
      - condition: and
        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
    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

The and is not needed.
All conditions unless specified with an or is by default and.

You’re welcome but then why did you remove the Solution tag from my post and then add it to your own post?

If you subsequently amended your original requirements, that doesn’t invalidate my answer to your original requirements.

The main principle demonstrated in my answer (creating complimentary pairs of triggers and conditions) is what’s responsible for solving the original problem (and you used the technique in your final example).

1 Like

He had multiple triggers in the first post also.
And most of the conditions also.
The only part that was a real issue was the action code.

Compare it to the example I posted and you’ll see a dramatic difference. His version doesn’t even come close to implementing complimentary pairs of triggers and conditions.

I’m sorry, I didn’t mean to offend anyone.
This is my first time posting to a forum like this.

My thought was that the ‘solution’ post would be the final version that works.
But I do take your point that your post solved my initial question and I added additional parameters after that.

Thanks again for all your help.

1 Like

No worries. No offence was taken. I was merely curious to know why the solution to the original problem was, a week later, no longer considered to be the solution.