Send OFF command to AC if door is open for over 30 sec and verify the door status every 5 minutes until closed

Hi, I need to create an automation for a room where an off command is sent to the air conditioner if the door is open for over 30 seconds. The automation should also check every 5 minutes if the door is closed and if not, an off command is sent to the AC if the door is open. If the door is closed, the automation is stopped until it is triggered again by the open status of the door. Is there any blueprint on this or anyone has something similar that would help me? Thanks in advance.

I don’t understand why you need this part if your AC has already been turned off when the door has been open for more than 30s.

Is it to avoid the situation where the door is already open when the AC is turned on?

If so, I suggest to do 2 separate automations.
First automation to cover your first sentence goes something like:
When: Door is open for 30s
And If: AC is on
Then: Turn off AC

Second automation to cover your second sentence goes something like:
When: AC is on for 5m
And If: Door is open
Then: Turn off AC

What should happen if at the 5 minute mark the door has been closed?

Hi & thanks for your reply - I need to check every x minutes in case I’m not at home and someone else turns back ON the AC while the door is open…

Not a good idea to have an automation running continuously for more than a few minutes. If HA restarts, it will stop and not run again.

As @ShadowFist says, you need two automations, one triggered by the door opening, the other triggered by the AC being on for five minutes (or on a time pattern, with a condition that the AC is on).

1 Like

No, you don’t. Like @jackjourneyman says, that’s not a good idea.

The state of the door and AC should determine whether the automation runs. I will make absolutely no difference whether you are home or not.

thanks @jackjourneyman - the only problem with this suggestion is that the AC is a ‘dumb’ one so can’t get its status of being on or off. I can only send On or OFF commands via a Broadlink universal IR remote. No issue in my opinion if HA restarts as the automation runs in a restart mode. The automation should stop if the door is closed and should trigger again based on the door status or the duration of the open status…I know it’s quite complicated…

I don’t think this is what restart mode means. If HA is restarted, the automation will not run again until it is triggered again.

An automation that is triggered every x minutes on a time pattern does check every x minutes. As for the dumb AC - if you send an “off” command and it is already off, does it matter?

If you’re concerned about this, you can create a Broadlink switch, so you at least know its assumed state.

Post your entire existing YAML, marked up as code so that indentation etc. is not completely broken. That will make it easier for us to just help you add the missing triggers/conditions.

the broadlink switch is useful info, thanks for that. I only had the script but setting the switch makes more sense.

alias: Turn off AC when garden door open for over 30s-new
description: Turns off AC if garden door is open for 30 seconds and checks every 5 minutes
triggers:
  - entity_id:
      - binary_sensor.backyard_door_opening
    to: "on"
    trigger: state
  - minutes: /15
    trigger: time_pattern
conditions:
  - condition: state
    entity_id: binary_sensor.backyard_door_opening
    state: "on"
actions:
  - choose:
      - conditions:
          - condition: or
            conditions:
              - condition: state
                entity_id: binary_sensor.backyard_door_opening
                state: "on"
                for:
                  seconds: 30
              - condition: and
                conditions:
                  - condition: state
                    entity_id: binary_sensor.backyard_door_opening
                    state: "on"
                  - condition: template
                    value_template: >
                      {% set door_time =
                      states('input_datetime.garden_door_opened_time') |
                      as_datetime %} {% set current_time = now() %} {{
                      (current_time - door_time).total_seconds() > 900 }}
        sequence:
          - action: script.1703524180604
            data: {}
          - target:
              entity_id: input_datetime.garden_door_opened_time
            data:
              timestamp: "{{ now().timestamp() }}"
            action: input_datetime.set_datetime
    default:
      - stop: Automation stopped as door is closed
mode: restart

this is what I hope it might work…any feedback/suggestions much appreciated

Hello Dan,

Take whatever inspiration you want from this or use it as is. I think I’m doing the same kinda thing you are looking for.

I’d do two automations, the first would look for the door being open for 30 seconds and then it would turn off the AC like this:

description: "Turn off AC when a barn door is left open"
mode: single
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.front_door_mqtt
      - binary_sensor.back_door_mqtt
    from: "off"
    to: "on"
    for:
      hours: 0
      minutes: 0
      seconds: 30
conditions: []
actions:
  - action: climate.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: climate.waterfurnace_zone_1

Then second automation would kick off when a door is closed, and if all the doors are closed it would turn the AC back on. No real need for a timer to go back and check.