HI all, TFL have an API, so I wonder if anyone has thought of crating a HA component for it? Is there interest?
I have quite a bit of python experience (numpy, pandas mostly), but have not developed a HA component yet. Perhaps this would be a good one for me to start with, in which case can anyone offer advice on how to begin?
The transportapi site looks interesting, shame they donāt seem to obviously support trams (joys of living south of the river - not much in the way of tubeā¦). Iād love to get live timing for trams into HA at some point. In the mean time, itās easy to modify your rest sensor to give the tram status - thanks!
A āuk transportā component covering every mode of transport would be pretty awesome.! Is there an API covering tram? Those things arrive every 5 mins at least
I may just be being silly, but I donāt even think thereās a way of getting live tube data from transportapi let alone more obscure methods like trams.
But the TfL API now has decent tram support
Anyway, enough of my love of trams for now - thanks for looking at this, always good to see other UK folks in the HA game!
transportAPI appears to support train (and tram via TFL?), bus, boat, tube, car and cycling directions.
From the docs:
ātflā means to use Transport For Londonās journey planner (Plan a journey - Transport for London) which will only work in and around London, and some interchange destinations
around the country.
āsoutheastā means to use Traveline Southeastās journey planner (http://www.travelinesoutheast.org.uk/) which covers the whole UK, but the queries run more slowly, and the name matching can be more ambiguous.
When āserviceā is not specified, we automatically make an appropriate
choice. We select ātflā if both origin and destination are within
Greater London, or āsoutheastā if one or the other lie outside London.
Live bus data is not available for all stops. This operation will make use
of different live data sources including NextBuses (http://nextbuses.mobi/) and TfL Countdown (Stations, stops & piers - Transport for London), to
bring you a consistently formatted response with the best live data
available, or fallback to timetable. The results can be ordered by time or
grouped by bus route
The NextBuses datasource will be used for bus stops outside of London, and
outside of a few other areas where we have access to more direct live bus
data. NextBuses is a more expensive source and the charge is adjusted to 10
hits per request to reflect this. If you wish to avoid this hit charge and
use only the other data sources, add a nextbuses=no parameter.
OK after a hiatus making some progress on the UK transport component - posting progress here to get feedback on what people want. The component will show the route/line status and where appropriate the next departure time on train/bus/tram routes. Component currently makes use of the TransportAPI API (http://www.transportapi.com/) and the TFL API (https://api.tfl.gov.uk/).
This is a great idea, Iād definitely make use of a unified transport component. I also like your script to change the colour of your lights depending on the data you get back from these sensors.
Struggling to get this to work for my local buses. The example works.
The difference appears to be setting the destination, I presume this is the ādirectionā in the API.
The example shows setting this to Wantage, checking this in the API for the example stop it shows the direction as Market Place (Wantage). So from this should this be set to the bit in brackets. This worked for the example bus stop when I change it to Didcot, which in the API was: Parkway Station (Didcot).
Unfortunately for my local stop ā13004328Bā the destination doesnāt show anything in brackets just āStanley nr Crook Turning Circleā or something similar. Trying to enter this just breaks the component.
How should I select the bus stop destination in my case?
2017-07-31 12:52:41 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved Traceback (most recent call last): File "/usr/lib/python3.5/asyncio/tasks.py", line 241, in _step result = coro.throw(exc) File "/srv/hass/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 381, in async_process_entity new_entity, self, update_before_add=update_before_add File "/srv/hass/lib/python3.5/site-packages/homeassistant/helpers/entity_component.py", line 212, in async_add_entity yield from self.hass.async_add_job(entity.update) File "/usr/lib/python3.5/asyncio/futures.py", line 361, in __iter__ yield self # This tells Task to wait for completion. File "/usr/lib/python3.5/asyncio/tasks.py", line 296, in _wakeup future.result() File "/usr/lib/python3.5/asyncio/futures.py", line 274, in result raise self._exception File "/usr/lib/python3.5/concurrent/futures/thread.py", line 55, in run result = self.fn(*self.args, **self.kwargs) File "/srv/hass/lib/python3.5/site-packages/homeassistant/util/__init__.py", line 303, in wrapper result = method(*args, **kwargs) File "/srv/hass/lib/python3.5/site-packages/homeassistant/components/sensor/uk_transport.py", line 184, in _update _delta_mins, [bus['scheduled'] for bus in self._next_buses] ValueError: min() arg is an empty sequence
If I change the origin and destination to your example it works. I have tried putting my destination in quotes in case the spaces cause problems but still the same.
Thanks. Did you perform the troubleshooting described in the docs of manually checking the get request?
The component is actually searching the ādirectionā data, although this is labelled ādestinationā in the config
Thanks, yes I checked on their API reference page and that is where I got the direction value āWatergate Estate Ullswater Crescentā. As I mentioned this looks different to the values in the example. The API reference page GET request shows āMarket Place (Wantage)ā and you say to put āWantageā as the direction.
Hereās the relevant part from the GET request on the API page: