This project uses the ESP-01 to control the garage door opener as well as sense when the door is open or closed.
The ESP-01 talks via wifi to an OpenHAB controller that monitors door status as well as sends door open/close commands. The OpehHAB controller then sends tweets to let you know if your door is open, closed, or has stayed open too long.
This project uses an ESP-01 SOC programmed with NodeMCU.
This project is best for experimenters that already have an OpenHAB system running, or want a real-world interface to use with an OpenHAB system.
Step 1 - Wire up your ESP-8266 ESP-01 ModuleWire the ESP-01 as follows. Go ahead and leave your TTL converter connected so you can continue programming and debug.
For the bench, you can see that I am using a simple push button to emulate the door open/closed sensor.
Follow Marc's good instruction on how to load NodeMCU onto your ESP-01 athttps://importhack.wordpress.com/2014/11/22/how-to-use-ep8266-esp-01-as-a-sensor-web-client/
ESPlorer is a great way to program the ESP-01. Get ESPlorer IDE running, so you can access and program the ESP-01.
Step 3 - Program your ESP-01Change the ip address of the M:connect command to match the ip address of your MQTT broker. (More on the broker in step 4)
-- 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)
null
Step 4 - Setup and Configure OpenHABConfigure OpenHAB. (These instructions assume you have a OpenHAB server already. For more info on openhab, visit https://github.com/openhab/openhab/wiki/Quick-Setup-an-openHAB-Server)
- Set up MQTT Broker if you have not done so already
- Set up the OpenHAB configuration files as follows, to display door open/closed switch status, and send door button presses.
- Configure an openhab rule to send you a tweet when the door is open or closed for testing. Send you a tweet when the door is left open for 5 minutes
Sitemap:
Text item=Switch1
Switch item=Relay1 mappings=[ON="Go!"]
Items:
Number Switch1 "Door Status [MAP(switch.map):%d]" (Sensors) {mqtt=" (All) {mqtt=">[mqttbroker:openhab/garage/relay1:command:ON:GO]", autoupdate="false"}
transform/switch.map:
0=open
1=closed
rules:
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
Step 5 - Hook it UpConnect it up to the garage. The relay will connect to your garage door opener exactly the same way the push button on the wall does. You should see the two wires without too much trouble. I just connected to the wireless controller that was plugged in the wall -
Connect the other two wires from the controller to a magnetic switch that is set up to close when the garage door is closed.
Comments