Raspberry PI GPIO input buffer circuit

Hi,
Can anyone confirm if you were able to use the GPIOs of the RPI as inputs, in a reliable way? Mainly: which electronic components you used to buffer the electrical input signal?

I tested with a RPI3 and with an RPI4 with Home Assistant 0.111.2
I use the internal pull-up resistor and I verify the voltage at the GPIO pin with a multimeter and an oscilloscope

What works:
When I (repeatedly) pull down a GPIO by connecting it to ground, it seems to work consistently.
But in real-world, one needs to buffer the electrical signals because the inductance of long wires will kill the ports or the voltage of the input signal is too high etc…

And with the buffering, … my problems begin
To pull down the GPIO, I first used a 74LS05 (open collector inverter), and afterwards an optocoupler (4n35)
Both methods pull the pin down from 3v3. With the optocoupler, it goes to about 0.2 volt
In the beginning, in most cases, Home-Assistant reports the right State, but after a few transitions it no longer responds reliable and I see the following phenomenon:

  • when the pin is pulled low (to 0.2v), the State remains ON (it should go OFF)
  • when the voltage at the pin goes back up (from 0,2v to 3.3v), the state which is ON glitches to low for less than a second to OFF and then returns to ON
    In an attempt to get rid of the issue, I have also added a RC filter (2k2 in series between GPIO and optocoupler, and a 22uF tantalum capacitor between GPIO and ground)
    I tested with different hardware (an RPI3 and an RPI4) and I used different power supplies as well.

Any tips are greatly appreciated
If anything in my description was unclear, please let me know. I’d be happy to clarify. I know I’m not the best at explaining things
thanks so much
ChrisV