Close garage door at night if its open

I want to set an automation that will do the following;

  • If after 10pm and before 6am, if the garage door is open, then close the garage door.
  • Wait 1 minute and check if the door sensor shows closed. (toys could be in the door sensor and not allow to close)
  • If the garage is still open, send alerts to devices to close the door and repeat sending notifications until the garage door sensor shows closed.

Here is what i have. i dont think my repeat is correct, but it may be.

thanks

alias: "Night Time: Close Garage"
description: ""
trigger:
  - type: opened
    platform: device
    device_id: ef7935dcfb3bd798c87a6402c32d2c71
    entity_id: 3e3df0fe89359c6f63284cea2b57bc2b
    domain: binary_sensor
condition:
  - condition: time
    after: "22:00:00"
    before: "06:00:00"
action:
  - device_id: 12b15e8cc2078e184f705786b8b336e6
    domain: cover
    entity_id: 53a1b09d46822e1502ef4ae0b8bbb044
    type: close
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - if:
      - type: is_open
        condition: device
        device_id: ef7935dcfb3bd798c87a6402c32d2c71
        entity_id: 3e3df0fe89359c6f63284cea2b57bc2b
        domain: binary_sensor
    then:
      - service: notify.alexa_media
        data:
          message: garage open
          target: >-
            media_player.living_room, media_player.family_room,
            media_player.kitchen, media_player.moms_room, media_player.basement
      - repeat:
          sequence: []
          until:
            - type: is_not_open
              condition: device
              device_id: ef7935dcfb3bd798c87a6402c32d2c71
              entity_id: 3e3df0fe89359c6f63284cea2b57bc2b
              domain: binary_sensor
      - service: notify.mobile_app_iphone
        data:
          message: Garage door is open
mode: restart

Check the documentation how to properly do a repeat: Script Syntax - Home Assistant
You need to define a sequence (which is your notification).

Are you sure you want to immediately close the door, as soon as it is opened? Don’t you need to get your car etc. into the garage? :wink:

1 Like

More to the point, the automation triggers when the door opens, so if the door is already open at 22:00 nothing will happen.

And yes, As Florian said, if the door opens after 22:00 it’ll immediately close. That sounds … not well thought out.

1 Like

I did some more tinkering but am at work now.

I changed to; if door status has been open for 5 mins while inbetween 10-6 then action.

Will read links later and update. Thanks

i read the link provided. i see how repeats work somewhat. i am still confused how i would word it to automate how i want it to work.

I don’t think this is going to work the way you think it will. If prior to 10pm the door has been open more than 5 minutes, it will never trigger once it’s after 10pm because it will have already crossed the 5 minute threshold.

Yes. After tinkering, this is what i have concluded. I am currently reading about helpers and if i can create something to help me complete this task.

An unsupervised garage door closing. What could possibly go wrong?

I think simply adding a trigger of 10pm in addition to your 5 minutes open trigger will get you what you’re after. Then it will run if it’s already open and again if it’s somehow opened during the night.

Although personally I wouldn’t want the garage door operated in an automation without user input.

i have some fail-safes.

1st. check status of garage door. if its closed, do nothing.
2nd. if garage door happens to be open and i want it closed, wait 15 seconds and see if the door closed. If it didnt, send an alert that there may be an obstruction in the garage door.

It’s the unsupervised aspect that’s a problem. Check the safety section of your garage door manual and it’s likely to include a line about requiring monitoring (i.e. a set of eyes confirming it’s safe to close the door).

In some jurisdictions it’s permitted to have unsupervised closings provided there’s a visual and/or audible notification prior to closure (to at least warn anyone present that the door is about to close). That’s what I have (an announcement indicating closure in 10 seconds).
.

Thats a good idea. Maybe i’ll add a speaker out there for an alert.

After tinkering around, I finally figured out the code.

Every 5 mins it will trigger, check to see if its between 10pm and 6am, and check to see if the garage has been open for atleast 5 minutes. It will then close the garage. it will then delay for 30 seconds and recheck the door status. If the door status is still open, it will send an alert that the door will not close. (most likely a kids toy or bike blocking the sensor)

alias: "Night Time: Close Garage"
description: ""
trigger:
  - platform: time_pattern
    minutes: /5
condition:
  - condition: time
    after: "22:00:00"
    before: "06:00:00"
    weekday:
      - sun
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
  - condition: state
    entity_id: binary_sensor.garage_door_sensor_door
    state: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
action:
  - service: cover.close_cover
    data: {}
    target:
      entity_id: cover.garage_door_controller
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - if:
      - condition: state
        entity_id: binary_sensor.garage_door_sensor_door
        state: "on"
    then:
      - repeat:
          sequence:
            - service: notify.mobile_app_gravity
              data:
                message: The Garage Door Is Stuck Open
            - service: notify.alexa_media
              data:
                target: >-
                  media_player.living_room, media_player.family_room,
                  media_player.kitchen, media_player.moms_room
                message: Garage door is stuck open. Go check the garage door.
              enabled: true
            - delay:
                hours: 0
                minutes: 0
                seconds: 30
                milliseconds: 0
          until:
            - condition: state
              entity_id: binary_sensor.garage_door_sensor_door
              state: "off"
      - service: notify.mobile_app_gravity
        data:
          message: The Garage Door Has Been Free'd and Is Now Closed
      - service: notify.alexa_media
        data:
          target: >-
            media_player.living_room, media_player.family_room,
            media_player.kitchen, media_player.moms_room
          message: The Garage Door Has Been Free'd and Is Now Closed
        enabled: true
mode: restart

I’d probably remove the state condition make the trigger:

trigger:
  - platform: state
    entity_id: binary_sensor.garage_door_sensor_door
    to: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0

The reason I added this was just in case someone or myself happens to use the garage during the 2200-0600-time frame. It will check to verify it’s been open at least 5 mins before closing it again.

Or:

alias: "Night Time: Close Garage"
description: ""
trigger:
  - platform: time
    at: "22:00:00"
  - platform: state
    entity_id: binary_sensor.garage_door_sensor_door
    to: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
condition:
  - condition: time
    after: "22:00:00"
    before: "06:00:00"
  - condition: state
    entity_id: binary_sensor.garage_door_sensor_door
    state: "on"
    for:
      hours: 0
      minutes: 5
      seconds: 0
action:
  - service: cover.close_cover
    data: {}
    target:
      entity_id: cover.garage_door_controller
  - delay:
      hours: 0
      minutes: 0
      seconds: 30
      milliseconds: 0
  - if:
      - condition: state
        entity_id: binary_sensor.garage_door_sensor_door
        state: "on"
    then:
      - repeat:
          sequence:
            - service: notify.mobile_app_gravity
              data:
                message: The Garage Door Is Stuck Open
            - service: notify.alexa_media
              data:
                target: >-
                  media_player.living_room, media_player.family_room,
                  media_player.kitchen, media_player.moms_room
                message: Garage door is stuck open. Go check the garage door.
              enabled: true
            - delay:
                hours: 0
                minutes: 0
                seconds: 30
                milliseconds: 0
          until:
            - condition: state
              entity_id: binary_sensor.garage_door_sensor_door
              state: "off"
      - service: notify.mobile_app_gravity
        data:
          message: The Garage Door Has Been Free'd and Is Now Closed
      - service: notify.alexa_media
        data:
          target: >-
            media_player.living_room, media_player.family_room,
            media_player.kitchen, media_player.moms_room
          message: The Garage Door Has Been Free'd and Is Now Closed
        enabled: true
mode: restart
2 Likes

I will try that

I tried this. Changed the times around for current time. It did not work.

What does the trace show?

I take this back. It does work. I forgot to cycle the automations.yaml