Using the app and key I am able to use the online api to check that everything is working. This returns everything as expected.
But in HA I get the attributes in the sensor:
unit_of_measurement: min
next_buses:
icon: mdi:bus
request_time: 2019-03-17T18:55:31+00:00
locality: XXXXXXXXX
stop_name: XXXXXXXXXX
atcocode: XXXXXXXXXXX
friendly_name: Next bus to Bus Station
redacted for privacy.
But the state remains as Unknown.
I have tried a number of different destinations, but can’t get it to work. I know all the other data works as that is needed for the online api check. I have read the python script for the component, and understand what it is doing, but frankly my python isn’t good enough to debug it.
Thanks for that, still doesn’t work. My formatting seems to match yours.
I am wondering if it is something to do with the destination having a space in it, which is why I tried the quotes.
What I would really want is to make the destination an optional input, or allow it to take wildcards. Looking on the api the destinations are not consistently named (at least for the routes around me), so using a fixed destination will mean missing some busses or running multiple sensors.
It all relates to the destination field, as I expected.
The direction shown in the API request is name of the final bus stop. That didn’t work for me. Instead what I did was.
Did the API request as explained in the documentation
Found the line “id”, which returns a url for that route based on the API request
Navigated to that url, which is the json of the entire bus route you requested (can be very long)
Scrolled to the bottom to find the terminating bus stop
In the last bus stop found the field “locality” and used that as my Destination in my configuration.ymal
I have tried using the locality for stops before the last stop, but that doesn’t seem to work (based on how the component is currently written).
Hope this helps people in the future, I hope the docs get updated to reflect this and longer term someone who is good enough at python changes the component to be a little more flexible (as the API doesn’t need destination/direct, why does the component mandate it?).
Good Morning @Targettio I have exactly the same problem I think. The API call works and I have tried to pull the locality from the last entry as you did in step 5. but i still get the message
WARNING (SyncWorker_18) [homeassistant.components.uk_transport.sensor] Invalid response from API
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus estimated, the state is unknown.
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus route, the state is unknown.
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus scheduled, the state is unknown.
WARNING (MainThread) [homeassistant.components.template.sensor] Could not render template Next bus direction, the state is unknown.
{
time: "10:17",
date: "2019-11-28",
atcocode: "0100BRP90373",
name: "The Centre (C1)",
stop_name: "The Centre",
smscode: "bstgajm",
locality: "Bristol City Centre, Bristol",
bearing: "S",
indicator: "C1",
latitude: 51.45381,
longitude: -2.59696
}
I am tenatious so i want to get it to work, it worked previously until i moved house! I am considering using a scrape of the web page, but it really shouldn’t be that difficult should it.
any help greatly received.
I just want to thank everyone who has contributed to this thread. This is the first Home Assistant Automation that I’ve got to work on the start of the journey. It was really satisfying. I was getting frustrated last night as nothing was showing… I then came back this morning, and of course everything had populated… I guess as I was doing it at stupid o clock and there weren’t any immediate trains. Still got to get buses to work, but trains feels like a victory.
One query… the “… mins till next train” countdown… using the free API, I can’t set my refresh rate high, as I am trying to get a few different sensors working all at once… I am wondering if it is possible to have the countdown calculated by the difference between the system clock and the live updated time, as I am guessing at the moment, it only calculates on refreshing the update from the API?