Problems with WiFi range and connection speed for presence detection using ESP32 / ESP8622 boards

I want to put an ESP32 / ESP8622 in our cars so that I can use them for presence detection. E.g. Open the garage door when we arrive home, close the garage door when we turn off the car.

I’m using some ESP8266 dev boards (Adafruit Feather HUZZAH), but I can’t get ESPHome to connect to WiFi fast enough. I did a few test runs today in the car where I drove up to the garage door and had to wait for 5-10 seconds before it connected and started to open.

I’m using the fast_connect: true option for the wifi module, but that didn’t help very much. Is there another way to configure the wifi module to connect even faster? Does it have some exponential back-off logic if it fails to connect repeatedly? I disabled the ap and captive_portal options.

I think the best option might be to get a WEMOS D1 Mini Pro and use an external 2.4G antenna. Maybe it will be able to connect while I’m further away down the road.

Yet another option would be to use the remote transmitter and remote receiver modules. I could set up another ESP32 in the garage to receive the 433MHz signals. That seems like it could be a lot faster and maybe more reliable.

It might be hard to make it secure though, so that someone can’t record/replay a signal and open the garage door. I found this thread, but it looks like no-one has worked on this before. Also this thread.

I have an idea for a protocol - The car ESP32 (C) would send an initial message with it’s unique ID. The garage ESP32 (G) would calculate a random nonce and store it in memory for this ID, and then transmit ID + nonce. C would compute the SHA256 hash of ID + nonce + 32 byte pre-shared key, and then transmit ID + hash. G receives the message and checks if it’s valid. If so, then it clears the nonce from memory, and then updates the HA sensor to “connected”. (Would also add a lot of error-correction and send everything multiple times so it’s very reliable.) Then it would keep repeating this once per second until the car is turned off. If it doesn’t receive any messages for a few seconds, then it updates the sensor to “disconnected.”

Cryptography is always difficult to get right! My initial attempt was vulnerable to replay attacks because I forgot to clear the nonce after it was used. I also added unique IDs in case both of our cars are on at the same time. But I think I’ve come up with something that’s pretty secure and not too hard to implement. Could be a fun project.

Is there a better / easier / existing way to achieve this? Should I just go with the WEMOS D1 Mini Pro + antenna?

I don’t have a garage, but I have a ESP32 in the window facing the front door of out condominium and I use the BLE function of the companion app to detect when we get home.
Most of the times it opens the door when I’m about 10 m from the door.
Sometimes it doesn’t at all, but if I open the app on the phone it will open the door immediately, so I guess it’s the phone that has put the app in the background/sleep.

It has about 90-95% success rate for me. I notice that it doesn’t perform as good for my spouse but probably more than 50%.

1 Like

Interesting, I haven’t tried the BLE option yet. I tried using the GPS presence from the Home Assistant companion app on iOS, but I ran into the same problem where it would be very slow to update sometimes when the app was in the background. The app also set up a sensor that could detect different travel modes, such as walking, biking, driving, etc. So I tried to use “driving” as a condition for opening the garage door, but that wasn’t 100% reliable.

I think it would also be useful to track the cars separately. It would be nice to trigger some automations based on when the car turns on or off. But mainly so that we don’t open the garage door if we are just coming back from a walk. (In that case I would want to unlock the front door, so I might set up the BLE function for that as well.)

Oh… iOS… ouch… Well umm… that makes it a lot more problematic.

In the scenario you described I would use the BLE sensor to detect coming home with car using the connected BT devices (car), and if not connected to the car then open the door. But I’m not sure that is possible in iOS, maybe you know?

Have you seen the ZigBee car tracker? There is a post about it here on the forum.

1 Like

Hmm I think the BLE sensor might not have enough range, since bluetooth can only go about 30 feet. Also sometimes I have to wait a long time for my phone to pick up the car stereo over bluetooth, so I think it might not broadcast regularly enough.

I’ll have to look up the ZigBee car tracker, I might be able to get that to work! I already have a pretty big ZigBee network with a few nodes in the garage.

I actually just received some 433MHz receivers / transmitters this morning, so I might play around with these as well and see if I can get something working.

My WEMOS D1 Mini Pros arrived with antennas. I’ve just tried them out and it’s a little bit better, but I’m still having problems with the connection speed. If I reboot the ESP8266 then it connects to WiFi and updates the status in about 5-6 seconds, even near the end of the driveway. But if it’s already on and I drive down the driveway, then it still takes around 20-30 seconds to connect, and I still end up waiting by the garage door before it starts to open.

I’m trying all the options I can find for the WiFi component, such as configuring a static IP and specifying the BSSIDs for the specific APs + SSIDs that are closest to the driveway:

# No fallback hotspot needed
wifi:
  fast_connect: true

  # Faster connection with static IP
  manual_ip:
    static_ip: "${static_ip}"
    gateway: x.x.x.x
    subnet: 255.255.255.0
    dns1: x.x.x.x
    dns2: 1.1.1.1

  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password
      bssid: xx:xx:xx:xx:xx:xx
      priority: 2
    - ssid: !secret wifi_ssid
      password: !secret wifi_password
      bssid: xx:xx:xx:xx:xx:xx
      priority: 0

Is there anything else I can do to get the ESP8266 to retry the connection as quickly as possible and send the presence update? I might try setting reboot_timeout to 5 seconds, but hopefully that doesn’t damage the chip if it’s constantly rebooting while we’re driving around.


I tried setting reboot_timeout to 3 seconds and it got stuck in an infinite reboot loop, so that’s not enough time to connect. 5 seconds works fine. I might set it 6 seconds just to be safe.