Wemos d1 mini not connecting

I’m using a wemos d1 mini to control a 8 chanel relay, after flashing the board via esphome everything works perfectly, the board connects to the wifi and HA, relays work perfectly, but if i remove the board and plug it again it does not connect to wifi and nothing works, i tried plugging it the pc and a normal 5v adaptor. Nothing seems to be working.

Post your yaml file. Be sure to use code tags (<> above). Also, how did you flash the Wemos?

esphome:
  name: main_switch
  platform: ESP8266
  board: d1_mini

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "ZXF1I2NBId+t9MtotO4eUVayKetQo8/H9TFGdowZNAw="

ota:
  password: "7ef311a77fc71135d9991db716d5bcc4"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Main-Switch Fallback Hotspot"
    password: "3AO0jJCccWfE"

captive_portal:
switch:
  - platform: gpio
    pin: D0
    name: "Relay 1"
  - platform: gpio
    pin: D5
    name: "Relay 2"
  - platform: gpio
    pin: D6
    name: "Relay 3"
  - platform: gpio
    pin: D7
    name: "Relay 4"
  - platform: gpio
    pin: D8
    name: "Relay 5"
  - platform: gpio
    pin: D1
    name: "Relay 6"
  - platform: gpio
    pin: D2
    name: "Relay 7"
  - platform: gpio
    pin: D3
    name: "Relay 8"
    

I flashed by directly flashing from the esphome web interface via a usb cable.

You mean tuning it off then on?

I’ve seen sometimes that my ESP’s take a while before being able to connect to wifi again, receiving something equivalent to “unauthorized” from the access point for whatever reason, but they always end up connecting again.

Yes, turning it off and then on again, now its been almost an hour since the esp has been powered and I’m refreshing my router’s web page to see if its getting connected, till now nothing.

Can you see this SSID?

what if you flash it again?

Everything looks fine in the yaml file. Have you tried flashing it again? (That would be my first step).

Here is as basic as you can get for a Wemos D1 Mini. The fast_connect option tells the ESP to go straight to the SSID in the YAML file. The default is that the ESP scans the network for SSID’s which can add a few seconds to the startup. The web_server component installs a small web page that you can access by going to the device IP in your browser.

Do you have another Wemos D1 Mini? They are cheap enough that I buy them 5 at a time. Of the dozens of Wemos D1 Minis in various projects around the house and only one wouldn’t connect to WiFi.

substitutions:
  devicename: xtest
  
esphome:
  name: ${devicename}
  
esp8266:
  board: d1_mini

  
wifi:
  ssid: "Kaywinnet"
  password: !secret wifi_password
  fast_connect: true

logger:
  level: DEBUG

api:

ota:
  safe_mode: True

web_server:
  port: 80   

That is a good test. I’ve never used the fallback AP myself so I never have the AP: component in my yaml files.

Reboot the router.

I’ve tried 3 different boards, rebooted the router, the rpi, everytime the same problem. The fallback wifi also cannot be found.

Forget the Pi. It has nothing to do with the Wemos connecting. Have you tried the minimum YAML code I posted above?

do you have other esp devices connected to the same network?
are they reachable?
if so, I too would suggest to flash a minimum yaml code to the device without anything attached to it (no relays or anything else).
do you see the led on the board blinking when you power it on or resetting it?


I’ve flashed the code you’ve given and showing this error. I’ve just added the password of the wifi additionally.

No, just the one. I’ve just started installing HA in my home, the first one itself is showing problems.

oh ok, starting with HA and ESP for the first time can be tricky.
let’s begin from scratch then.
first past this code into your yaml file for the d1 mini board:

esphome:
  name: testboard
  platform: ESP8266
  board: d1_mini

logger:

api:

ota:

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

web_server:

next create a bin file from this yaml file (I suppose you know how to do this)
when the bin file is created, flash your d1 mini with this firmware.
when it’s done, it should be online after a minute or so.

pls check if you have in your esphome directory in HA the secrets.yaml file?
(there should be a secrets.yaml and a testboard.yaml file)
and are the details inside correct? (SSID and password of your wifi)

When I try this its getting connected, I’ve tried 3 times.

Ok great.
now you can add the rest of your code to the yaml file and install it to your d1 mini through wifi (no need to make a new bin file or reflash it).

captive_portal:

switch:
  - platform: gpio
    pin: D0
    name: "Relay 1"
  - platform: gpio
    pin: D5
    name: "Relay 2"
  - platform: gpio
    pin: D6
    name: "Relay 3"
  - platform: gpio
    pin: D7
    name: "Relay 4"
  - platform: gpio
    pin: D8
    name: "Relay 5"
  - platform: gpio
    pin: D1
    name: "Relay 6"
  - platform: gpio
    pin: D2
    name: "Relay 7"
  - platform: gpio
    pin: D3
    name: "Relay 8"
    

If I turn off the whole system and turn it on again the d1 mini does not connect automatically, then I’ve to flash the .bin file again to make it connect. After repeating this for a couple of times the d1 mini connects automatically even when the whole system is rebooted, whole system means the HA server and the router its connected to. I dont understand why its like that but it seems to work perfectly now.

I must say, sometimes my D1 mini also appears offline in ESPHome, even when the device is actually online and the webserver of the device is reachable.
I therefore have added a restart button option in the yaml file.
if the device appears offline, I then go to it’s url and apply the restart button and the device appears online again in ESPHome.