S31 with ESPHome only connects when wired

I am just trying to start with Home Assistant using a few Sonoff S31 plugs. Running HAOS (2024.12.1) on a VM on a qnap. I have been able to wire the TTL converter and flash ESPHome to the units. I then unplug the TTL and plug back in as advised on various tutorials.

When wired, Home Assistant can find the plugs and I can access the s31’s web server and logs. After putting the unit back together and plugging it into the wall, it does not connect to the wifi, no HA response, logs, nothing. I wire it back up to the TTL, plug it back into my computer and it is back again. This is repeatable on all of the (same) switches I bought. What am I missing?

YAML:

esphome:
  name: plug-01
  friendly_name: plug_01

esp8266:
  board: esp01_1m

# Enable logging
logger:

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

ota:
  - platform: esphome
    password: "fml"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Plug-01 Fallback Hotspot"
    password: "fml"

captive_portal:
    
web_server:

# Device Specific Config
uart:
  rx_pin: RX
  baud_rate: 4800
  parity: EVEN

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff S31 Button"
    on_press:
      - switch.toggle: relay
  - platform: status
    name: "Sonoff S31 Status"

sensor:
  - platform: wifi_signal
    name: "Sonoff S31 WiFi Signal"
    update_interval: 60s
  - platform: cse7766
    current:
      name: "Sonoff S31 Current"
      accuracy_decimals: 1
    voltage:
      name: "Sonoff S31 Voltage"
      accuracy_decimals: 1
    power:
      name: "Sonoff S31 Power"
      accuracy_decimals: 1
      id: my_power
  - platform: total_daily_energy
    name: "Sonoff S31 Daily Energy"
    power_id: my_power

switch:
  - platform: gpio
    name: "Sonoff S31 Relay"
    pin: GPIO12
    id: relay
    restore_mode: ALWAYS_ON

time:
  - platform: sntp
    id: my_time

status_led:
  pin:
    number: GPIO13
    inverted: True

I wanted to mention that the s31 connects to wifi when plugged into the wall. I am also able to navigate to a very simple wifi selection page using both the ip and plug_02.local (mdns). I believe this is supposed to be a esphome page. The page also has a section to upload an OTA update, which fails saying “Update Failed: ERROR[4]: Not Enough Space”.

The log through HA’s ESPHome Compiler:

INFO ESPHome 2024.11.3
INFO Reading configuration /config/esphome/plug-02.yaml...
INFO Detected timezone 'America/New_York'
INFO Starting log output from 192.168.0.234 using esphome API
INFO Successfully connected to plug-02 @ 192.168.0.234 in 0.013s
WARNING Can't connect to ESPHome API for plug-02 @ 192.168.0.234: Handshake timed out after 30.0s (TimeoutAPIError)
INFO Trying to connect to plug-02 @ 192.168.0.234 in the background
WARNING plug-02 @ 192.168.0.234: Connection error occurred: plug-02 @ 192.168.0.234: Connection lost
INFO Successfully connected to plug-02 @ 192.168.0.234 in 0.014s
WARNING plug-02 @ 192.168.0.234: Connection error occurred: plug-02 @ 192.168.0.234: Connection lost
INFO Successfully connected to plug-02 @ 192.168.0.234 in 0.013s

From “Update All” function on HA ESPHome dashboard:

Updating /config/esphome/plug-02.yaml
------------------------------------------------------------

INFO ESPHome 2024.11.3
INFO Reading configuration /config/esphome/plug-02.yaml...
INFO Detected timezone 'America/New_York'
INFO Generating C++ source...
INFO Compiling app...
Processing plug-02 (board: esp01_1m; framework: arduino; platform: platformio/[email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 1MB Flash
Dependency Graph
|-- ESPAsyncTCP-esphome @ 2.0.0
|-- ESPAsyncWebServer-esphome @ 3.2.2
|-- DNSServer @ 1.1.1
|-- ESP8266WiFi @ 1.0
|-- ESP8266mDNS @ 1.2
|-- noise-c @ 0.1.6
|-- ArduinoJson @ 6.18.5
RAM:   [====      ]  44.1% (used 36128 bytes from 81920 bytes)
Flash: [=====     ]  53.3% (used 545425 bytes from 1023984 bytes)
========================= [SUCCESS] Took 3.72 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of plug-02.local in mDNS
INFO Connecting to 192.168.0.234 port 8266...
INFO Connected to 192.168.0.234
INFO Uploading /data/build/plug-02/.pioenvs/plug-02/firmware.bin (549584 bytes)
ERROR Error receiving acknowledge version: timed out
=========== [ERROR] /config/esphome/plug-02.yaml ===========

Highly probably this is Access Point page which starts when device can’t connect to configured WiFi.
Did You tried to select right WiFi and enyter password ? Is it connects ?
YAML file looks fine IMHO.

Yes, you are correct. It is the initial wifi access page. Strange thing, even when it is connected to the existing network, it is still broadcasting the fallback. Both showing the same access page.

AFAIK then must not happens. OR it connects to WiFi and show web_server specified frontend OR it not connects to WiFi, then starts fallback AP. Not both same time.