Thanks, to everyone, for the conversations that got me as far as I have -
Garage Door Opener with ESP01, a relay and a switch.
http://kayakpete.tumblr.com/post/110860 ... 66-running

[2/13/2015 - *** Diagram removed - See responses ***]
[2/15/2015 EDIT - Updated code]
[2/13/2015 EDIT - Updated code]
-- Garage Door controller version 2/15/15 pete@hoffswell.com
-- GPIO2 is connected to switch with internal pulldown enabled
gpio.write(4,gpio.LOW)
gpio.mode(4,gpio.INPUT,gpio.PULLDOWN)
--GPIO0 is connected to Relay
gpio.mode(3,gpio.OUTPUT)
gpio.write(3,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")
m:publish("openhab/garage/relay1","GO",0,0) -- counter program start
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(4, "both",function (level)
state = gpio.read(4)
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(3,gpio.LOW)
tmr.delay(1000000) -- wait 1 second
gpio.write(3,gpio.HIGH)
else
print("Invalid - Ignoring")
end
end)
On occasion, I get the following:
PANIC: unprotected error in call to Lua API (door1.lua:24: sending in process)
That's the m:publish within the gpio.trig function.
Also some times it locks up enough to where I must power cycle the ESP01. When I do, sometimes even that won't recover until I disconnect GPIO0
Any thoughts as to how to fix either of these issues?
Thanks!