Things used in this project

Hardware components:
Esp01
Everything ESP ESP8266 ESP-01
×1
5v Relay Module
×1
00114 05
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 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.

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

Caravaggio, a Drawing Machine
Advanced
  • 3,521
  • 30

Caravaggio is a drawing machine able to replicate a digital image using a pen and a continuous line.

Mycroft AI Furboid
Advanced
  • 100
  • 4

Work in progress

I am using Hasbro's 1998 Furby, a Raspberry Pi Zero W, Pimoroni Explorer pHAT, and the Mycroft AI to make a fun robo assistant.

Smart Parking
Advanced
  • 1,702
  • 18

it system that managing cars access to parking place by using Rfid Technology

Smart Parking

Team Hadramoot

Raspberry Pi Remote Control Car Camera
Advanced
  • 263
  • 5

Full instructions

This project will make a remote control car which has a view via an attached camera.

Arduino Wireless Weather Station
Advanced
  • 7,956
  • 35

Full instructions

In this tutorial I am going to show you how to build a Wireless Weather Station with a big 3.2" Color TFT display using Arduino.

Virtual Arduino Tennis
Advanced
  • 711
  • 4

Full instructions

Play tennis on a Neopixel matrix and an accelerometer with an Arduino! It's like Mario Tennis meets makers!

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback