ESP8266 status LED error when using switch: and light.addressable_set:

Hi all,

My ESP8266 flashes error (fast flashing) on boot up and reboots constantly. It’s started once I added code for setting a WS2811/12 LED on/off then controlling a relay. The debug output doesn’t start either. I’m thinking I have mangled the code in some way that allows it to compile, but the code that’s comes out must be bad in some way.

The code runs when I block out the whole switch: section so I’m thinking the problem is in there. The relays worked until I added the code for the WS2812 LED’s.

It’s probably simple (I’m only new to YAML/ESPHome), but after 2 days of trying to get it to work I have hit a wall…

Can anyone help?

esphome:
  name: ha-node1

esp8266:
  board: esp12e

# Enable logging
logger:

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

ota:
  password: " "

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.2.61
    gateway: 192.168.2.254
    subnet: 255.255.255.0

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

captive_portal:


 # Use the blue LED in the device as a status LED, which will blink if there are warnings (slow) or errors (fast)
status_led:
  pin:
    number: GPIO5
    inverted: True

# Status Lights
light:
  - platform: neopixelbus
    type: GRB
    variant: WS2811
    pin: GPIO3
    num_leds: 8
    name: "Status Light"
    id: Status_Light
    method:
      type: esp8266_dma
  - platform: partition
    name: "Partition Light 1"
    segments:
      - id: Status_Light
        from: 0
        to: 7
        
# Four relay outputs, exposed as switches in Home Assistant
switch:
  - platform: gpio
    pin: GPIO16
    name: Relay1
    id: relay1
    on_turn_on:
    - light.addressable_set:
        id: Status_Light
        range_from: 1
        range_to: 2
        red: 50%
        green: 0%
        blue: 0%
      
    on_turn_off:
    - light.addressable_set:
        id: Status_Light
        range_from: 1
        range_to: 2
        red: 0%
        green: 0%
        blue: 0%
        
  - platform: gpio
    pin: GPIO14
    name: Relay2
    id: relay2
    on_turn_on:
      - light.addressable_set:
          id: Status_Light
          range_from: 2
          range_to: 2
          red: 50%
          green: 0%
          blue: 0%
    on_turn_off:
      - light.addressable_set:
          id: Status_Light
          range_from: 2
          range_to: 2
          red: 0%
          green: 0%
          blue: 0%
        
  - platform: gpio
    pin: GPIO12
    name: Relay3
    id: relay3
    on_turn_on:
      - light.addressable_set:
          id: Status_Light
          range_from: 3
          range_to: 3
          red: 50%
          green: 0%
          blue: 0%
    on_turn_off:
      - light.addressable_set:
          id: Status_Light
          range_from: 3
          range_to: 3
          red: 0%
          green: 0%
          blue: 0%
        
  - platform: gpio
    pin: GPIO13
    name: Relay4
    id: relay4
    on_turn_on:
      - light.addressable_set:
          id: Status_Light
          range_from: 4
          range_to: 4
          red: 50%
          green: 0%
          blue: 0%
    on_turn_off:
      - light.addressable_set:
          id: Status_Light
          range_from: 4
          range_to: 4
          red: 0%
          green: 0%
          blue: 0%

You are using gpio16 for relay. This pin is used for sleep wakeup and should be high at boot. Maybe it’s pulled down via external resistor (the one who drives relay transistor) and prevents from correct booting?
It’s not too good idea to use this pin unless you have no other options.

The board is one of those 4 relay boards from Aliexpress and has worked great so far. The pin is in the correct state for bootup and the code I have used before works well, even for the relay driven by GPIO16.

It will run without any of the light.addressable stuff so I suspect I have just done some bad code…

Also how are you powering this?

Do you have enough power available for all the LEDs, the relay and the ESP?

The board is supplied by a 12V 1Amp plug pack. I can get the code to run fine with the LED’s all on if I don’t try driving individual lights on the 8 LED strip. I could change the color etc, but only if I control them all as a group. It went wrong when I tried to control them separately.

Other thing is, am I using the right method for controlling the WS2812 LED’s individually? I looked for code that could showed a more direct indexing of a particular light but couldn’t find any. Using range_to: and range_from: seemed a little excessive to just change one LED.

Try to flash bin file via uart again. It happened to me before that all of the suddena after OTA update board didn’t work. Reflashing via uart helped. Coulnd’t find a reason, i guess it was an error when transferring update file via OTA…?

Thanks for the suggestion. I tried it but the result was the same :slightly_frowning_face:

Whoa, just got debug info from the serial debug (WiFi never worked). It sent all sorts of stuff:

Hard resetting via RTS pin… INFO Successfully uploaded program. INFO Starting log output from /dev/ttyUSB0 with baud rate 115200 [18:10:52]rll\x9c\x9e|\x8cl\xe0|\x8cl\xecb|\x8e\x82\xec\x92r\x92b\x8cb\x8c\xf2nn\x9elnn\x9c\xe2\xecbp\x8c\x8elrlrlp\xf2n\xe0\x82l\x8c\x9cbn\xe2|\xec\x8e\x8eb\x8c\xf2nn\xeel\x8c\x8el\x90nn\x8elnr\x8e\x92\x92nrr\x92p\xf2n\xe0r\x8c\x9c\x9c\x9c\x80\x8cbn\xe2|\x8eb\x8c\xf2nn\xee\x8el\x90nn\x8elnr\x8e\x92\x92nrlr\x92\x92nrl\x9c쎜\xec\x8el\xfc\x82n\x9cl[I][logger:243]: Log initialized [18:10:52][C][status_led:014]: Setting up Status LED… [18:10:52][C][ota:461]: There have been 0 suspected unsuccessful boot attempts. [18:10:52][I][app:029]: Running through setup()… [18:10:52][C][switch.gpio:011]: Setting up GPIO Switch ‘Relay1’… [18:10:52][D][switch:017]: ‘Relay1’ Turning OFF. [18:10:52][D][switch:037]: ‘Relay1’: Sending state OFF [18:10:52] [18:10:52]--------------- CUT HERE FOR EXCEPTION DECODER --------------- [18:10:52] [18:10:52]Exception (29): WARNING Exception type: Access to invalid address: STORE (wild pointer?) [18:10:52]epc1=0x4022050f epc2=0x00000000 epc3=0x00000000 excvaddr=0x000000c8 depc=0x00000000 WARNING Decoded 0x4022050f: esphome::light::AddressableSet<>::play() [18:10:52] [18:10:52]>>>stack>>> WARNING Found stack trace! Trying to decode it [18:10:52] [18:10:52]ctx: cont [18:10:52]sp: 3ffffad0 end: 3fffffc0 offset: 0190 [18:10:52]3ffffc60: 00000000 3fff1e34 3fff14cc 402204e5 WARNING Decoded 0x402204e5: esphome::light::AddressableSet<>::play() [18:10:52]3ffffc70: 4023364c 3fff14cc 00000001 00000002 WARNING Decoded 0x4023364c: AsyncServer::setNoDelay(bool) [18:10:52]3ffffc80: 000000ff 00000045 3ffe8d6a 4021ded0 WARNING Decoded 0x4021ded0: esphome::esp_log_printf_(int, char const*, int, __FlashStringHelper const*, …) [18:10:52]3ffffc90: 3ffffcc0 3ffffcb0 00000010 3fff2520 [18:10:52]3ffffca0: 00000000 3fff1e1c 3fff1e34 402321c0 WARNING Decoded 0x402321c0: esphome::Action<>::play_complex() [18:10:52]3ffffcb0: 3fff2774 3fff277c 3fff1e2c 4023228a WARNING Decoded 0x4023228a: ZN7esphome10ActionListIJEE4playEv$isra$0 at main.cpp [18:10:52]3ffffcc0: 3fff1ca8 3ffe8cd9 00000010 4021e8a8 WARNING Decoded 0x4021e8a8: std::Function_handler<void (bool), esphome::switch::SwitchTurnOffTrigger::SwitchTurnOffTrigger(esphome::switch::Switch*)::{lambda(bool)#1}>::M_invoke(std::Any_data const&, bool&&) [18:10:52]3ffffcd0: 3fff1d20 00000000 3fff1c9c 402183dc WARNING Decoded 0x402183dc: esphome::switch::Switch::publish_state(bool) [18:10:52]3ffffce0: 3fff1d00 00000000 3fff1c9c 40211a80 WARNING Decoded 0x40211a80: esphome::esp8266::ESP8266GPIOPin::digital_write(bool) [18:10:52]3ffffcf0: 3fff1d20 00000000 3fff1c9c 4021233c WARNING Decoded 0x4021233c: esphome::gpio::GPIOSwitch::write_state(bool) [18:10:52]3ffffd00: 3ffffd50 00000022 175663dd 4021ded0 WARNING Decoded 0x4021ded0: esphome::esp_log_printf(int, char const*, int, _FlashStringHelper const*, …) [18:10:52]3ffffd10: 3ffffd40 3ffffd30 00000010 4021ded0 WARNING Decoded 0x4021ded0: esphome::esp_log_printf(int, char const*, int, _FlashStringHelper const*, …) [18:10:52]3ffffd20: 3ffffd40 3ffffd30 00000010 3fff2520 [18:10:52]3ffffd30: 3fff1d20 3fff0b0c 3fff1c9c 3fff2520 [18:10:52]3ffffd40: 3fff1ca8 00000000 3fff1c9c 3fff2520 [18:10:52]3ffffd50: 3fff1d20 00000004 3fff1c9c 402182e2 WARNING Decoded 0x402182e2: esphome::switch::Switch::turn_off() [18:10:53]3ffffd60: 00000000 00000004 3fff1c9c 40212090 WARNING Decoded 0x40212090: esphome::gpio::GPIOSwitch::setup() [18:10:53]3ffffd70: 3fff0001 00000003 3ffefa28 402209c8 WARNING Decoded 0x402209c8: non-virtual thunk to esphome::neopixelbus::NeoPixelBusLightOutputBase<NeoEsp8266DmaMethodBase, NeoRgbFeature>::setup() [18:10:53]3ffffd80: 00000000 00000004 3ffefa28 402120cb WARNING Decoded 0x402120cb: non-virtual thunk to esphome::gpio::GPIOSwitch::setup() [18:10:53]3ffffd90: 3fff0fec 00000002 3ffefa28 40231ebc WARNING Decoded 0x40231ebc: esphome::Component::call_setup() [18:10:53]3ffffda0: 3fff14b0 3ffffdc0 00000011 40231f40 WARNING Decoded 0x40231f40: esphome::Component::call() [18:10:53]3ffffdb0: 3fff14d0 00000003 3ffefa28 4021d3ed WARNING Decoded 0x4021d3ed: esphome::Application::setup() [18:10:53]3ffffdc0: 00000011 00000011 3fff270c 3fff1484 [18:10:53]3ffffdd0: 00000014 402201b0 00000020 40101040 WARNING Decoded 0x402201b0: setup WARNING Decoded 0x40101040: malloc [18:10:53]3ffffde0: 00000000 00000000 00000008 3fff1484 [18:10:53]3ffffdf0: 3ffefadc 3ffefaf4 00000000 402201d8 WARNING Decoded 0x402201d8: setup [18:10:53]3ffffe00: 02a8c001 02a8c03d fffffffe 00000000 [18:10:53]3ffffe10: 00000000 feefef00 feefeffe feefeffe [18:10:53]3ffffe20: 3fff1294 00000019 0000001e 00000000 [18:10:53]3ffffe30: 00000000 00000000 00000000 00000000 [18:10:53]3ffffe40: 3ffffe48 0000000c 61455361 734b7964 [18:10:53]3ffffe50: 36546e56 00000000 00000000 00000000 [18:10:53]3ffffe60: 02a8c001 02a8c03d fffffffe 00000000 [18:10:53]3ffffe70: 00000000 00000000 3ffffe80 00000006 < [18:10:53]3ffffe80: 4168614e 00003250 00000000 00000000 [18:10:53]3ffffe90: 00000000 00000000 3ffffea0 0000000c < [18:10:53]3ffffea0: 4168614e 71312150 65337732 00000000 [18:10:53]3ffffeb0: 00000000 00000000 02a8c001 02a8c03d [18:10:53]3ffffec0: fffffffe 00000000 00000000 00000000 [18:10:53]3ffffed0: 3fff1494 3fff1498 3fff1498 4c003479 [18:10:53]3ffffee0: 74686700 10ad1500 96908c20 10c292cb [18:10:53]3ffffef0: 3fffff68 00000001 eaa57ae9 b8f3369c [18:10:53]3fffff00: 97fb7562 10ad1572 96908c20 10c292cb [18:10:53]3fffff10: fad7789d 9647aefe eaa57ae9 b8f3369c [18:10:53]3fffff20: 97fb7562 10ad1572 96908c20 10c292cb [18:10:53]3fffff30: 3ffffef0 00000001 feefeffe feefeffe [18:10:53]3fffff40: feefeffe feefeffe feefeffe feefeffe [18:10:53]3fffff50: feefeffe feefeffe feefeffe feefeffe [18:10:53]3fffff60: feefeffe feefeffe 3fff264c feefeffe [18:10:53]3fffff70: 3fff18c8 3fff1b04 3ffefa70 ffffffff [18:10:53]3fffff80: 00000008 3fffff68 feefeffe feefeffe [18:10:53]3fffff90: feefeffe feefeffe feefeffe 3ffefe98 [18:10:53]3fffffa0: 3fffdad0 00000000 3ffefe84 4022e35c WARNING Decoded 0x4022e35c: loop_wrapper() at core_esp8266_main.cpp [18:10:53]3fffffb0: feefeffe feefeffe 3ffe8610 40100511 WARNING Decoded 0x40100511: cont_wrapper [18:10:53]<<<stack<<< [18:10:53] [18:10:53]--------------- CUT HERE FOR EXCEPTION DECODER --------------- [18:10:53] [18:10:53] ets Jan 8 2013,rst cause:2, boot mode:(3,6) [18:10:53] [18:10:53]load 0x4010f000, len 3460, room 16 [18:10:53]tail 4 [18:10:53]chksum 0xcc [18:10:53]load 0x3fff20b8, len 40, room 4 [18:10:53]tail 4 [18:10:53]chksum 0xc9 [18:10:53]csum 0xc9 [18:10:53]v0007f070 [18:10:53]~ld [18:10:53][I][logger:243]: Log initialized [18:10:53][C][status_led:014]: Setting up Status LED… [18:10:53][C][ota:461]: There have been 1 suspected unsuccessful boot attempts. [18:10:53][I][app:029]: Running through setup()… [18:10:53][C][switch.gpio:011]: Setting up GPIO Switch ‘Relay1’… [18:10:53][D][switch:017]: ‘Relay1’ Turning OFF. [18:10:53][D][switch:037]: ‘Relay1’: Sending state OFF [18:10:53] [18:10:53]--------------- CUT HERE FOR EXCEPTION DECODER --------------- [18:10:53] [18:10:53]Exception (29): WARNING Exception type: Access to invalid address: STORE (wild pointer?) [18:10:53]epc1=0x4022050f epc2=0x00000000 epc3=0x00000000 excvaddr=0x000000c8 depc=0x00000000 WARNING Decoded 0x4022050f: esphome::light::AddressableSet<>::play()

It seems to repeat after this…

Looking at the debug info I saw the line [18:10:53][D][switch:037]: ‘Relay1’: Sending state OFF. So I commented out that block so relay2 would be the first relay the program would get to and now it’s relay2 that is the relay mentioned. I wonder if there is some kind of underlying issue with switch: and using light.addressable_set: that doesn’t work when sending state info to HA?

I have removed the LED code. Not being someone who can program very well, I can see this is way beyond my skill set, and after 20h of digging around forums it would seem C++ knowledge would be needed to be able to debug this further…

Replying to an old post as I had the same issue with the Light addressable_set call causing a boot loop, with the same error as the OP :

I don’t know the root cause of this error, but I found that if I prevented calls to addressable_set duirng boot/initialisation, then the error doesn’t occur. I did this with a global boolean with an initial value set to false, and only set to true at the end of the on_boot script. I then test this global in the operations that were causing the calls to addressable_set.

It’s not pretty, there’s probably more elegant ways, and it doesn’t solve the underlying issue, but hopefully this may help someone else having the same problem…

esphome:
  on_boot:
    - lambda: "id(boot_completed) = true;"
    
globals:
  # This is used to stop a boot loop caused by addressable_set
  - id: boot_completed
    type: bool
    restore_value: no
    initial_value: '0'  # false

binary_sensor:
  # Physical button that toggles a light output
  - platform: gpio
    pin:
      number: GPIO0
      mode:
        input: true
        pullup: true
      inverted: true
    id: button_1
    on_press:
      then:
        - light.toggle: light_1

output:
  # GPIO output for the light
  - platform: gpio
    pin: GPIO12
    id: relay_1

light:
  # Addressable RGB LED
  - platform: neopixelbus
    id: leds
    type: RGB
    variant: WS2811
    pin: GPIO13
    num_leds: 1

  # Light connected to the relay_1 output
  - platform: binary
    name: "Light 1"
    id: light_1
    output: relay_1
    on_turn_on:
      - if:
          # addressable_set seems to cause issues during boot, so ignore this during boot
          condition:
            lambda: 'return id(boot_completed);'
          then:
            - light.addressable_set:
                id: leds
                range_from: 0
                range_to: 0
                red: 0%
                green: 100%
                blue: 0%
    on_turn_off:
      - if:
          # addressable_set seems to cause issues during boot, so ignore this during boot
          condition:
            lambda: 'return id(boot_completed);'
          then:
            - light.addressable_set:
                id: leds
                range_from: 0
                range_to: 0
                red: 100%
                green: 100%
                blue: 100%