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.
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.
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).
.
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
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.