NodeMCU freezes after restart/power loss

I have this circuit. It controls three 12V LED strips via NodeMCU. The controller itself is powered via a step-down board 12V->5V. The logic itself works correctly, it is controlled from the assistant. But if you send a reboot signal remotely or simply de-energize, the device simply freezes.

Pressing the physical reset button simply turns on one of the LED strips.

The only thing that will help is to completely disconnect lr7843 from EPS, also disconnect its power supply, then reconnect it, wait for it to load and connect to WiFi, and only then reconnect lr7843. It is very strange to do such manipulations every time.

Optocouplers are installed on the power keys, in theory there can’t be a direct connection there. I think that this is a general minus of the power supply that goes through the Mini360. I don’t see any other reasons for this behavior.

esphome:
  name: "light-control"
  friendly_name: RelayESP

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: "QHvaOCvXhjQkQvQjrSaT10OGmC6HGFC2z0lK5PeyAa4="

ota:
- platform: esphome
  password: "a8a79f4452d1268e60cafb33e75423c8"

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

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Light Control"
    password: "pass"

captive_portal:
udp:  

web_server:
  port: 80
  version: 2

# PWM освещение
output:
  - platform: esp8266_pwm
    pin: D1
    frequency: 1000 Hz
    id: pwm_light1
    min_power: 0.0
    max_power: 1.0
    zero_means_zero: true
  - platform: esp8266_pwm
    pin: D2
    frequency: 1000 Hz
    id: pwm_light2
    min_power: 0.0
    max_power: 1.0
    zero_means_zero: true
  - platform: esp8266_pwm
    pin: D3
    frequency: 1000 Hz
    id: pwm_light3
    min_power: 0.0
    max_power: 1.0
    zero_means_zero: true
# RGB output           
  - platform: esp8266_pwm
    pin: D7
    frequency: 100 Hz
    id: pwm_rgb_green
    min_power: 0.0
    max_power: 1.0
    zero_means_zero: true
    inverted: true    
  - platform: esp8266_pwm
    pin: D6
    frequency: 100 Hz
    id: pwm_rgb_red
    min_power: 0.0
    max_power: 1.0
    zero_means_zero: true
    inverted: true    
  - platform: esp8266_pwm
    pin: D5
    frequency: 100 Hz
    id: pwm_rgb_blue
    min_power: 0.0
    max_power: 1.0
    zero_means_zero: true
    inverted: true       

# PW освещение (контроллеры)
light:
  - platform: monochromatic
    output: pwm_light1
    name: "Свет над столом"
    gamma_correct: 1.4
    id: tablelight
  - platform: monochromatic
    output: pwm_light2
    name: "Основной свет 1"
    gamma_correct: 1.4
    id: mainlight1
  - platform: monochromatic
    output: pwm_light3
    name: "Основной свет 2"
    gamma_correct: 1.4
    id: mainlight2
# RGB strip    
  - platform: rgb
    name: "RGB strip"
    red: pwm_rgb_red
    green: pwm_rgb_green
    blue: pwm_rgb_blue
    effects:
      - random:
          name: "Slow Random Colours"
          transition_length: 30s
          update_interval: 30s
      - random:
          name: "Fast Random Colours"
          transition_length: 4s
          update_interval: 5s
      - pulse:
          name: "Fast Pulse"
          transition_length: 0.5s
          update_interval: 0.5s
          min_brightness: 0%
          max_brightness: 100%
      - pulse:
          name: "Slow Pulse"
          update_interval: 2s
      - pulse:
          name: "Asymmetrical Pulse"
          transition_length:
            on_length: 1s
            off_length: 500ms
          update_interval: 1.5s
      - flicker:
          name: Flicker Effect With Custom Values
          alpha: 95%
          intensity: 1.5%

binary_sensor:

  - platform: gpio
    pin: 
      number: D0
    name: table_light_button
    id: table_light_button
    on_click:
      then:
      - light.toggle: tablelight

    on_press:
      then:
      - if:
          condition: 
            light.is_off: tablelight
          then:
          - delay: 0.5s
          - while:
              condition:
                binary_sensor.is_on: table_light_button
              then:
                - light.dim_relative:
                    id: tablelight
                    relative_brightness: 5%
                    transition_length: 0.1s
                - delay: 0.1s
          else:
          - delay: 0.5s
          - while:
              condition:
                and:
                  - binary_sensor.is_on: table_light_button
                  - light.is_on: tablelight
              then:
                - light.dim_relative:
                    id: tablelight
                    relative_brightness: -5%
                    transition_length: 0.1s
                - delay: 0.1s            
                    
globals:
  - id: totalClick
    type: int
    restore_value: no
    initial_value: "1.4"

number:
  - platform: template
    name: "sliderLight"
    id: "SliderOne"
    step: 1
    min_value: 0
    max_value: 100
    mode: slider
    optimistic: true
    on_value:
       then:
         - light.turn_on:
            id: tablelight
            brightness: !lambda "return x/100;"        

D3 and D4 are strapping pins. If your mosfet module has pull-down on gate the boot fails. So use some other pin than D3 for mosfet (or any other component with pull-down).

1 Like

hmm, I had such an idea, I’ll try to check it.

Tried it. Removed all devices from D0/1/2/3/4, as well as from RX and TX. But the problem persists, it seems it does not even depend on whether something is connected to NodeMCU. It simply does not connect to WiFi and starts a Hot Spot access point. But even if you go in and specify the correct WiFi with a password, the esp still does not connect to WiFi.

I have another project with similar behavior, where the display is connected to the esp. It connects to WiFi probably 1 out of 100 attempts.

Note that other ESP boards that use esphome or WLED connect to WiFi without any problems.

My suggestion was based on strapping pin you used and your post about disconnecting mosfet for recovery.

At this point, you should verify your power sources.
And try without UDP

I thought so too. But it looks like it’s a problem with the firmware itself or WiFi connection. Because I’ve been sitting for half a day trying to flash a completely different esp8266 board, which is powered only by the USB port, and everything repeats. :disappointed_relieved:

How to do this?

Remove that line from your code.

In general, nothing helps, even removing udp, disabling the web server, hot spot… Some problems with connecting to WiFi, I just left the ESP connected to the power supply, after about 20 minutes it just connected itself and works as it should. I don’t understand what the problem is.