MCP23017 wild misbehavior after update to 2023.7.1

Since the update to ESPHome 2023.7.1, I’m seeing wild misbehavior on my central switch panel. Specifically, I see binary_sensors triggering without the corresponding switches being touched. The setup was sensitive to touching some of the wires before but it never went wild without external manipulation. I’m wondering if ESPHome actually activates the pullups of the MCP23017 correctly.

Hardware: ESP32, 2xMCP23017 via I²C, a bunch of switches and LEDs.

MCP config:

i2c:
  scan: true
  id: bus_a

mcp23017:
  - id: 'mcp_0x20'
    address: 0x20
  - id: 'mcp_0x21'
    address: 0x21

Example for a switch:

binary_sensor:
  - platform: gpio
    id: mcp_0x20_a0
    pin:
      mcp23xxx: mcp_0x20
      number: 0
      mode:
        input: true
        pullup: true
      inverted: true
    on_press:
      then:
        - homeassistant.service:
            service: light.toggle
            data:
              entity_id: light.living_room_ceiling_light

I’m thinking if I should add my own pullups and drop the builtin ones… Or does anybody have any other ideas?

Does not look like there have been any changes to this component since August 2022: Pull requests · esphome/esphome · GitHub

However there are a few similar issues open: Issues · esphome/issues · GitHub

Hm, ok, thanks! I’ll try using my own (lower) pullups then.

Did this fix your issue? I’m trying it out for the first time on esphome and am seeing this as well. Some of the pins even trigger so rapidly the logger becomes flooded and backdated

As a workaround, I’ve added the following filters (after removing the invert on the pin config)

filters:
  - invert:
  - delayed_on: 30ms
  - delayed_off: 30ms

It’s something I’ve used extensively on the internal esp8266 pins to deal with the noise at my place. I forgot about these when trying out the MCP23017

I wonder if the reason I’m not seeing this issue is because all but one of my inputs are shorted to ground when in the normal state?

  - platform: gpio
    name: "PIR Dining"
    device_class: motion
    pin:
      mcp23xxx: hub_0
      number: 0
      mode:
        input: true
        pullup: true
      inverted: false

  - platform: gpio
    name: "PIR Entry"
    device_class: motion
    pin:
      mcp23xxx: hub_0
      number: 1
      mode:
        input: true
        pullup: true
      inverted: false

...

  - platform: gpio
    name: "Power Fail"
    pin:
      mcp23xxx: hub_1
      number: 5
      mode:
        input: true
        pullup: true
      inverted: true

And that last one has a lot shorter leads.

Back then, using my own lower pullups didn’t do much. I restructured the wiring which helped a little. I had a RPi 3B in the same rack and level which was doing SDR decoding 24/7 and after I replaced that with a Banana Pi CM4 which lives 2U higher, the problems stopped completely. So I believe, the problems were related to EMI coming from the Pi 3B in my case. In general, the MCP23017 seems to be extremely sensitive to EMI/EFI. Just moving a finger close to a wire makes an input go crazy. Got mine from AliExpress, so maybe they’re not genuine. Dunno. Just to be safe, I decided not to use them any new project anymore. There’s plenty other I2C expanders out there.