Hi Rasta,
To help we'd need more info on the mechanical switch (normally closed or open) and the optical sensor (PNP or NPN). I think the idea would be to wire the switch and sensor in a way that a current goes to the Kanalog input when both the switch and opto sensor are triggered. The problem with an optical sensor on the motor shaft is that it triggers every motor revolution. So it needs to be inhibited until the limit switch is enabled. The logical AND of both sensors.
Note also a Kanalog opto input has 2 terminals. a + and -. Both terminals must be driven to activate it.