ESPHome + ESP8266 D1 + multiple MCP23017

I have some issues with uploading OTA and flashing via ESP Home Flasher code presented below. This issue starts in case of trying to use more than three MCP23017 in setup. Setup for two MCP23017 works without any issue. MCP23017 are used as port expanders (outputs) for handling multiple relays. Code compiles properly according to logs, but uploading to device leads to failure. I cannot identify source of this problem therefore I am raising this topic as bug report.

esphome:
  name: przekazniki1
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: 
  password: 

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: 

ota:
  password: 

web_server:
  port: 80

i2c:
  sda: D1
  scl: D2
  scan: True
 
mcp23017:
  - id: 'mcp23017_hub1'
    address: 0x20
  - id: 'mcp23017_hub2'
    address: 0x21
  - id: 'mcp23017_hub3'
    address: 0x22

switch:
#mcp23017_hub1
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 8
    mode: OUTPUT
    inverted: True
  id: relay1
- platform: template
  name: relay_channel_1
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay1
    - delay: 500ms
    - switch.turn_off: relay1
  turn_off_action:
    - switch.turn_off: relay1

- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 9
    mode: OUTPUT
    inverted: True
  id: relay2
- platform: template
  name: relay_channel_2
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay2
    - delay: 500ms
    - switch.turn_off: relay2
  turn_off_action:
    - switch.turn_off: relay2

- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 10
    mode: OUTPUT
    inverted: True
  id: relay3
- platform: template
  name: relay_channel_3
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay3
    - delay: 500ms
    - switch.turn_off: relay3
  turn_off_action:
    - switch.turn_off: relay3

- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 11
    mode: OUTPUT
    inverted: True
  id: relay4
- platform: template
  name: relay_channel_4
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay4
    - delay: 500ms
    - switch.turn_off: relay4
  turn_off_action:
    - switch.turn_off: relay4
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 12
    mode: OUTPUT
    inverted: True
  id: relay5
- platform: template
  name: relay_channel_5
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay5
    - delay: 500ms
    - switch.turn_off: relay5
  turn_off_action:
    - switch.turn_off: relay5
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 13
    mode: OUTPUT
    inverted: True
  id: relay6
- platform: template
  name: relay_channel_6
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay6
    - delay: 500ms
    - switch.turn_off: relay6
  turn_off_action:
    - switch.turn_off: relay6

- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 14
    mode: OUTPUT
    inverted: True
  id: relay7
- platform: template
  name: relay_channel_7
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay7
    - delay: 500ms
    - switch.turn_off: relay7
  turn_off_action:
    - switch.turn_off: relay7
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 15
    mode: OUTPUT
    inverted: True
  id: relay8
- platform: template
  name: relay_channel_8
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay8
    - delay: 500ms
    - switch.turn_off: relay8
  turn_off_action:
    - switch.turn_off: relay8
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 7
    mode: OUTPUT
    inverted: True
  id: relay9
- platform: template
  name: relay_channel_9
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay9
    - delay: 500ms
    - switch.turn_off: relay9
  turn_off_action:
    - switch.turn_off: relay9
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 6
    mode: OUTPUT
    inverted: True
  id: relay10
- platform: template
  name: relay_channel_10
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay10
    - delay: 500ms
    - switch.turn_off: relay10
  turn_off_action:
    - switch.turn_off: relay10
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 5
    mode: OUTPUT
    inverted: True
  id: relay11
- platform: template
  name: relay_channel_11
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay11
    - delay: 500ms
    - switch.turn_off: relay11
  turn_off_action:
    - switch.turn_off: relay11
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 4
    mode: OUTPUT
    inverted: True
  id: relay12
- platform: template
  name: relay_channel_12
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay12
    - delay: 500ms
    - switch.turn_off: relay12
  turn_off_action:
    - switch.turn_off: relay12
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 3
    mode: OUTPUT
    inverted: True
  id: relay13
- platform: template
  name: relay_channel_13
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay13
    - delay: 500ms
    - switch.turn_off: relay13
  turn_off_action:
    - switch.turn_off: relay13
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 2
    mode: OUTPUT
    inverted: True
  id: relay14
- platform: template
  name: relay_channel_14
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay14
    - delay: 500ms
    - switch.turn_off: relay14
  turn_off_action:
    - switch.turn_off: relay14
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 1
    mode: OUTPUT
    inverted: True
  id: relay15
- platform: template
  name: relay_channel_15
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay15
    - delay: 500ms
    - switch.turn_off: relay15
  turn_off_action:
    - switch.turn_off: relay15
    
- platform: gpio
  pin:
    mcp23017: mcp23017_hub1
    number: 0
    mode: OUTPUT
    inverted: True
  id: relay16
- platform: template
  name: relay_channel_16
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay16
    - delay: 500ms
    - switch.turn_off: relay16
  turn_off_action:
    - switch.turn_off: relay16

#mcp23017_hub2
- platform: gpio
  pin:
    mcp23017: mcp23017_hub2
    number: 8
    mode: OUTPUT
    inverted: True
  id: relay17
- platform: template
  name: relay_channel_17
  icon: mdi:electric-switch
  turn_on_action:
    - switch.turn_on: relay17
    - delay: 500ms
    - switch.turn_off: relay17
  turn_off_action:
    - switch.turn_off: relay17

AND SO ON FOR NEXT RELAYS

Logs from ESP Home Flasher:

Using 'COM6' as serial port.
Connecting....%)Writing at 0x00048000... (100 %)Wrote 457904 bytes (306616 compressed) at 0x00000000 in 7.5 seconds (effective 488.6 kbit/s)...
Hash of data verified.

Leaving...
Hard Resetting...
Done! Flashing is complete!

Showing logs:
[21:07:35][I][logger:166]: Log initialized
[21:07:35][C][ota:366]: There have been 2 suspected unsuccessful boot attempts.
[21:07:35][I][app:029]: Running through setup()...
[21:07:35][C][mcp23017:010]: Setting up MCP23017...
[21:07:35][W][i2c:070]: Received NACK on transmit of address 0x20
[21:07:35][E][component:092]: Component was marked as failed.
[21:07:35][C][mcp23017:010]: Setting up MCP23017...
[21:07:35][W][i2c:070]: Received NACK on transmit of address 0x21
[21:07:35][E][component:092]: Component was marked as failed.
[21:07:35][C][mcp23017:010]: Setting up MCP23017...
[21:07:35][W][i2c:070]: Received NACK on transmit of address 0x22
[21:07:35][E][component:092]: Component was marked as failed.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay1'...
[21:07:35][D][switch:025]: 'relay1' Turning OFF.
[21:07:35][D][switch:045]: 'relay1': Sending state OFF
[21:07:35][D][switch:025]: 'relay1' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay2'...
[21:07:35][D][switch:025]: 'relay2' Turning OFF.
[21:07:35][D][switch:045]: 'relay2': Sending state OFF
[21:07:35][D][switch:025]: 'relay2' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay3'...
[21:07:35][D][switch:025]: 'relay3' Turning OFF.
[21:07:35][D][switch:045]: 'relay3': Sending state OFF
[21:07:35][D][switch:025]: 'relay3' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay4'...
[21:07:35][D][switch:025]: 'relay4' Turning OFF.
[21:07:35][D][switch:045]: 'relay4': Sending state OFF
[21:07:35][D][switch:025]: 'relay4' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay5'...
[21:07:35][D][switch:025]: 'relay5' Turning OFF.
[21:07:35][D][switch:045]: 'relay5': Sending state OFF
[21:07:35][D][switch:025]: 'relay5' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay6'...
[21:07:35][D][switch:025]: 'relay6' Turning OFF.
[21:07:35][D][switch:045]: 'relay6': Sending state OFF
[21:07:35][D][switch:025]: 'relay6' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay7'...
[21:07:35][D][switch:025]: 'relay7' Turning OFF.
[21:07:35][D][switch:045]: 'relay7': Sending state OFF
[21:07:35][D][switch:025]: 'relay7' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay8'...
[21:07:35][D][switch:025]: 'relay8' Turning OFF.
[21:07:35][D][switch:045]: 'relay8': Sending state OFF
[21:07:35][D][switch:025]: 'relay8' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay9'...
[21:07:35][D][switch:025]: 'relay9' Turning OFF.
[21:07:35][D][switch:045]: 'relay9': Sending state OFF
[21:07:35][D][switch:025]: 'relay9' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay10'...
[21:07:35][D][switch:025]: 'relay10' Turning OFF.
[21:07:35][D][switch:045]: 'relay10': Sending state OFF
[21:07:35][D][switch:025]: 'relay10' Turning OFF.
[21:07:35][C][switch.gpio:011]: Setting up GPIO Switch 'relay11'...
[21:07:35][D][switch:025]: 'relay11' Turning OFF.
[21:07:35][D][switch:045]: 'relay11': Sending state OFF
[21:07:35][D][switch:025]: 'relay11' Turning OFF.
[21:07:36][C][switch.gpio:011]: Setting up GPIO Switch 'relay12'...
[21:07:36][D][switch:025]: 'relay12' Turning OFF.
[21:07:36][D][switch:045]: 'relay12': Sending state OFF
[21:07:36][D][switch:025]: 'relay12' Turning OFF.
[21:07:36][C][switch.gpio:011]: Setting up GPIO Switch 'relay13'...
[21:07:36][D][switch:025]: 'relay13' Turning OFF.
[21:07:36][D][switch:045]: 'relay13': Sending state OFF
[21:07:36][D][switch:025]: 'relay13' Turning OFF.
[21:07:36][C][switch.gpio:011]: Setting up GPIO Switch 'relay14'...
[21:07:36][D][switch:025]: 'relay14' Turning OFF.
[21:07:36][D][switch:045]: 'relay14': Sending state OFF
[21:07:36][D][switch:025]: 'relay14' Turning OFF.
[21:07:36][C][switch.gpio:011]: Setting up GPIO Switch 'relay15'...
[21:07:36][D][switch:025]: 'relay15' Turning OFF.
[21:07:36][D][switch:045]: 'relay15': Sending state OFF
[21:07:36][D][switch:025]: 'relay15' Turning OFF.
[21:07:36][C][switch.gpio:011]: Setting up GPIO Switch 'relay16'...
[21:07:36][D][switch:025]: 'relay16' Turning OFF.
[21:07:36][D][switch:045]: 'relay16': Sending state OFF
[21:07:36][D][switch:025]: 'relay16' Turning OFF.
[21:07:36][C][switch.gpio:011]: Setting up GPIO Switch 'relay17'...
[21:07:36][D][switch:025]: 'relay17' Turning OFF.
[21:07:36][D][switch:045]: 'relay17': Sending state OFF
[21:07:36][D][switch:025]: 'relay17' Turning OFF.

AND SO ON FOR NEXT RELAYS

[21:07:36][C][wifi:033]: Setting up WiFi...
[21:07:36][D][wifi:324]: Starting scan...
[21:07:42][D][wifi:339]: Found networks:
[21:07:42][I][wifi:385]: -  ▂▄▆█
[21:07:42][D][wifi:386]:     Channel: 3
[21:07:42][D][wifi:387]:     RSSI: -51 dB
[21:07:42][I][wifi:385]: -  ▂▄▆█
[21:07:42][D][wifi:386]:     Channel: 12
[21:07:42][D][wifi:387]:     RSSI: -67 dB
[21:07:42][I][wifi:194]: WiFi Connecting to 
[21:07:44][I][wifi:457]: WiFi Connected!
[21:07:44][C][wifi:303]:   SSID: 
[21:07:44][C][wifi:304]:   IP Address: 
[21:07:44][C][wifi:306]:   BSSID: 
[21:07:44][C][wifi:307]:   Hostname: 'przekazniki1'
[21:07:44][C][wifi:311]:   Signal strength: -66 dB ▂▄▆█
[21:07:44][C][wifi:315]:   Channel: 3
[21:07:44][C][wifi:316]:   Subnet: 255.255.255.0
[21:07:44][C][wifi:317]:   Gateway: 
[21:07:44][C][wifi:318]:   DNS1: 
[21:07:44][C][wifi:319]:   DNS2: (IP unset)
[21:07:44][D][wifi:466]: Disabling AP...
[21:07:44][C][web_server:069]: Setting up web server...
[21:07:44][C][ota:029]: Over-The-Air Updates:
[21:07:44][C][ota:030]:   Address: przekazniki1.local:8266
[21:07:44][C][ota:032]:   Using Password.
[21:07:44][W][ota:036]: Last Boot was an unhandled reset, will proceed to safe mode in 8 restarts
[21:07:44][C][api:022]: Setting up Home Assistant API server...
[21:07:44][I][app:059]: setup() finished successfully!
[21:07:44][I][app:105]: ESPHome version 1.16.2 compiled on Mar 27 2021, 21:05:14
[21:07:44][C][wifi:443]: WiFi:
[21:07:44][C][wifi:303]:   SSID: 
[21:07:44][C][wifi:304]:   IP Address: 
[21:07:44][C][wifi:306]:   BSSID: 
[21:07:44][C][wifi:307]:   Hostname: 'przekazniki1'
[21:07:44][C][wifi:311]:   Signal strength: -63 dB ▂▄▆█
[21:07:44][C][wifi:315]:   Channel: 3
[21:07:44][C][wifi:316]:   Subnet: 255.255.255.0
[21:07:44][C][wifi:317]:   Gateway: 
[21:07:44][C][wifi:318]:   DNS1: 
[21:07:44][C][wifi:319]:   DNS2: (IP unset)
[21:07:44][C][i2c:028]: I2C Bus:
[21:07:44][C][i2c:029]:   SDA Pin: GPIO5
[21:07:44][C][i2c:030]:   SCL Pin: GPIO4
[21:07:44][C][i2c:031]:   Frequency: 50000 Hz
[21:07:44][I][i2c:033]: Scanning i2c bus for active devices...
[21:07:45][I][i2c:049]: Found no i2c devices!
[21:07:45]
[21:07:45]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[21:07:45]
[21:07:45]Exception (29):
[21:07:45]epc1=0x4021cd3b epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
[21:07:45]
[21:07:45]>>>stack>>>
[21:07:45]
[21:07:45]ctx: cont
[21:07:45]sp: 3ffffcf0 end: 3fffffc0 offset: 0190
[21:07:45]3ffffe80:  00000000 3fff153c 0000010c 4022722c  
[21:07:45]3ffffe90:  00000003 3fff153c 00000000 4021a991  
[21:07:45]3ffffea0:  00000000 00000000 00000000 00000000  
[21:07:45]3ffffeb0:  3fff0000 00000000 3fff157c 401004ff  
[21:07:45]3ffffec0:  00000000 3fff153c 00000002 4021b293  
[21:07:45]3ffffed0:  3fffff20 3fffb624 3fff0e00 4020eacd  
[21:07:45]3ffffee0:  40255266 00000000 3fff2b14 3fff2b14  
[21:07:45]3ffffef0:  3fffbe3c 00002619 3fff153c 4021be9c  
[21:07:45]3fffff00:  3fffac7c 4020bdcc 3fff2b14 4021a48a  
[21:07:45]3fffff10:  00000000 4bc6a7f0 00002619 4020ec5a  
[21:07:45]3fffff20:  3fffbe3c 00002619 3fff2b14 4020b940  
[21:07:45]3fffff30:  00002619 00000000 3fff0e00 4022a400  
[21:07:45]3fffff40:  00000000 00000010 3fff2dc4 4022a475  
[21:07:45]3fffff50:  3fffdad0 00000000 3fff0e00 4020c6a3  
[21:07:45]3fffff60:  007a1200 32b86579 feefef00 feefeffe  
[21:07:45]3fffff70:  3fffbf0c 3fff8c2c 3fff8c1c 3fff8c0c  
[21:07:45]3fffff80:  00000000 00000000 00000001 3fff1868  
[21:07:45]3fffff90:  3fffdad0 00000000 3fff1828 4020efc8  
[21:07:45]3fffffa0:  3fffdad0 00000000 3fff1828 402276c0  
[21:07:45]3fffffb0:  feefeffe feefeffe 3ffe8574 4010065d  
[21:07:45]<<<stack<<<
[21:07:45]
[21:07:45]last failed alloc call: 4021A98C(268)
[21:07:45]
[21:07:45]--------------- CUT HERE FOR EXCEPTION DECODER ---------------
[21:07:45]
[21:07:45] ets Jan  8 2013,rst cause:2, boot mode:(3,6)
[21:07:45]
[21:07:45]load 0x4010f000, len 3584, room 16 
[21:07:45]tail 0
[21:07:45]chksum 0xb0
[21:07:45]csum 0xb0
[21:07:45]v2843a5ac
[21:07:45]~ld
[21:07:45][I][logger:166]: Log initialized
[21:07:45][C][ota:366]: There have been 3 suspected unsuccessful boot attempts.
[21:07:45][I][app:029]: Running through setup()...
[21:07:45][C][mcp23017:010]: Setting up MCP23017...
[21:07:45][W][i2c:070]: Received NACK on transmit of address 0x20
[21:07:45][E][component:092]: Component was marked as failed.
[21:07:45][C][mcp23017:010]: Setting up MCP23017...
[21:07:45][W][i2c:070]: Received NACK on transmit of address 0x21
[21:07:45][E][component:092]: Component was marked as failed.
[21:07:45][C][mcp23017:010]: Setting up MCP23017...
[21:07:45][W][i2c:070]: Received NACK on transmit of address 0x22
[21:07:45][E][component:092]: Component was marked as failed.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay1'...
[21:07:45][D][switch:025]: 'relay1' Turning OFF.
[21:07:45][D][switch:045]: 'relay1': Sending state OFF
[21:07:45][D][switch:025]: 'relay1' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay2'...
[21:07:45][D][switch:025]: 'relay2' Turning OFF.
[21:07:45][D][switch:045]: 'relay2': Sending state OFF
[21:07:45][D][switch:025]: 'relay2' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay3'...
[21:07:45][D][switch:025]: 'relay3' Turning OFF.
[21:07:45][D][switch:045]: 'relay3': Sending state OFF
[21:07:45][D][switch:025]: 'relay3' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay4'...
[21:07:45][D][switch:025]: 'relay4' Turning OFF.
[21:07:45][D][switch:045]: 'relay4': Sending state OFF
[21:07:45][D][switch:025]: 'relay4' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay5'...
[21:07:45][D][switch:025]: 'relay5' Turning OFF.
[21:07:45][D][switch:045]: 'relay5': Sending state OFF
[21:07:45][D][switch:025]: 'relay5' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay6'...
[21:07:45][D][switch:025]: 'relay6' Turning OFF.
[21:07:45][D][switch:045]: 'relay6': Sending state OFF
[21:07:45][D][switch:025]: 'relay6' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay7'...
[21:07:45][D][switch:025]: 'relay7' Turning OFF.
[21:07:45][D][switch:045]: 'relay7': Sending state OFF
[21:07:45][D][switch:025]: 'relay7' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay8'...
[21:07:45][D][switch:025]: 'relay8' Turning OFF.
[21:07:45][D][switch:045]: 'relay8': Sending state OFF
[21:07:45][D][switch:025]: 'relay8' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay9'...
[21:07:45][D][switch:025]: 'relay9' Turning OFF.
[21:07:45][D][switch:045]: 'relay9': Sending state OFF
[21:07:45][D][switch:025]: 'relay9' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay10'...
[21:07:45][D][switch:025]: 'relay10' Turning OFF.
[21:07:45][D][switch:045]: 'relay10': Sending state OFF
[21:07:45][D][switch:025]: 'relay10' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay11'...
[21:07:45][D][switch:025]: 'relay11' Turning OFF.
[21:07:45][D][switch:045]: 'relay11': Sending state OFF
[21:07:45][D][switch:025]: 'relay11' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay12'...
[21:07:45][D][switch:025]: 'relay12' Turning OFF.
[21:07:45][D][switch:045]: 'relay12': Sending state OFF
[21:07:45][D][switch:025]: 'relay12' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay13'...
[21:07:45][D][switch:025]: 'relay13' Turning OFF.
[21:07:45][D][switch:045]: 'relay13': Sending state OFF
[21:07:45][D][switch:025]: 'relay13' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay14'...
[21:07:45][D][switch:025]: 'relay14' Turning OFF.
[21:07:45][D][switch:045]: 'relay14': Sending state OFF
[21:07:45][D][switch:025]: 'relay14' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay15'...
[21:07:45][D][switch:025]: 'relay15' Turning OFF.
[21:07:45][D][switch:045]: 'relay15': Sending state OFF
[21:07:45][D][switch:025]: 'relay15' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay16'...
[21:07:45][D][switch:025]: 'relay16' Turning OFF.
[21:07:45][D][switch:045]: 'relay16': Sending state OFF
[21:07:45][D][switch:025]: 'relay16' Turning OFF.
[21:07:45][C][switch.gpio:011]: Setting up GPIO Switch 'relay17'...
[21:07:45][D][switch:025]: 'relay17' Turning OFF.
[21:07:45][D][switch:045]: 'relay17': Sending state OFF
[21:07:45][D][switch:025]: 'relay17' Turning OFF.

AND SO ON FOR NEXT RELAYS

[21:07:46][C][wifi:033]: Setting up WiFi...
[21:07:46][D][wifi:324]: Starting scan...
[21:07:52][D][wifi:339]: Found networks:
[21:07:52][I][wifi:385]: -  ▂▄▆█
[21:07:52][D][wifi:386]:     Channel: 3
[21:07:52][D][wifi:387]:     RSSI: -47 dB
[21:07:52][I][wifi:385]: -  ▂▄▆█
[21:07:52][D][wifi:386]:     Channel: 12
[21:07:52][D][wifi:387]:     RSSI: -65 dB
[21:07:52][I][wifi:194]: WiFi Connecting to 
[21:07:54][I][wifi:457]: WiFi Connected!
[21:07:54][C][wifi:303]:   SSID: 
[21:07:54][C][wifi:304]:   IP Address: 
[21:07:54][C][wifi:306]:   BSSID: 
[21:07:54][C][wifi:307]:   Hostname: 'przekazniki1'
[21:07:54][C][wifi:311]:   Signal strength: -59 dB ▂▄▆█
[21:07:54][C][wifi:315]:   Channel: 3
[21:07:54][C][wifi:316]:   Subnet: 255.255.255.0
[21:07:54][C][wifi:317]:   Gateway: 
[21:07:54][C][wifi:318]:   DNS1: 
[21:07:54][C][wifi:319]:   DNS2: (IP unset)
[21:07:54][D][wifi:466]: Disabling AP...
[21:07:54][C][web_server:069]: Setting up web server...
[21:07:54][C][ota:029]: Over-The-Air Updates:
[21:07:54][C][ota:030]:   Address: przekazniki1.local:8266
[21:07:54][C][ota:032]:   Using Password.
[21:07:54][W][ota:036]: Last Boot was an unhandled reset, will proceed to safe mode in 7 restarts

Logs from OTA update, in dev there is an error, in 1.16 ESP is not active after OTA and needs to be flashed again with basic code:

INFO Reading configuration /config/esphome/przekazniki1.yaml...
INFO Generating C++ source...
INFO Compiling app...
INFO Running:  platformio run -d /config/esphome/przekazniki1
Processing przekazniki1 (board: d1_mini; framework: arduino; platform: [email protected])
--------------------------------------------------------------------------------
HARDWARE: ESP8266 80MHz, 80KB RAM, 4MB Flash
PACKAGES: 
 - framework-arduinoespressif8266 3.20704.0 (2.7.4) 
 - tool-esptool 1.413.0 (4.13) 
 - tool-esptoolpy 1.20800.0 (2.8.0) 
 - toolchain-xtensa 2.40802.200502 (4.8.2)
Library Manager: Installing Update
Library Manager: Already installed, built-in library
Dependency Graph
|-- <ESPAsyncTCP-esphome> 1.2.3
|   |-- <ESP8266WiFi> 1.0
|-- <ESP8266WiFi> 1.0
|-- <ESP8266mDNS> 1.2
|   |-- <ESP8266WiFi> 1.0
|-- <ESPAsyncWebServer-esphome> 1.2.7
|   |-- <ESPAsyncTCP-esphome> 1.2.3
|   |   |-- <ESP8266WiFi> 1.0
|   |-- <Hash> 1.0
|   |-- <ESP8266WiFi> 1.0
|   |-- <ArduinoJson-esphomelib> 5.13.3
|-- <ArduinoJson-esphomelib> 5.13.3
|-- <Wire> 1.0
|-- <DNSServer> 1.1.1
|   |-- <ESP8266WiFi> 1.0
Retrieving maximum program size /data/przekazniki1/.pioenvs/przekazniki1/firmware.elf
Checking size /data/przekazniki1/.pioenvs/przekazniki1/firmware.elf
RAM:   [=====     ]  49.6% (used 40596 bytes from 81920 bytes)
Flash: [====      ]  43.4% (used 453752 bytes from 1044464 bytes)
========================= [SUCCESS] Took 4.21 seconds =========================
INFO Successfully compiled program.
INFO Resolving IP address of przekazniki1.local
INFO  -> 192.168.....
INFO Uploading /data/przekazniki1/.pioenvs/przekazniki1/firmware.bin (457904 bytes)
Uploading: [============================================================] 100% Done...


INFO Waiting for result...
INFO OTA successful
INFO Successfully uploaded program.
INFO Starting log output from przekazniki1.local using esphome API
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 1 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 1 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 2 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 3 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 5 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 7 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 11 seconds
WARNING Error resolving IP address of przekazniki1.local. Is it connected to WiFi?
WARNING (If this error persists, please set a static IP address: https://esphome.io/components/wifi.html#manual-ips)
WARNING Initial connection failed. The ESP might not be connected to WiFi yet (Error resolving IP address: Error resolving address with mDNS: Did not respond. Maybe the device is offline., [Errno -5] No address associated with hostname). Re-Trying in 17 seconds

I have tried using ESPHome in ver. 1.16 and dev. Flashing via OTA and ESPHome Flasher. Flashing for two MCP’s is working properly and I am able to use with this solution 32 realys but I need much more and then this issue occurs. Can can anyone help me in this matter?

That’s a lot of power required, i2c is reporting no devices. Could be under powered or there is too much capacitance on the I2c bus due to length or a bad cable.

Hi, flashing was done without connecting to any of MCP23017, only power and data to ESP8266 so this is not an issue. MCP’s and relays are powered with additional cables from sufficient power source and relays will be switched on for half a sec as an impulse and for sure not more than few in the same time.

Sorry I misunderstood, are the mcp’s connected when you try to boot after flashing or are you booting the chip with nothing connected. Does the captive portal kick in after a minute?

This is a similar project. They limited the breakout board to 2 mcp’s and used a P82B96TD to boost the bus as well. But it says it can go up to 96 i/o’s

I copied your code, compiled, loaded it, and connected wirelessly without a problem albeit on a nodemcu 32. So maybe a bad chip, problem with d1 mini’s or something in the rest of the code. Paste in just what you posted and see if that works.

I was limited by post length with full code presentation and therefore it was for 17 pcs. of relays. For this quantity code works also for me and I am able to control first stack of relays. Could You check if You are able to upload and launch Your ESP properly? Below code for 48 relays. My target is to have total 80 relays. After uploading this code below ESP will not start (it is not visible via wifi and does not log back to ESPHome) and I need to flash it via ESPHome flasher with previous code to work properly again. Maybe the code is too long then? To many switches in one config? I am not aware if there are any limitations.

It looks like there is too much and is throwing an actual stack overflow haha. Mine sits in a reboot loop right after flashing. Anyway a quick search for

Stack canary watchpoint triggered

Suggests increasing the stack size.

Full boot loop output

[06:33:44]Rebooting...
[06:33:44]ets Jun  8 2016 00:22:57
[06:33:44]
[06:33:44]rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
[06:33:44]configsip: 0, SPIWP:0xee
[06:33:44]clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
[06:33:44]mode:DIO, clock div:2
[06:33:44]load:0x3fff0018,len:4
[06:33:44]load:0x3fff001c,len:1044
[06:33:44]load:0x40078000,len:8896
[06:33:44]load:0x40080400,len:5828
[06:33:44]entry 0x400806ac
[06:33:44][I][logger:166]: Log initialized
[06:33:44][C][ota:366]: There have been 5 suspected unsuccessful boot attempts.
[06:33:44][I][app:029]: Running through setup()...
[06:33:44][C][mcp23017:010]: Setting up MCP23017...
[06:33:44][W][i2c:070]: Received NACK on transmit of address 0x20
[06:33:44][E][component:092]: Component was marked as failed.
[06:33:44][C][mcp23017:010]: Setting up MCP23017...
[06:33:44][W][i2c:070]: Received NACK on transmit of address 0x21
[06:33:44][E][component:092]: Component was marked as failed.
[06:33:44][C][mcp23017:010]: Setting up MCP23017...
[06:33:44][W][i2c:070]: Received NACK on transmit of address 0x22
[06:33:44][E][component:092]: Component was marked as failed.
[06:33:44][C][mcp23017:010]: Setting up MCP23017...
[06:33:44][W][i2c:070]: Received NACK on transmit of address 0x25
[06:33:44][E][component:092]: Component was marked as failed.
[06:33:44][C][mcp23017:010]: Setting up MCP23017...
[06:33:44][W][i2c:070]: Received NACK on transmit of address 0x24
[06:33:44][E][component:092]: Component was marked as failed.
[06:33:44][C][switch.gpio:011]: Setting up GPIO Switch 'relay1'...
[06:33:44][D][switch:025]: 'relay1' Turning OFF.
[06:33:44]Guru Meditation Error: Core  1 panic'ed (Unhandled debug exception)
[06:33:44]Debug exception reason: Stack canary watchpoint triggered (loopTask) 
[06:33:44]Core 1 register dump:
[06:33:44]PC      : 0x4008be27  PS      : 0x00060336  A0      : 0x40085228  A1      : 0x3ffb0020  
[06:33:44]A2      : 0x00000001  A3      : 0x00000000  A4      : 0x00000004  A5      : 0x0000002d  
[06:33:44]A6      : 0x00000000  A7      : 0x00000004  A8      : 0x3ffb00f0  A9      : 0x3ffb00f0  
[06:33:44]A10     : 0x3ffb00f0  A11     : 0x0000002a  A12     : 0xffffffff  A13     : 0x3f4005cc  
[06:33:45]A14     : 0x3ffb00f0  A15     : 0x3ffb0314  SAR     : 0x00000012  EXCCAUSE: 0x00000001  
[06:33:45]EXCVADDR: 0x00000000  LBEG    : 0x400014fd  LEND    : 0x4000150d  LCOUNT  : 0xfffffffe  
[06:33:45]
[06:33:45]Backtrace: 0x4008be27:0x3ffb0020 0x40085225:0x3ffb03f0 0x40136d7a:0x3ffb0480 0x400d8621:0x3ffb04c0 0x400d8655:0x3ffb04f0 0x400d8689:0x3ffb0540 0x400d883c:0x3ffb0560 0x400df51d:0x3ffb0580 0x400df54a:0x3ffb05b0 0x400d9a79:0x3ffb0610 0x400d7761:0x3ffb0640 0x400d9957:0x3ffb0690 0x400d74c9:0x3ffb06b0 0x400d74f2:0x3ffb06e0 0x4016daa1:0x3ffb0700 0x4016db25:0x3ffb0720 0x400deafd:0x3ffb0740 0x400e924e:0x3ffb0790 0x400f772b:0x3ffb1fb0 0x40089699:0x3ffb1fd0
[06:33:45]
[06:33:45]Rebooting...

So this might be a bigger issue then, mine is stuck on boot loop also. Do You see a possibility to optimize the code or use another device? I would really like to avoid using extra two modules of ESP to control this relays.

1 Like

The stack size can/should be able to be increased. Esp’s look like they run on freertos and the config is in a text file when it is compiled. This is more involved than I can help you with.

Esphome’s discord channel would probably be the best place to ask how to increase stack size.

The only other thing I could think to reduce the size of the code. I looked for a global automation, turn off action could be set for all the relays, but I couldn’t find anything. That other project is 2x the size though but it is running through an ethernet connection so there may be a wifi restriction as well.

I started this post and as I wrote the last paragraph figured let me try without the wifi component. I removed wifi ota and api, sure enough it loads and runs!

I don’t know how much space the ethernet component adds. I still think discord might be the best spot to figure out if you can increase the stack size.

I have raised this topic in ESPHome GitHub:

I am using mcp23017 with a di_min with sda connected to D2 and scl connected to D1


The pinout shows SDA connected to D2 and SCL to pin D1.

Your code above showed:
i2c:
sda: D1
scl: D2
scan: True