Introduction: ESP8266 Garage Door Opener With Temperature/Humidity

This is a fairly straight forward Garage Door Opener. No breadboard required. Its a very simple low cost wireless garage door opener, only a few parts need to be purchased and can be integrated directly with OpenHAB.

Parts List:

  • Wemos D1 Mini eBay ~$3.50
  • Wemos Relay Shield eBay ~$2.30
  • Wemos DHT22 Sensor eBay ~$4.50
  • USB 2A Power Supply eBay ~$2.50
  • MicroUSB Cable Optional (Only required if you dont have a spare to flash the Wemos D1)

Total: ~$13 for a Wireless Garage Door Opener hooked up to your OpenHAB Installation

Step 1: Step 1: Flash Firmware

Plug Wemos D1 Mini into your computer and Load up Arduino IDE.

I like using Homie MQTT Framework for all my sensors/relays. It helps keep a nice working pattern and supports OTA if there changes/updates that need to be made to the code.

Here is the code that I'm using to flash.

Download the latest version of Homie from https://github.com/marvinroger/homie-esp8266/

You can follow how to setup homie at their readme

<p>#include <Homie.h><br>#include <DHT.h></p><p>#define FW_NAME "garage-door"
#define FW_VERSION "1.0.1"</p><p>#define PIN_RELAY         D1
#define PIN_SENSOR        D5
#define OPENER_EVENT_MS   1000
#define DEBOUNCER_MS      250
#define DHT_PIN           D4
#define DHT_TYPE          DHT22
#define PUB_INTERVAL      60</p><p>DHT dht(DHT_PIN, DHT_TYPE);
unsigned long lastTemperatureSent = 0;
unsigned long openerEvent = 0;</p><p>Bounce debouncer = Bounce();
int lastSensorValue = -1;</p><p>HomieNode openerNode("opener", "relay");
HomieNode doorNode("door", "sensor");
HomieNode temperatureNode("temperature", "temperature");
HomieNode humidityNode("humidity", "humidity");</p><p>bool openerHandler(HomieRange range, String value) {
  if (value == "1" || value == "ON" || value == "true") {
    digitalWrite(PIN_RELAY, HIGH);
    openerEvent = millis();
  }
  return true;
}</p><p>void setupHandler() {</p><p>  pinMode(PIN_RELAY, OUTPUT);
  pinMode(PIN_SENSOR, INPUT_PULLUP);</p><p>  digitalWrite(PIN_RELAY, LOW);  
  
  Homie.setNodeProperty(temperatureNode, "unit").setRetained(true).send("f");
  Homie.setNodeProperty(humidityNode, "unit").setRetained(true).send("%");
  dht.begin();</p><p>  debouncer.attach(PIN_SENSOR);
  debouncer.interval(DEBOUNCER_MS);
}</p><p>void loopHandler() {
  int sensorValue = debouncer.read();</p><p>  if (sensorValue != lastSensorValue) {
     Serial.print("Door is now: ");
     Serial.println(sensorValue ? "open" : "close");</p><p>     Homie.setNodeProperty(doorNode, "open").send(sensorValue ? "true" : "false");
     lastSensorValue = sensorValue;
  }</p><p>  if (millis() - lastTemperatureSent >= PUB_INTERVAL * 1000UL || lastTemperatureSent == 0) {
    float temp_c = dht.readTemperature();
    float humidity = dht.readHumidity();
    float temp_f = (temp_c* 9 +2)/5+32; 
    
    Homie.setNodeProperty(temperatureNode, "degrees").send(String(temp_f));
    Homie.setNodeProperty(humidityNode, "relative").send(String(humidity));
    lastTemperatureSent = millis();
  }
 
}</p><p>void setup() {
  Serial.begin(115200);
  Serial.println();
  Serial.println();
  
  Homie_setFirmware(FW_NAME, FW_VERSION);</p><p>  openerNode.advertise("press").settable(openerHandler);
  doorNode.advertise("open");
 
  temperatureNode.advertise("unit");
  temperatureNode.advertise("degrees");
  
  Homie.setSetupFunction(setupHandler);
  Homie.setLoopFunction(loopHandler);
  
  Homie.setup();
}</p><p>void loop() {
  if (openerEvent && (millis() - openerEvent >= OPENER_EVENT_MS)) {
    digitalWrite(PIN_RELAY, LOW);
    openerEvent = 0;
  }</p><p>  Homie.loop();
  debouncer.update();
}</p>

Step 2: Step 2: Setup Items/Sitemap on Your OpenHab

Here is my default.items

Number GarageMonitor_Temp01 "Garage Temperature [%.1f °F]" (gGARAGE, gTemperature) {mqtt="<[OpenHab:devices/garage/temperature/degrees:state:default]"}
Number Garage_Humidity01 "Garage Humidity [%.1f %%]" (gGARAGE, gTemperature) {mqtt="<[OpenHab:devices/garage/humidity/relative:state:default]"}

Switch Garage_Relay1 "Garage Door" (gGARAGE) {mqtt=">[OpenHab:devices/garage/opener/press/set:command:ON:true]"}

Here is my default.sitemap

Text label="Garage" icon="garage" {
Frame label="Garage Temperature/Humidity" { Text item=GarageMonitor_Temp01 Text item=Garage_Humidity01 } Frame label="Garage Door" { Switch item=Garage_Relay1 mappings=[ON="Go!"] } }

Save everything and test with your OpenHab setup.

Once your relay is working perfectly fine, hook it up to your garage door opener and start controlling your door via your OpenHab app.

Step 3: Step 3: Things to Add.

Waiting for my Door Contact Sensor to arrive to connect to device, once I receive it, i'll update the instructables

Thanks for reading.

* I maybe compensated for products you buy through this page through affiliate links.