Hello, fellow DIYers and smart home enthusiasts! Today I want to share with you how I built a garage door opener using an ESP8266 enabled relay and Home Assistant (hass.io). This project was inspired by the need to remotely control my garage door from anywhere in the world, and also to integrate it with my existing smart home system. Here are the steps I followed:

Step 1: Gather the materials Link to heading

For this project, you will need:

  • An ESP8266 board (I used a NodeMCU)
  • A relay module (I used a 5V one-channel relay)
  • A magnetic reed switch
  • Some jumper wires
  • A micro USB cable
  • A power supply (I used an old phone charger)
  • A garage door opener (duh!)

Step 2: Wire everything up Link to heading

The wiring is pretty simple. Connect the VCC and GND pins of the relay module to the 3V3 and GND pins of the ESP8266 board. Connect the IN pin of the relay module to any digital pin of the ESP8266 board (I used D1). Connect one end of the reed switch to another digital pin of the ESP8266 board (I used D2) and the other end to GND. Connect one terminal of the garage door opener to NO (normally open) pin of the relay module and the other terminal to COM (common) pin. Plug in the micro USB cable to power up the ESP8266 board.

Step 3: Flash some code Link to heading

The code for this project is based on this tutorial by Random Nerd Tutorials. It uses HTTP GET requests to trigger the relay on or off, and also reads the state of the reed switch to determine if the garage door is open or closed. You will need to modify some variables in the code according to your WiFi credentials, your Home Assistant IP address and port, your API password (if any), and your chosen pin numbers. You can find my code here.

Step 4: Set up Home Assistant Link to heading

The final step is to set up Home Assistant to communicate with our ESP8266 device. We will use MQTT as our protocol for sending commands and receiving status updates. You will need to install an MQTT broker on your Home Assistant server (I used Mosquitto) and configure it in your configuration.yaml file. Then you will need to create two MQTT switches: one for controlling the relay and one for reading the reed switch state. You can find my configuration.yaml file here.

That’s it! Now you have a smart garage door opener that you can control from anywhere using your phone or voice assistant. You can also create automations based on your location, time of day, weather conditions, etc. For example, you can have your garage door open automatically when you arrive home or close automatically when you leave.

I hope you enjoyed this blog post and found it useful. If you have any questions or feedback, please leave them in the comments below. Happy hacking!