A headshot of Joey.
  • aws-lambda
  • typescript
  • iot
  • aws-eventbridge
  • aws-cdk

Garage door closer lambda

myQ lambda architecture diagram

Adding smart capabilities to a garage door opener has many advantages. For example, the ability to open and close the garage door from anywhere in the world is great for allowing people one-time access into one's home without giving them a key, garage door opener, or garage code.

Another benefit is having a log of when the door was opened and closed, which means knowing if the garage door was left open when no one is home. At some point, most garage doors end up open overnight or when no one is home which can lead to problems with animals or even theft. That is how this idea was born.

I created an AWS lambda function that checks the status of my garage door and closes it if it has been open longer than an hour. The lambda function is triggered by an AWS EventBridge scheduled event. If any errors occur, I send a notification using a webhook to a service that publishes a notification to my Alexa devices at home.

I also used AWS Systems Manager Parameter Store for the application secrets. I chose Parameter Store for two reasons: 1) it is cheaper than secrets manager and 2) the secrets are external to AWS and I do not plan to rotate them programmatically on a schedule.

The application flow goes like this:

  1. AWS EventBridge publishes an event every hour at minute five using a cron expression.

  2. The AWS Lambda function is triggered by that event.

  3. The lambda function retrieves the application secrets from AWS Systems Manager Parameter Store.

  4. The lambda function queries the myQ API to see if the garage door is open and if the last state change was over an hour ago.

  5. Issue a door close command to the myQ API.

  6. Send a notification to my Alexa devices that the door was closed at the current time.

  7. If errors, also send a notification.

All credit for the myQ API integration goes to the NPM library hjdhjd/myq.

If you have any questions or suggestions regarding my lambda function, please create an issue on the GitHub repository using the source code link below!

Source code link

github.com