Using Home Assistant to automatically close my garage if its open longer than 10 minutes after sunset and before sunrise

I became a fan of home automation after having kids that would constantly leave lights on as well as times when I would forget to close the garage door. Initially I would use sites such as ITTT for some automations, but ITTT limited options. Enter Home Assistant. Home Assistant gives you the power to combine several automated products from different manufactures under 1 roof. The best part of Home Assistant is the fact that it is Open Source.

I use devices designed for Google Assistant or Alexa without any issues. The best part is using Home Assistant, I can have my Alexa control Google devices and vise-versa. I have been using Home Assistant for about 4 years now and it ties in with my Alexa and Google Assistant seamlessly.

I have an older garage door opener that is extremely quiet and works well, so I didn’t want to purchase a newer opener just to be able to control my garage door via an app. Allot of the garage door wifi devices were dependent on newer models. After researching several devices I found a device that fit my needs: Garadget (available on Amazon). Garadget is also open source and does not need to be cloud dependent. This device goes inline with your existing wired garage door opener that you have in your house. you can either splice the line or connect it at the same place your wired opener goes. So there is no need to train the device with older garage door wireless openers. Automating my garage door was my first step into home automation years ago. Now most everything in my house is automated in some way. My wife loves it….(not so much).

This script was based off the work I had found on an old garadget community post that I can no longer find. I will link it here if I’m able to find it in the future. the script works in 2 parts, the automation itself and the script it calls to open or close the garage itself. First the Automation (which would be placed in your home assistant config directory’s automations.yml:

- id: '1580266666413'
  alias: Garage auto-close
  trigger:
    - platform: state
      entity_id: cover.garage
      to: "open"
      for:
        minutes: 10
    - platform: sun
      event: sunset
      offset: "+00:25:00"
  condition:
    condition: and
    conditions:
      - condition: state
        entity_id: cover.garage
        state: "open"
        for:
          minutes: 10
      - condition: or
        conditions:
          - condition: sun
            after: sunset
            after_offset: "+00:25:00"
          - condition: sun
            before: sunrise
  action:
    service: cover.close_cover
    entity_id: cover.garage

Next add the following to scripts.yaml (also located in home assistant’s config folder):

garage_trigger:
  alias: Garage Trigger
  sequence:
  - entity_id: cover.garage
    service: cover.toggle

Lastly, you would want to make sure Garadget is defined in Home Assistant’s configuration.yaml (Home Assistant calls the garage door a “Cover”). You will need to get your garadget’s device ID assigned via Home Assistant. you will also need to gather you Gardget’s access token, which you can get using this post.

cover:
  - platform: garadget
    covers:
      garadget:
        device: yourdeviceid
        access_token: youraccesstoken
        name: garage
          #username: !locatedinmysecretsfile
          #password: !locatedinmysecretsfile