Building an Automated Door Lock System with Drupal 8
If you've been in web development for any length of time, a relative, friend or stranger has had an idea for you. This typically involves listening to a lengthy plan of how their idea will make them rich while you try to pretend that you care.
Finally, a friend of mine had a good idea. He had just purchased a Bed & Breakfast with an automated door lock system. He wanted to create a method to automatically send a guest their door keycode on the check-in date. My wheels started spinning, can I build this in Drupal? Yes!
Key Components:
- Webhooks - Booking engine with webhook functionality. Anytime someone books a room or a booking is updated, this webhook is fired and pings a url in D8 that has been configured to consume the JSON data passed from the webhook.
- Drupal’s Queue System - The JSON data from the webhook is added to Drupal's Queue system to be processed later as a booking entity containing the start date of their stay, contact information, etc.
- CRON - Using Drupal's cron system, a check is made to see if any bookings are starting today. If there are, they are added to an Email queue and/or SMS queue to be sent out.
- Twilio - For SMS notifications
- SendGrid - For email notifications
- Home Assistant - Using the REST API from Home Assistant (open source home automation software running on a Raspberry PI) we'll be able to automatically remove and add new PIN codes.
Although a complex setup, this method provides you with the security of ensuring the right people have access to your house. By leveraging Drupal, I was amazed how easily this could be pulled of. With all the great functionality in core, the solution requires minimal custom code.
Some base understanding of Drupal 8 code and concepts will be helpful as we dive in and look at:
- Scalability - Using Drupal's Queue System to delay process intensive actions.
- Security - Integration with the Key module for storing API keys.
- Reliability - Integrating with third party services like SendGrid and Twilio for notifications.
- Reusability - Leverage Drupal Services for code organization and reuse.
My hope is that you'll leave with a renewed appreciation of how flexible Drupal can be.