Pi I/O intergration

I have following setup:
1x RPi where Home Assistant is running
3x IO Pi Plus with 3x range extenders that are used to extend the I2C bus up to 30 meters/100 ft.

Each of the IO Pi Plus’ are about 20 meters away from RPi in different directions, so the only communication bus between RPi and IO Pi Plus is the I2C bus. IO Pi Plus’ are used to monitor light switches (sensors in HASS) and turn on and off relays to control lights etc (switches in HASS). Automations in HASS control what switches sensors will trigger, so I can update configurations by editing yaml-files, instead of doing any changes to code.

Do you know if the mcp23017 can send message over I2C bus without the need of polling each of the bus for changes?

I’ve half way finished a python script that is polling for the interrupt bus for any changes (maybe similar to yours). Thanks for the github link btw!!. I also need to implement software debounce to it, so that only single event will trigger even if user pushes the button for 200 ms, for example. Because of debounce and other stuff, I need to keep several different data items per pin in memory on the RPi side. Reading all the data at the same time from interrupts seems to complicate things, compared to polling and processing single pin at the time, which is my current setup.

this is great. i might get one of these.

Yeah, it works really well! Extender needs external power supply, so it does not even put pressure on the RPi.

Only thing you need to take care of is powering IO Pi board on the far end of the extender. There is some discussion on ABElectronics forums where I asked if it is really necessary to provide also the 3.3V voltage to IO Pi Plus. Currently I have voltage divider to provide the 3.3V, but according to the latest discussion it seems that one might do without 3.3V.

If you find good I2C range extenders from somewhere else, please link also here :slight_smile:

You can wire the interrupt pins from the mcp23017, it has 2 (one for each port: A and B) that can be configured as mirrors. At that distance you will probably need a buffer/line driver to amp up the signal to the Pi. If you configure the interrupt pins as Open Drain you can daisy chain them to just one pin in the Pi, so whenever any pin on the IC changes state it will go low. Then, on the Pi, you can use GPIO.add_event_detect() for a falling edge on that pin with a callback to a function that polls the ICs to check which pin caused the interrupt and update its state in HA.
I added an example on how to use add_event_detect to the Adafruit’s GitHub repo a few weeks ago when I did a PR to add some more interrupt functionality: https://github.com/adafruit/Adafruit_CircuitPython_MCP230xx/blob/50b397880e222ad676e1f161197cf2a24532df9f/examples/mcp230xx_event_detect_interrupt.py
The only thing is that if you have any IO pin configured as output, the interrupt pins get a lot of noise that makes them unusable. My solution to that is to configure the interrupts as not mirrored and use one port exclusively for outputs as to not mix outputs and inputs in the same port. I have no idea why that happens since, according to the datasheet, outputs shouldn’t trigger the interrupts.

2 Likes

Is everyone still able to use their IO PI Plus with HA?
I recently was forced to update and they don’t seem to work anymore. I’ve been downgrading trying to find an old version that works but the further I go back the more problems that occur

I have several that are working fine on 0.93.1. How are you using them?

Thank you for this one.

I’m doing s fresh installation on RPi 4 and newest HA. Have to check out, which parts need fixing…

I already have input and output on different bus, but cannot send the interrupt to RPi as it is so far away. I have to see how to get the IO Pi Plus interrupts to work or just let the better CPU just bear the load of polling all the pins :slight_smile:

Sorry for the delayed response. I have not got it working yet. I have two RPI running. One with Home assistant other with Hassio. How did the RPI 4B go?

Fresh install so it took a while to get t up and running. It is faster atleast :slight_smile:

I noticed that there is new integration with IOPi plus:

Have not got it to work yet as v0.105 has some bug with it. It could allow direct integration of the I/O without external Python scripts, I hope.

Hi all,

I am planning to hardwire a number of sensor inputs to the HA platform on a RPi.
Outputs will be Zigbee controlled devices.

For the inputs I would like some suggestions from the forum what kind of I/O board I can use and easily integrate with the HA platform. Is there something ‘plug and play’?

I have hardwired 10 inputs coming from an existing alarm system. These inputs are normale closed and carrying 5 or 12 DC (I can select).
These 10 digital inputs I want to connect to a suitable I/O board so I can read the statusses of those alarm signals with HA.

Next to that I also have 5 temp sensors (DS18B20) on a 1-wire link. This 1-wire I also want to connect to HA to record and log the temp readings of those 5 sensors. Can I directly connect the 1-wire to the RPi or do I need also a specific I/O board for this?

Or could I combine the above (the 10 digital inputs & the 1-wire) on one I/O board for HA? Any advice on make&model I/O board I could buy for connecting this to the RPi?

Btw, I could also remove the voltage on the 10 wires I have from the alarm system. Those 10 signals are from simpel door/window switches (NC). Could I then wire up those 10 switches directly to the RPi’s GPIO pins?

Could I also connect then the 1-wire directly to 1 of the other GPIO pins to read out the 5 temp sensors?

Hi Jayden, I started using ths new integration you mentioned but it doesn’s seem to support interrupts, and scanning time of min 1s is not good enough for ‘real time’ control of lights using switches. Are you still using a custom component to get faster updates using interrupts?

Hi!

I’m still using my old setup that gives response in 100-200 ms in HA after pushing button. That does not use interrupts. It polls through all the pins, but still gives about decent response time. Using interrupts would probably lower CPU use and make it faster.

I planned to test MCP23017 on HA, but could not test it out without extra IOPi expander board. I have one now, but have not had the time to try it.

You have problem that the scanning time is 1 second? That does not sound promising… :frowning: I thought I could get rid of the extra script…

I think using wires with voltage will fry your RPi easily. Not recommend by me at least.

I’ve been using IoPi expander that has worked nicely.

Also, wires are not directly connected to RPi. It only needs I2C + power (5V + 3.3V).

I just started playing with Home Assistant yesterday and I’m a C# developer so I’m having some hard time wrapping my head around everything, but so far I managed to figure out how the support for MCP23017 works, and that there is no build in support for interrupts. Before I was playing with OpenHAB and even though they also don’t have interrupts, but at least their scanning time was fast enough not make me want to look into adding interrupts. Here however, the minimal scanning time I can set is 1s, which is not good if I want to detect light switch activation and turn on a lamp (user has to hold the switch for at least 1s in worst case).

I wonder why this alternative version with interrupts is not part of the core, because both are made by the same author (@Jardiamj). I have tested his component (had to update manifest to match pip modules I have in my hassio image and fix his config) and it works. Now I just need to make some changes to be able to have more interrupt ports in the config becuase I have 5 chips that I need to handle, but other than that i looks promising!

Does your setup send information about interrupt with GPIO to RPi?

Hi, I got the component to a somehow working state using interrupts and I have in fact been using my custom component at home for a while.

There are still some issues that I need to figure out but I haven’t had the time to do so since I started taking some formal computer science classes (Up until now I have been self taught).

There can be some threading issues with the interrupt and a fix might need some work on the Adafruit’s library it depends on. I haven’t looked into it deeply enough and that’s the reason the interrupt logic is still not there.
Here is an issue submitted in github if you want to take a look: https://github.com/home-assistant/core/issues/31867

My classes are a bit time demanding so it might take me a while to look into properly implementing the interrupt logic in there.

Jardi.

Yes exactly, I have 5 MCP23017 modules with interrupt ports daisy chained to my GPIO on RPi and on each interrupt (I monitor both state changes) I scan all my modules to detect which pin triggered the interrupt. This is based on the custom component which @Jardiamj has in his repo. Seems to work ok but need to test more.

I am learning Home Assistant since last weekend and my background is C# not Python, but I am motivated to make this component work the best way it can. I’m finishing house renovation and I only have network cables in my light switches so if this doesn’t work, I won’t be able to turn on my lights :sweat_smile: Thank you for referencing that issue on GitHub, I think I will be able to contribute there soon, just need to learn more about HA architecture and translate how I would handle this in C# to Python :wink:

PS. Good luck with your classes!

I will be interested to test/check interrupt version of MCP23017 integration. Currently 1 second pulling is not enough for my PIR and light controlling automation. It works but in worst case I need to wait more than 1 second for the lights to turn on and I am already almost half way in the hall… :slight_smile:
If I can help let me know.