Things used in this project

Hardware components:
Esp01
Espressif ESP8266 ESP-01
×1
5v Relay Module
×1
00114 05
SparkFun SparkFun Breadboard Power Supply 5V/3.3V
×1
Magnetic Door Switch
×1
TTL Serial Converter
×1
Software apps and online services:
OpenHAB
Nodemcu style5 150px.png 150x150
NodeMCU NodeMCU firmware

Schematics

Wiring Diagram
8589391425867423356

Code

sitemapSpace
OpehHab sitemap file
      Text item=Switch1
      Switch item=Relay1 mappings=[ON="Go!"]
esp8266-garage-door.luaLua
esp8266 code to drive garage door
-- Garage Door controller version 2/15/15 pete@hoffswell.com
-- GPIO0 is connected to switch with internal pulldown enabled  
gpio.write(3,gpio.LOW)
gpio.mode(3,gpio.INPUT,gpio.PULLDOWN)  
--GPIO2 is connected to Relay
gpio.mode(4,gpio.OUTPUT)  
gpio.write(4,gpio.HIGH)  

print("Program Start")

-- Start up mqtt
m = mqtt.Client("ESP1", 120, "user", "password")
m:lwt("/lwt", "offline", 0, 0)
m:connect("192.168.15.22", 1883, 0, function(conn) print("mqtt connected")
   m:subscribe("openhab/garage/relay1",0, function(conn) print("subscribed relay1") 
   end)
end)

-- Reconnect to mqtt server if needed
m:on("offline", function(con) print ("reconnecting...")
   tmr.alarm(1, 10000, 0, function()
      m:connect("192.168.15.22", 1883, 0, function(conn) print("mqtt connected")
         m:subscribe("openhab/garage/relay1",0, function(conn) print("subscribed relay1") 
         end)
      end)
   end)
end)

 -- Switch Trigger
gpio.trig(3, "both",function (level)
   state = gpio.read(3)
   m:publish("openhab/garage/switch1",state,0,0)
   print("Sent openhab/garage/switch1 " .. state )    
end)

-- MQTT Message Processor
m:on("message", function(conn, topic, msg)   
   print("Recieved:" .. topic .. ":" .. msg)   
   if (msg=="GO") then  -- Activate Door Button
      --print("Activating Door")   
      gpio.write(4,gpio.LOW)  
      tmr.delay(1000000) -- wait 1 second
      gpio.write(4,gpio.HIGH)  
   else  
      print("Invalid - Ignoring")   
   end   
end)  
itemsSpace
OpenHAB items file
Number Switch1         "Door Status [MAP(switch.map):%d]"    <garagedoor> (Sensors) {mqtt="<[mqttbroker:openhab/garage/switch1:state:default]", autoupdate="false"}
Switch Relay1 "Garage Door"           <garagedoor>    (All) {mqtt=">[mqttbroker:openhab/garage/relay1:command:ON:GO]", autoupdate="false"}
switch.mapSpace
map file for OpenHAB
goes in the transform/switch.map directory
0=open
1=closed
rulesSpace
OpenHAB rules file
var Timer timer = null

rule "Tweet Switch Status"
when
     Item Switch1 changed
then
     var SimpleDateFormat df = new SimpleDateFormat( "YYYY-MM-dd HH:mm:ss" )
     var String Timestamp = df.format( new Date() )
     if(Switch1.state == 0) {
        sendDirectMessage('yourtwittername', 'Switch Open ' + Timestamp)
        timer = createTimer(now.plusSeconds(300)) [|   // start timer and watch for 5 minute timeout
        sendDirectMessage('yourtwittername', 'Door open too long!')
        ]
     } else if(Switch1.state == 1) {
        sendDirectMessage('yourtwittername', 'Switch Closed ' + Timestamp)
        if(timer!=null) {  // cancel timer, door is closed
            timer.cancel
            timer = null
        }
     }
end

Credits

Pete2014
Pete Hoffswell

Network Engineer for All the People. Internet advocate. Microcontroller Fan. Maker.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Hank the HexaPod - Mega Bread Robotics Series # 7
Advanced
  • 95
  • 4

Work in progress

After a few months of gathering parts, reading about the new hardware, and ripping my hair out due to no support. I done did it Paw.

Punch Activated Arm Flamethrowers (Real Firebending)
Advanced
  • 38,727
  • 294

Shoot fireballs from your fists when you throw a punch with these arm mounted smart flamethrowers!

Get Nostalgic and Use Nokia 84x48 LCD with Arduino
Advanced
  • 2,939
  • 14

Protip

These 84 by 48 pixel LCDs are what you might have found in Nokia 3310. And what about using them in the Arduino projects?

Smart Energy Monitor Based on Arduino
Advanced
  • 229
  • 3

Full instructions

Open source Smart energy monitor with some new features like "Terminal Commands " , "Readings Logger", "Data Plotting ".

Magic VR Hat
Advanced
  • 225
  • 3

Wear the hat, get transported to different 360 VR experience.

GPS + WiFi Rover
Advanced
  • 1,249
  • 12

Full instructions

An outdoor rover, capable of autonomous navigation (using GPS and sonar sensors) or controlled over WiFi.

Sign up / LoginProjectsPlatformsTopicsContestsLiveAppsBetaFree StoreBlog