Help understanding why my device doesn't connect to the HA API

I have a Sonoff Mini (ESP8266) plugged into a GFI outlet in my basement. (The purpose is to monitor when the GFI trips).

The yaml file has

web_server:
  port 80:

I can edit and upload to the Sonoff wirelessly.
I can control the Sonoff (on/off).
But it presents in /developer tools/states as “Unavailable”

Here is the device yaml file, and following that are my two packages. (I use packages for the code that appears in all of my yaml files. It greatly reduces clutter).


substitutions:
  device_name: gfi
  friendly_name: gfi

packages:
  wifi: !include common/wifi.yaml
  device_base: !include common/esp8266.yaml  


status_led:
  pin:
    number: 13

web_server:
  port: 80

 
##############################
# Sonoff Basic peripherals

# Virtual switch GPI12  
switch:
  - platform: gpio
    name: ${device_name}
    pin:
      number: 12
      mode: output
    id: relay12
    restore_mode: always on
    

    
binary_sensor:
  - platform: status
    name: ${device_name} Status

  # Physical Button on GPIO0
  - platform: gpio
    pin: 
      number: 0
      inverted: False
      mode: INPUT_PULLUP
    name: ${device_name} button
    internal: true
    on_press:
      - switch.toggle: relay12
      
  # Physical Button on GPIO14  
  - platform: gpio
    pin: 
      number: 14
      inverted: False
      mode: INPUT_PULLUP
    name: ${device_name} GPIO14 Button
    on_press:
      then:
      - switch.toggle: relay12
    on_release:
      then:
      - switch.toggle: relay12

This is the esp8266.yaml package:

################################################
#esp8266
#
#Useage:
#packages:
#  wifi: !include common/wifi.yaml
#  device_base: !include common/esp8266.yaml
#
#In the project file, you can override the default board type.
#For example:
#esp8266:
#  board: esp01_1m    #Sonoff Basic and Mini (DEFAULT)
#  board: d1_mini     #Wemos D1 Mini
#  board: nodemcuv2   #NodeMCU
#
################################################

esphome:
  name: ${device_name}

esp8266:
  board: esp01_1m
  framework:
    version: recommended
    
# Logger level "debug" is needed to get 1-Wire addresses, like the ds18b20.
logger:
  level: DEBUG

api:

ota:
  safe_mode: True

This is the wifi.yaml package:

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

sensor:
  - platform: wifi_signal
    name: ${friendly_name} WiFi Level
    id: ${friendly_name}_WiFi_level
    update_interval: 300s

# Get the WiFi details
text_sensor:
  - platform: wifi_info
    ip_address:
      name: ${friendly_name} IP
    ssid:
      name: ${friendly_name} SSID
    mac_address:
      name: ${friendly_name} Mac Address

This particular Sonoff Basic has been working for many months. The only change is that I changed to a new router. I don’t think that is my problem since I can upload to it and control it through the web interface.

Any ideas would be appreciated.

My api: section have a parameter for encryption and under that a key.
The api: section is the one enabling the HA interconnection.

Have you tried removing the integration device and re-adding it?

I don’t use API keys because I am not security paranoid. All you need for the API to connect to Home Assistant is the api: component. I have some 76 WiFi devices on my network, at least half are ESPHome devices. None of them have the api key and they work just fine. And have for many months.

I will, however, try adding a key to this one to test.

Made no difference.

I changed the title to be more accurate.
Can someone help me understand why a device won’t connect to the Home Assistant API?

AFAIK ESPHome connects to its devices using [device_name].local domains - i had some issues doing shenanigans with changing device names, because EH couldn’t find them anymore.
If you recently changed your router, it may have some setting to block .local domains. See if you can open gfi.local on your phone/computer.

EDIT: after posting i re-read the OP and saw that you can upload to it just fine. I think it invalidates my theory.

Thanks for trying.
Here is the log file output:

INFO ESPHome 2023.11.4
INFO Reading configuration /config/esphome/gfi.yaml...
INFO Starting log output from gfi.local using esphome API
INFO Successfully connected to gfi in 0.104s
INFO Successful handshake with gfi in 0.044s

... Skip the purple stuff ...

[17:34:46][D][api:102]: Accepted 192.168.1.57
[17:34:46][W][api.connection:106]: : Reading failed: BAD_INDICATOR errno=11
[17:35:46][D][api:102]: Accepted 192.168.1.57
[17:35:46][W][api.connection:106]: : Reading failed: BAD_INDICATOR errno=11
[17:36:46][D][api:102]: Accepted 192.168.1.57
[17:36:46][W][api.connection:106]: : Reading failed: BAD_INDICATOR errno=11
[17:36:49][D][sensor:093]: 'gfi WiFi Level': Sending state -78.00000 dBm with 0 decimals of accuracy

I am baffled.