Hi,
I’m in UK and have been struggling to use the core component ‘UK Transport’. It is promising that you can get train time & bus times. I never got it to work. For trains there are awesome HACS components but being a newbie, I wanted something out of the box. As any sane person will do, I looked into the code.
I figured out the API end points have changed. Thanks to awesome community, it was fixed by @AlexLamond @frenck. Trains worked but not the bus.
Finally after setting up a development environment, I started digging again and found few issues:
- The API call is every 87 seconds per query instead of 48 minutes. I guess lot of users are used to specific times or using scan_interval. I have free Transport API account that gives 30 calls and based on current logic, 1 query will consume all calls in 30-45 mins.
- Response for bus stop timetable returns the final destination of the bus and does not return intermediate stops. There is different API call to get stops for the bus journey. The component checks for the stops before returning results and since my request is for intermediate stop it doesn’t work.
- I can give end point but I have 3 buses from my closest stop and all of them go to the interested intermediate stop and one of the route has 2 different end point that makes 4 destinations to track but configuration allows for only one and adding more queries will increase the API calls and delay the next call.
My plan is to fix it but need the community to guide me:
- Introduce a new config item ‘app_limit’ which will default to 30 if not given. This will set API call every 48 mins. Home users with 300 calls can set this value accordingly and API will be called every 5 minutes approx. If ‘scan_interval’ is provided in configuration then this logic will not be invoked and existing 87 seconds per query will work.
- Pass multiple destinations separated by comma say ‘London,Leeds,Manchester’ it’ll return all buses having final destination to either London, Leeds or Manchester. The only downside will be that the sensor name will say ‘next_bus_to_london_leeds_manchester’. Any destination having space or special character will still continue to behave the same. I guess everyone is used to 1 destination per query, they won’t see a change but this will definitely reduce the calls.
- Introduce ‘operator_name’ for bus similar to trains.
I’ve thought about some additional points but still not sure since they might be breaking changes.
- Unless manually maintained, if the default 30 API limit is used with 1 query, the results will be in shown every 48 minutes. If there are buses every 20 minutes, the sensor will not show the correct time post the 1st bus thereby making the time irrelevant when the 1st bus has left. Since it will not be real time updated, you might see next bus in 19 minutes even when bus is leaving in 5 mins. Will it be worth showing time time for next refresh or something like ‘2 bus until 11:00’. Same goes for trains.
- Reuse the destination in configuration.yaml as source stop name to make sensor say something like ‘Next Bus At ’. It will return all buses from the stop irrespective of final destination. If bus route change, added or running short journeys, it’ll show the bus and anyways it’ll show the destination. I guess most of us are used to bus route number.
Ideas & suggestions are welcome.