I did some digging, and it looks like an error with the position offset calculations in get_station_schedule. I'm not sure if this is something which changed in a recent version, as I do recall it being somewhat more reliable in the past, but here's what I found for 0.16.43:
The results seem to depend entirely on the direction. North (0) and east (6) work, but south and west don't. Changing the condition on line 319 to 0 or 4 did not fix the problem.
Anyway, I redid the offsets manually, and the following code works for me.
if (direction < 4) then
x = x - 2
else
x = x + 2
end
if (direction == 2) or (direction == 4) then
y = y - 2
else
y = y + 2
end
It looks like that's good enough to pass in the position to find_entitites_filtered, rather than an area. I mention it because earlier hacking had me using an expanding area and sometimes picking up nearby trains rather than the one at the stop.