Gpio relay on long cable doesn't work

@nattila1 you need to connect the transistor and GND from the RPI to the relay. So you need two wires from rpi to the relay. And then also your rail supply to VCC and GND. See my drawing.

The relay is active low and the rpi 3.3V are not used to supply the relay. The 5V from the rail are put to ground to switch the relay on.

Edit: @nattila1 just watched this maybe it helps. https://youtu.be/Ur0w7VeLX08

As you may see there you do not need the transistor circuit, but the on off behaviour will be inverted. To use an external power supply you need to feed supply from the rpi, the pins you toggle will be either ground switch goes on or high switch is off.
With a good cable the distance is no problem with a bad it is, was wrong. Had wrong numbers for the dc resistance. The expected current is up to 20mA, with a good UTP cat 5 cable the dc lopp resistance is 0.188Ohm/m. With 40m you got 7,5Ohm which will added twice one for the supply line and one for the signal line. So you end at 0.3V voltage drop above your cable, which is to much.
To solve, that its a bit of a hack, i would change the resistance on the board to a smaller one. As you can see in my drawing there is o resistance above the optocoupler, near VCC, this is usually used to limit the current. I would desolder and meausure it, measure my cable resistance and solder a new resistor in which is the old one minus 2 times my cable resistance. This Resistances are R1 and R4 for your board, see the manual.