Monitor your Garage Doors with MQTT

Its a nighttime ritual for me.  Usher kids to bed, pick up kitchen, turn out lights, and peek into the garage to ensure the overhead doors are closed.  Odds are they aren’t, as someone always seems to have left them open through the normal bustle of the day.

I have been dabbling with home automation, building sensors and devices to automate the mundane.  So to that end, I set out to build something for the garage.  Design goals were:

  • Provide a status of open/closed for the two overhead doors
  • Ability to open/close doors from my phone

The hub of my home system today is Home Assistant (running on raspberry pi) which is very versatile, and allows many integration points.  As many internet of things devices are using MQTT, I am using that as the primary means of communication to/from the hub.

The micro controller used is an esp8266 which has an amazing story in itself; rising from simple beginnings – being initially sold as a uart->wifi adapter and becoming a stand along micro controller thanks to a dedicated group of enthusiasts.  This device can be had for about $8.00, has WiFi, and can run code compiled on the Arduino IDE.

Parts:

This project was fairly straightforward as it stands on the shoulders of projects done by others, as well as some starts and stops I had with recent ESP8266 projects.  The device is powered by a 5v wall wart, which supplies power for the ESP as well as the relay breakout board used.  These components combined with the hall sensors on the doors are all that was needed.  An overview of the hardware connections are here..

In Fritzing:

Fritzing Diagram

In reality:

ESP_WiringCloseUp

Note that the relay outputs that connect to the door ‘buttons’ can actually be connected right at the opener, where the button’s wire comes in.  Thats the blue/white wires on the right side above.

The door sensors are installed on the wall, and triggered by magnets on the doors.  This means any position other than fully closed will register as open (good in my opinion).  Installed they look something like this:

 

On the software side what the ESP8266 is doing is watching for the digital reads of pins D5 (door 1) or D6 (door 2) to change state (open / closed) and when it sees this it’ll post a message on the MQTT server.

The home automation hub takes it from there.  The other thing the ESP8266 is doing is watching for updates on MQTT for requests to open or close the door.  Once a message is notified the ESP will close the relay for a second (simulating a button press) and the door will start moving.  The messages look like this (going from open to closed):

/esp/garageDoorTwo/set 0       #this is the request to close
/esp/garageDoorTwo/state 0    #this is confirming state changed to closed

The actual code on the ESP8266 is linked below.  The highlights are the WiFi join, enabling of over-the-air updates, and the management of the MQTT messaging.

garageDoor.ino code

And if you happen to use HomeAssistant here is the relevant parts of the configuration.yaml file.

config.yaml code

And to wrap things up, here is what the results look like on my iPhone.

IOS_HA_Homescreen

Let me know if you have any questions or clarifications and I’ll try to answer them.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s