ESPHome presence sensor is slow to connect

I’m having issues with this ESPhome sensor. It simply returns an incrementing number until a HA automation detects the sensor returning a number, whereupon HA toggles a matching input boolean and the sensor stops the incrementing. Looking at the ESPHome page, I see the sensor connects in just a few seconds. However, it takes about 30 seconds for the sensor to report in HA. Is there anything wrong with my code that would allow it to report faster, like the ESPhome page?

esphome:
  name: car_bmw
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "myssid"
  password: "0123456789"
  fast_connect: true
  reboot_timeout: 0s
  
  manual_ip:
    static_ip: 172.16.68.150
    gateway: 172.16.68.1
    subnet: 255.255.255.0

mqtt:
  discovery: true
  discovery_prefix: homeassistant
  client_id: home-assistant-1
  broker: 172.16.68.62
  username: mqtt
  password: mqttpassword
  reboot_timeout: 0s
    
logger:

api:
  password: 'fubar'
  
ota:
  password: 'fubar'
  
binary_sensor:
  - platform: homeassistant
    name: "Garage Opened BMW"
    entity_id: input_boolean.bmw_opened_garage
    id: garage_opened_bmw
    
sensor:
  - platform: template
    name: "BMW"
    lambda: |-
      static int num_cycles = 0;
      static int prev_count = 0;
      int retVal;
      num_cycles += 1;
      if (id(garage_opened_bmw).state)
      {
        retVal = prev_count;
      }
      else
      {
        retVal = num_cycles;
        prev_count = num_cycles;
      }
      return retVal;
    update_interval: 1s