WiFi/MQTT car presence sensor for garage door automation

This is a pretty simple project I’m using to automate my garage doors when cars come and go. This presumes that you already have a garage door cover device available in Home Assistant. The device connects to MQTT when your car turns on (or arrives home), then an automation will tell Hass to open the garage door if it’s closed. When the car is powered off (or you drive out of range), a Last Will and Testament will notify Home Assistant of the new state and then an automation can trigger the garage door close command after a short delay.

The included Arduino code is setup to work with Home Assistant MQTT Discovery to automatically create a binary_sensor device which will indicate the connection status of the device. The device should be powered from your car’s ignition so it’s only on when the car is running. When the device powers on, it will attempt to connect to the defined MQTT broker, publishes a discovery message, and configures a Last Will and Testament. When the device is powered off (or you drive out of WiFi range), the Last Will and Testament is sent by your broker to update subscribed automation system(s).

The included Home Assitant automation example utilizes this information to open or close a connected garage door.

This project relies on the PubSubClient library for MQTT. Follow this guide for the general process and add the ‘PubSubClient’ from the Library Manager. Once that is installed you will need to edit the PubSubClient.h file and change the line #define MQTT_MAX_PACKET_SIZE 128 to #define MQTT_MAX_PACKET_SIZE 512. You can find the installed library under the path shown in File > Preferences > Sketchbook location.

Workflow - User perspective

  • Car is in your garage and the garage door is closed
  • You get in the car and turn it on, the garage door opens
  • You drive away, the garage door closes a minute later
  • When you arrive back home, the garage door opens as you approach
  • When you turn off your car, the garage door closes about a minute later

Detailed workflow

  • Car is powered off, garage door is closed
  • Car turns on, device publishes connection message to MQTT
  • Home automation platform sees that the garage door is closed and the device is connected, then sends command to open garage
  • You drive away when ready
  • Device eventually drives out of range, MQTT broker sends disconnection message configured as the LWT
  • Home automation platform sees the garage door is open and the device has disconnected, then sends command to close garage
  • You go on about your day, then return home.
  • Device connects to WiFi, then MQTT and publishes connection message
  • Home automation platform sees that the garage door is closed and the device is connected, then sends command to open garage
  • You park your car and turn it off
  • Home automation platform sees the garage door is open and the device has disconnected, then sends command to close garage

Bill of Materials

  • WeMos D1 mini Pro
  • u.FL to SMA antenna whip
  • External 2.4GHz WiFi antenna
  • M3x8mm socket head cap screw (or similar)
  • M3x4x6 threaded insert (or similar)
27 Likes

A+ writeup!! Love the documentation! If your hobby docs are this nice… do you need a job? :slight_smile:

1 Like

Day job has me writing process documentation pretty regularly and no process is complete until you’ve arranged it such that the next guy will be able to repeat the task. Looks like that’s spilling over into my hobbies :smiley:

5 Likes

are the external antennas required?

Thanks for the writeup!!

Just too make sure I’m not missing anything :wink: This device has to be connected / plugged into the car, correct?

yes … powered by the car , but i m initially testing on the bench .
so far working well

1 Like

Nope, I have been running this with a bare WeMos D1 Mini wrapped in heatshrink and plugged into my car’s USB port, all of which can be accomplished for < $3 and will let you test to see if the range works for you. In the OP I switched over to a WeMos D1 mini Pro with the hopes of extending the range via an external antenna, which doesn’t seem to have made a material impact. I still need to do some more testing but the approach does work in a general sense and is ready for you to try out.

When you pull into the driveway, how long does it take for the garage door to open?

Right now it triggers when I’m about half-way up my drive. I’d like some more range so it is actually open by the time I’m at the garage door, so I’ll be experimenting w/ different antennas and placement options in the vehicle.

Your mileage may vary depending on where your WiFi AP is placed, your AP’s antenna arrangement, etc.

Can’t see the binary sensor in hassio when using mqtt discovery. Using hassio 57.3. When I add the sensor manually its updated, so its connecting and sending stuff the mqtt.

I have to add binary sensor manually too.
Tested the Standard Wemos in the car, just connected up it us to the USB power port (new car). Wemos is sitting in the central console
Driveway is about 15 m long … MQTT broker send the close disconnect when i’m about 30m away from the driveway.
On return , the garage door opens just as i’m about 5m away from the garage door. I pause the car for about 2 secs and door is fully open
MAGIC :slight_smile:
Garage door closes just after i entered the house (from the garage) ie about 2 mins after i cut the power (turn engine off)

Next to install Wemos in the central console and hard wire it to the back of the USB plug and see how the signal goes.

If MQTT discovery isn’t working, it’s likely due to the default packet size for PubSubClient being set to 128 bytes, which is hilariously short and the maintainer of this library has not accepted PRs to fix this going back some 6 years at this point. Check my docs for another project here to find and change that value to some larger value. 512 bytes should be more than enough.

1 Like

Just got these in and setup for install in the cars.

I am trying to figure out if there is any logic for deciding if the car is coming or going. For me I would love to know what car is still in the garage.

I wonder if there is a way to report the signal strength to home assistant.

This project provides no mechanism to do that - it’s simply triggering automations when the device connects and disconnects, which happens to coincide well for opening/closing a door. Detecting if the car is physically in the garage will require some other means of detection.

I actually could do that - I’m travelling for work but I’ll take a look at that this weekend. I think that info might be useful…

With that information I might be able to do what I want.
Basically if the last signal strength is weak when the sensor goes to off, I know the car is leaving. if the last signal strength is strong when the sensor goes to off the car is coming.

Thank you for taking a look.

How do you plan to supply power from the car? Would be great to know how you plan to do that (in detail).

i’ve got something simillar working with a nut tag and room-assistant. However, the nut is not very reliable. it takes a while before the nut starts broadcasting and for room-assistant to pick up. What ends up happeing is that i’m sitting in the car on the driveway waiting for the door to open for a while. It eventually does, but is frustrating!!

This runs from a USB outlet, which most modern cars have. Otherwise, use a cheap cigarette lighter adapter.

Thanks. Did you have to move the 0 ohm resistor to attach the antenna - like shown in the video here?

Yes, the WeMos pro ships w/ the jumper/0ohm connected to the on-board ceramic antenna. You need to move re-solder it to use the external antenna per the video you’ve linked.

edit: actually watched the video - he’s using a hot-air rework station (which I don’t have… yet) but I just used a regular pencil iron. It’s an 0603 (IIRC) and should be reasonably straightforward to deal with.