NodeMCU cannot connect to network after adding sensors

I’ve set up a nodeMCU I have previously used with Tasmota (set up from scratch in ESPHome, didn’t migrate).

With the minimal config

esphome:
  name: shed-multisensor-1
  platform: ESP8266
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "d67357e849abfdae3f830144b3ef3bdb"

wifi:
  ssid: "REDACTED
  password: "REDACTED"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shed-Multisensor-1"
    password: "REDACTED"

captive_portal:

it works fine. But once I add some sensors, it verifies OK, it flashes OK (tried both OTA and with USB), but it never show up on the network. The “new” config just added one sensor and two binary sensors:

esphome:
  name: shed-multisensor-1
  platform: ESP8266
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "d67357e849abfdae3f830144b3ef3bdb"

wifi:
  ssid: "REDACTED
  password: "REDACTED"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shed-Multisensor-1"
    password: "REDACTED"

captive_portal:

sensor:
  - platform: dht
    pin: D1 #GPIO5
    temperature:
      name: "Shed Temperature"
    humidity:
      name: "Shed Humidity"
    update_interval: 60s

binary_sensor:
  - platform: gpio
    pin: D3 #GPIO0
    name: "Shed Motion"
    device_class: motion
  - platform: gpio
    pin: D6 #GPIO12
    name: "Shed Door"
    device_class: door

I’ve tried both setting up as “NodeMCU” and as “generic ESP8266”, and both using the GPIOX and the DX PIN nomenclature, nothing seems to work.

The pins are connected from back when it was used in Tasmota, and it hasn’t been (can’t be, as it’s installed, actually) moved since.

I tried the same on an ESP32-WROOM I had (but with nothing connected to PINS), and that one boots up just fine with either configs.

Any idea what’s wrong?

Perhaps D3 gpio0 is being pulled low at start-up so device stays in flash mode. Pick a different pin or just try it first without that sensor on D3. Not sure if you can do an INPUT_PULLUP on gpio0.

That seems to be it, it boots up if I comment out the PIR sensor on D3. Sigh, then I guess I have some dismantling to do… Well, thanks for the tip!

Is that a common thing for PIN D3? And are there other PINs I should be weary of using?

I second that. I’ve had exactly same problems. If you observe logger output with UART sniffer you’ll see that device “locks-up” when GPIO0 is configured as input. Do you have anything connected on GPIO0?

Try with different GPIO port, or try with internal pullup.

Beware of GPIO0 and 2 - they must be high on bootup, while GPIO15 must be GND.

https://randomnerdtutorials.com/esp8266-pinout-reference-gpios/

Different pinouts in different boards can sometimes cause problems. There is work around for some things.
Try adding mode: INPUT_PULLUP to the line just below pin: D1

Thanks for the pointers. It’s definitely something about that binary_sensor. Unfortunately mode_: INPUT_PULLUP didn’t work, so I dismantled it, and switched to a different PIN. But weirdly, moving it from D3 to either D2 or D7 didn’t work either. Same result, it never shows up on network after flashing.

Currently, I have the below config (ended up leaving the PIR plugged into PIN D2). Obviously the PIR doesn’t work, but the other sensors do. If I uncomment the PIR binary_sensor, it never shows up.

esphome:
  name: shed-multisensor-1
  platform: ESP8266
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: "REDACTED"

wifi:
  ssid: "REDACTED"
  password: "REDACTED"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Shed-Multisensor-1"
    password: "REDACTED"

captive_portal:

sensor:
  - platform: dht
    pin: D1 #GPIO5
    temperature:
      name: "Shed Temperature"
    humidity:
      name: "Shed Humidity"
    update_interval: 60s

binary_sensor:
#  - platform: gpio
#    pin: D2 #GPIO5
#    name: "Shed Motion"
#    device_class: motion
  - platform: gpio
    pin: D6 #GPIO12
    name: "Shed Door"
    device_class: door

Are you sure that your board have pull-up resistors on needed GPIO pins? Try to measure resistance between GPIO and +3.3V - it should be around 10kohm. If not, add external resistors. For basic guide look for ESP201 in google - search for images and you’ll get wiring diagram with all needed resistors.

If resistor is missing board can sometimes even boot if you’re lucky. If pin is “in the air” it can have +3.3V or GND level.
Did you try to connect UART programmer to Rx-Tx pins and observe output at boot with terminal program?

I haven’t looked at any of those things, I just flashed ESPHome, leaving all the wiring in place.

Is that something that would be specific to ESPHome? It worked with no issues for several months using Tasmota (with the same three sensors attached).

If it’s likely to be an ESPHome-specific issue, I’ll try testing those things when I’m back from vacation.

Can you post the serial logs when you try flashing it through USB with the broken configuration? I want to know if it doesn’t boot at all, or whether it only fails to connect to WiFi.

There’s a similar issue reported here, might be the same problem: Wifi handshake failed on sonoff basic R2 with a defined binary_sensor · Issue #2303 · esphome/issues · GitHub

I’ll look into it once I’m back from vacation.

Not really sure what to say here. I tried a few times (was struggling with how to get logs, since I could only do that through HASS UI if I could connect by wireless, wouldn’t accept the USB connection).

After a few attempts just like last time (working if I removed the D2 part of the config), I tried with the Ardiuno app, and connecting to serial monitor se see.

The first time I connected the Arduino serial monitor (immediately after flashing the config with the D2enabled) I did notice a line in the Ardiuno serial monitor saying handshake failed. The next time, I tried the serial monitor just when I started the flash, but then the flash failed (can’t do both at once?). Then I flashed without D2, and again with D2, and it came online.

So not sure what to say… At least it’s working, but it still bugs me a bit. Also that I didn’t save the logs the first time it said handshake failed, sorry about that, I thought I could just reproduce.

I recently updated a RobotDyn NodeM (running as nodemcuv2) at it will not find network. On the very odd occasion it sees the network and then fails to connect. If I remove the switch component using D7 (GPIO12) then the unit works flawlessly. Add a switch component with another port say D8 and it still does not connect to wifi. Remove the binary sensor on D6 and add the switch gpio on D7 and it connects to wifi. Why in the latest update can I not have the sensor and switch platform running simultaneously?