Can't connect to ESP. Please make sure your YAML file contains an 'api:' line

I keep getting the noted error.

  1. I can ping the device
  2. Using Device Builder, I can visit the device and turn it on/off (switch)
  3. yaml file has an api line with encryption
  4. I can type the ip address in a browser and I get the device website
  5. I am on the latest version of HA and ESPHome

I’m not sure what else to do to get Homeassistant to see the device.

yaml:

esphome:
  name: gatecontrol
  friendly_name: GateControl

esp8266:
  board: esp01_1m

# Enable logging
logger:
  

# Enable Home Assistant API
api:
  encryption:
    key: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

ota:
  - platform: esphome
    password: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

wifi:
  ssid: !secret wifi_ssid 
  password: !secret wifi_password 
  use_address: 10.0.0.11
  manual_ip:
    static_ip: 10.0.0.11
    gateway: 10.0.0.1
    subnet: 255.255.255.0
    dns1: 10.0.0.1


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Gatecontrol Fallback Hotspot"
    password: "xxxxxxxxxxx"

captive_portal:

switch:
  - platform: gpio
    pin: GPIO0
    id: relay
    name: "Gate Cycle"
    icon: "mdi:gate"
    on_turn_on:
      - switch.turn_on: relay
    on_turn_off:
      - switch.turn_off: relay
  
web_server:
  port: 80

Remove the use_address line from wifi.
Control your api key.

I tried that too, same result, so I put it back.

I was reading a long post with same issue and someone suggested the yaml file name should be the same as device name. Im going to try that tomorrow…

You can add the device manually to home assistant. You might have MDNS problems or something.

You have other devices that work / use different vlans ?

Sitting with similar issue on multiple devices. Only diffirence is I can’t ping then or access the web interface for the device.
What is strange is that it shows online in ESPHome builder page. I also removed one or 2 device, reboot Home assistant and they come up as new device discovered. But not able to add them back in again. Just gives me an error: “Can’t connect to ESP. Please make sure your YAML file contains an ‘api:’ line.”
Worked perfectly with esphome 2025.3.2, since updating to 2025.3.3 problems started. Went back to 2025.3.2 and problem still there.