This project controls your garage door opener using MQTT as the messaging service, ESPHome to configure the ESP8266 module, and a Raspberry Pi to serve the web app shown
in the demo video. The Raspberry Pi web server is not mandatory. You can trigger the Garage Door with any app that can publish an MQTT message (garageDoor/trigger
-
configurable in garage.yaml
as explained in the ESPHome section below). Read more about this project at
https://www.easyprogramming.net/raspberrypi/nodemcu_garage_door_control.php.
Check out the demo on YouTube by clicking on the following gif:
- Raspberry Pi - any version will work since this will just host the web server
- ESPHome set up (Hassio set up will work)
- NodeMCU Board (can use any ESP8266 module including D1 Mini)
- 5v Relay Module
- DHT11 sensor - for Temperature & Humidity
- Jumper cables
- Box for your stuff
- ESPHome - perhaps through Hassio
- MQTT Broker - any will work. I use Mosquitto installed on my Hassio (which is in turn installed on a Raspberry Pi 4)
- Apache for the web server - can be installed anywhere but I have it on a RPi Zero W that I use to serve other web content
The following diagram is for connecting your NodeMCU to your relay and DHT11 sensor:
Color | Pin | Connects to |
---|---|---|
Red (relay) | VU | VIN on Relay |
Black (relay) | Any Ground Pin | GND on Relay |
Green | D1 | Data pin on Relay |
Blue | Normally Open and Common pins on relay | To garage door controller |
Red (DHT) | any 3v Pin On NodeMCU | Power on DHT Module |
Black (DHT) | Any Ground Pin on NodeMCU | GND on DHT Module |
Yellow | D2 | Data Pin on DHT |
The blue wires represent the connections going into the Garage Door control. As you'll see in my demo, The door triggers (open/close/stop) when the two left-most terminals are connected in any way. When you put the two wires on the normally open connection on your Relay module, they are not connected. When the connect closes, the door controller then knows to do something.
Upload the contents of esphome/garage.yaml
to your ESP module using ESPHome. I use Hassio but if you have another method of doing so, it should be fine.
The following MQTT configurations are set and are configurable. If you configure the message, you must configure the subscription in script.js
as shown below. The
MQTT setup in the YAML is as follows:
mqtt:
broker: {{Broker IP}}
discovery: True
username: "your mqtt username"
password: "your mqtt password"
topic_prefix: "garage"
on_message:
topic: "garageDoor/trigger"
then:
- switch.turn_on: garageDoorTemplate
If you configure the topic above and if you are using the included web app, you must configure line 40 of script.js
and publish to the new trigger:
client.publish("garageDoor/trigger");
My YAML converts the default unit of measurement to Fahrenheit. To go back to Celsius, just remove this blcok:
filters:
- lambda: return x * (9.0/5.0) + 32.0;
unit_of_measurement: "°F"
And if you like Kelvin, change the block to this:
filters:
- lambda: return x + 273.15;
unit_of_measurement: "°K"
To learn how to install Apache and run a simple app, check out my tutorial on How to Turn your Pi into an Apache Web Server here.
Nazmus Nasir - Easy Programming
There's no way to tell if the door is open or closed. This is on my to-do list.
If you have questions, there are many ways to get in touch with me!
- Ask in the comments section of the YouTube video, I am generally very good at responding to questions.
- Ask in the comments section of EasyProgramming.net. Every tutorial comes with a Disqus section to allow a meaninful discussion
- If a repository exists on Github, open an issue!
- This should be used as a last resort because I check this email every once in a while and don't guarantee a response, but if you must, you can use the contact form found here: https://www.easyprogramming.net/contact.php