Connecting a whole bunch of wired sensors to Home Assistant using MCP23017 board and Raspberry Pi

Hello awesome people!

I just want to share my little home project. I have a whole bunch of wired reed sensors in my house that I wanted to integrate into Home Assistant, which I have running on a Raspberry Pi. After much thought I decided to use an mcp23017 board to connect the sensors, I ended up ordering the io pi plus because it is designed so you can solder a couple of idc20 connectors to it, then I ordered a couple of screw end block boards with idc20 connectors, I plugged some flat ribbon cables between them and ended up with a very decent looking setup.

I have written a pretty basic HA custom_component binary sensor for mcp23017, I am still working on it but it works well enough. The configuration.yaml should look like this:

binary_sensor:
  - platform: mcp23017
    i2c_address: 0x20
    scan_interval: 1
    pins:
      0: Living Room Window
      1: Front Door
      2: Back Door

And, well… here is a picture of my setup, I still need to tidy some things up:

5 Likes

Hi, is the mcp23017 connected to the Pi thats running HA, or is it a dedicated one ? If same Pi does this cure the gpio input problem in HA ?

But what do you do with those reed sensors?

MCP23017 is connected to the same PI running HA.
I am not aware of the gpio input problem you are referring to, I wrote my own custom component for HA and it’s been working fine so far.

They are installed in all doors and windows around my house, tell me if they open/close and then I’m setting up some automations based on that.

I tried connecting directly to the gpio pins using rpi_gpio, But HA can miss when they change state, so after only a few on offs, they were showing the wrong state. But as your using the mcp23017 it might not happen

I believe what you are experiencing has to do with the default bouncetime for the rp-gpio binary sensors being too short (50 milliseconds). Try adding bouncetime: 500 (half a second) in your configuration.yaml like this:
binary_sensor:
- platform: rpi_gpio
bouncetime: 500
ports:
11: PIR Office
12: PIR Bedroom

I tried adjusting bouncetime from 100 up to 900 and didn’t make any difference, I’ve programmed a nodemcu and use mqtt now

Well, it seems like you found a solution already but if you want to try using MCP23017, there are some cheap boards that are easy to set up and get them to work with HA. I tried documenting it all here: https://github.com/jardiamj/homeassistant/blob/master/custom_components/README.md