Run automation only when A/C is on

I am trying to make automation to run only when Samsung air conditioner (A/C) is on.

Specifically, I made an automation to check the temperature every 5 minutes between 08:30AM and 03:00AM, and depending on the temperature, A/C’s target temperature is set accordingly.

Sometimes, A/C is intentionally in OFF state (turned off by myself) between 08:30AM and 03:00AM. In such case, I do not want the automation to turn on the A/C. The automation below keeps on turning on A/C.

I tried “- condition: template” and “- condition: state” but the A/C is still turned on by automation…

For “- condition: state” , I chose “heat” because there is no “ON” as A/C has multiple “ON” states…No matter which state I choose for “- condition: state”, the automation would not stop turning on the A/C.

What am I missing?

alias: Lounge AC
description: ""
triggers:
  - trigger: time_pattern
    minutes: /5
conditions:
  - condition: and
    conditions:
      - condition: time
        after: "08:30:00"
        before: "03:00:00"
        weekday:
          - sun
          - mon
          - tue
          - wed
          - thu
          - fri
          - sat
      - condition: template
        value_template: "{{ states('climate.lounge_ac') != 'off' }}"
    enabled: true
actions:
  - choose:
      - conditions:
          - condition: numeric_state
            entity_id: sensor.lounge_sensor_2_temperature
            above: 25.4
        sequence:
          - action: climate.set_temperature
            metadata: {}
            target:
              entity_id: climate.lounge_ac
            data:
              hvac_mode: heat
              temperature: 22.5
      - conditions:
          - condition: numeric_state
            entity_id: sensor.lounge_sensor_2_temperature
            below: 25.1
        sequence:
          - action: climate.set_temperature
            metadata: {}
            target:
              entity_id: climate.lounge_ac
            data:
              temperature: 24
              hvac_mode: heat

What does the automation trace show?

Looks like the template condition is false…

template condition must be true to stop automation from turning on the A/C.

What is wrong with the template condition?

If 2 conditions match
Executed: January 26, 2026 at 2:55:00 AM
Result:
result: false
conditions/0
[If the time is after 8:30 AM and before 3:00 AM]
Executed: January 26, 2026 at 2:55:00 AM
Result:
after:
  __type: <class 'datetime.time'>
  isoformat: '08:30:00'
now_time:
  __type: <class 'datetime.time'>
  isoformat: '02:55:00.393464'
before:
  __type: <class 'datetime.time'>
  isoformat: '03:00:00'
weekday:
  - sun
  - mon
  - tue
  - wed
  - thu
  - fri
  - sat
now_weekday: mon
result: true
conditions/1
[If template renders a value equal to true]
Executed: January 26, 2026 at 2:55:00 AM
Result:
result: false
entities:
  - climate.lounge_ac

According to the trace the template condition failed meaning that states(‘climate.lounge_ac’) was off, so the automation would not have run.

As a side note, remove the “and” condition from the top of your conditions. Multiple conditions are “and” by default.

Vic4news’s answer is correct I just wanted to expand on it a bit:

conditions in home assistant (either in the conditions section or inline in the sequence) function as follows:

  • If true they operate as: “Continue automation”.
  • If false they abort the execution, so no additional steps happen.

Were those the results when you testing it with the Time Pattern Trigger (between 8:30 AM and 3:00 AM) or when you used the “Run” command?

Because the “Run” command will skip the conditions section and simply execute the actions section.

If you didn’t use the “Run” command, what is the state of climate.lounge_ac displayed in Developer Tools → States when the A/C unit is turned off? If it is literally off then the Template Condition you created should have worked because it requires the state to be not off in order for the automation to execute its actions.

      - condition: template
        value_template: "{{ states('climate.lounge_ac') != 'off' }}"