Can't add ESPHome Garage controller to HA

For some reason I cannot get HA to add an ESPhome device. Have tried starting from scratch multiple times. I create the device in ESPHome, download the config, flash with ESPhome flasher and then when it boots, i can see it working fine in ESPhome dashboard but when i try to add the integration for the entities in HA, it fails with an unknown error. I tried restarting HA multiple times. I also upgraded HA to the latest release. Any help would be appreciated.

Here is the error from HA logs:

Logger: aiohttp.server
Source: helpers/aiohttp_client.py:67
First occurred: 12:09:10 AM (2 occurrences)
Last logged: 12:09:12 AM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_protocol.py", line 433, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 85, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 100, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 80, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 235, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 146, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 180, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 72, in wrapper
    result = await method(view, request, data, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 271, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 367, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/esphome/config_flow.py", line 177, in async_step_discovery_confirm
    return await self._async_try_fetch_device_info()
  File "/usr/src/homeassistant/homeassistant/components/esphome/config_flow.py", line 149, in _async_try_fetch_device_info
    and await self._retrieve_encryption_key_from_dashboard()
  File "/usr/src/homeassistant/homeassistant/components/esphome/config_flow.py", line 384, in _retrieve_encryption_key_from_dashboard
    noise_psk = await dashboard.api.get_encryption_key(device["configuration"])
  File "/usr/local/lib/python3.10/site-packages/esphome_dashboard_api/__init__.py", line 103, in get_encryption_key
    config = await self.get_config(configuration)
  File "/usr/local/lib/python3.10/site-packages/esphome_dashboard_api/__init__.py", line 93, in get_config
    return await self.request(
  File "/usr/local/lib/python3.10/site-packages/esphome_dashboard_api/__init__.py", line 54, in request
    return await resp.json()
  File "/usr/src/homeassistant/homeassistant/helpers/aiohttp_client.py", line 67, in json
    return await super().json(*args, loads=loads, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/aiohttp/client_reqrep.py", line 1120, in json
    return loads(stripped.decode(encoding))
orjson.JSONDecodeError: unexpected character: line 1 column 3007 (char 3006)

Additional error:

Logger: aioesphomeapi.connection
Source: runner.py:179
First occurred: 12:09:09 AM (2 occurrences)
Last logged: 12:09:12 AM

192.168.10.125: Connection error occurred: Connection requires encryption

Here is the ESP config:

esphome:
  name: garage-door
  friendly_name: Garage Door

esp8266:
  board: esp01_1m

# Enable logging
logger:

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

ota:
  password: "XXXXXXXXX"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Garage-Door Fallback Hotspot"
    password: "XXXXXXXXXX"

captive_portal:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: False
    name: "Garage Door"
    device_class: garage_door
    
  - platform: template
    name: "Garage Door Car Present"
    device_class: presence
    lambda: |-
      if (id(ultrasonic_sensor1).state < 1.5) {
        // car is in the garage
        return true;
      } else {
        // no car
        return false;
      }   
      
switch:
  - platform: gpio
    pin: GPIO12
    id: relay
  - platform: template
    icon: "mdi:arrow-up-down-bold-outline"
    name: "Garage Door"
    turn_on_action:
    - switch.turn_on: relay
    - delay: 500ms
    - switch.turn_off: relay

sensor:
  - platform: ultrasonic
    id: ultrasonic_sensor1
    trigger_pin: GPIO05
    echo_pin: GPIO04
    name: "Garage Door Car"
    update_interval: 30s
    filters:
      filter_out: nan
    timeout: 9m

In ESP device logs:

[00:34:57][W][api.connection:071]: 192.168.10.250: Socket operation failed: BAD_INDICATOR errno=11

Start by rebooting HA, if that fails remove the device from the integration and re-add - maybe the encryption key doesn’t match.

Tried rebooting HA. The device isn’t in HA configurations. It never got that far.
It is insane. I grabbed another ESP8266 board, created a new config and same issue. They show online in ESPhome and show all is working well but I just can’t get them added to HA through integrations. In ESPhome, both these devices show this when I click show API key:

Maybe remove the encryption key? You say though that it’s not even getting discovered - very strange.

Sorry for the poor wording. Here is the first screenshot and then the next is the error.



Below is what it shows in ESPhome. The BT Proxy works fine and is added to integrations.

Starting a new config and excluding the encryption key was the trick ! Thanks for the comment !!