GPIO binary sensor only registers change of state on change of relay GPIO

I’m in the process of automating my down lights and at the same time switching them to 12VDC from mains power.

I am using a raspberry pi and 2 GPIOs, one to register the state of a physical switch and the other to activate a relay to turn the lights on and off. I plan to automate the on/off process based on a motion sensor, time of day, and with a physical switch override, but first I need to get the components working properly.

This is a crude schematic of the wiring.

And my configuration.yaml

binary_sensor:

  • platform: rpi_gpio
    ports:
    19: Family Room Switch
    pull_mode: ‘UP’
    bouncetime: 50
    invert_logic: true

switch:
platform: rpi_gpio
ports:
13: Family Room Lights
invert_logic: false

The relay works fine and I can turn the lights on and off just fine, however the switch state does not work as intended. Turning the switch off, immediately changes the sensor state to off, but turning the switch on does not immediately change the sensor state to on. The funny thing is, turning the light relay on or off will immediately set the sensor to the correct state.

It may be worth noting that I am using Cat5e cable for the gnd, GPIO19 and 13, over a length of about 15M. I am using the same cable in a near identical scenario with a reed switch instead of a manual switch, only over a shorter length of about 7M and it works perfectly well.

Any ideas? Do I need some kind of EOL resistor, or have I screwed up my wiring somewhere, or is it possibly the type of cable?

Thanks for any help.

Mark