Thanks for the help, I was guessing it was probably all my testing. No point in really adding the rate service unless you were using the API for more than just Home Assistant which I am not.
If I continue to hit limits then will look at forking but shouldn’t be necessary.
This is a great component! I love being able to ask Alexa “how long until the next bus!”. I may have found a bug though. Over night every night my logs get filled with the error message below. I have not had the time to debug this but I assume that as it only happens between 11 pm and 5am it is being caused as there are no buses during this period.
Aug 8 03:02:12 pi2 hass[16500]: ERROR:homeassistant.helpers.entity:Update for sensor.next_bus_to_redacted fails
Aug 8 03:02:12 pi2 hass[16500]: yield from self.hass.async_add_job(self.update)
Aug 8 03:02:12 pi2 hass[16500]: yield self # This tells Task to wait for completion.
Aug 8 03:02:13 pi2 hass[16500]: future.result()
Aug 8 03:02:13 pi2 hass[16500]: raise self._exception
Aug 8 03:02:13 pi2 hass[16500]: result = self.fn(*self.args, **self.kwargs)
Aug 8 03:02:13 pi2 hass[16500]: result = method(*args, **kwargs)
Aug 8 03:02:13 pi2 hass[16500]: _delta_mins, [bus[‘scheduled’] for bus in self._next_buses]
Aug 8 03:02:13 pi2 hass[16500]: ValueError: min() arg is an empty sequence
@bachoo786 I am moving our discussion from London tube status component to this thread. Your query was how to query an individual departure, in particular the 8:04 HRW to EUS.
My advice was to create a template sensor based on the scheduled departure time as described in the docs. One issue you have with that approach is that the base sensor returns data for more than 10 upcoming trains (in attributes.next_trains), so you will need to use a value template (or python script) to loop over each train to check against the scheduled departure of 8:04 OR have individual template sensors for each of the upcoming trains. I suggest the first approach, in particular using a python script which is triggered each time the base sensor is updated within a time window and fires a notify service when the departure of 8:04 is found. TBC
entity_id = 'sensor.next_train_to_eus'
attributes = hass.states.get(entity_id).attributes # attributes is a dict
next_trains = attributes['next_trains'] # next_trains is a list of upcoming trains, must access dict in this way
logger.warning("Number of upcoming trains is {}".format(len(next_trains)))
for train in next_trains:
estimated = train['estimated']
status = train['status']
operator_name = train['operator_name']
if estimated == '07:56':
logger.warning("Estimated departure at {} identified".format(estimated))
logger.warning("Status is {}".format(status))
if status == 'ON TIME':
hass.services.call('light', 'turn_on', { "entity_id" : 'light.lamp', 'color_name': 'green' })
else:
hass.services.call('light', 'turn_on', { "entity_id" : 'light.lamp', 'color_name': 'red' })
if operator_name == 'SOUTHERN RAIL':
logger.warning("Operator is {}, your'e buggered ".format(operator_name))
else:
logger.warning("Operator is {}, good luck ".format(operator_name))
After taking another look, it appears that the component doesn’t report the expected arrival time (although the transportapi does include it), therefore it is impossible to calculate the “next fastest train”, unless it is added in
My latest project on Hackster using this component, getting notifications and changing the colour of a light depending on the status of my morning train:
Hey @robmarkcole. Thanks for your effort with this module, I’ve used it to replace the useless national rail alerting service, and I will likely get it to interact with my lamp too
I’ve recently opened a feature request to add the ability to vary the refresh interval via automation. So, for example set it to every 10 minutes in the evenings and during the middle of the day when I don’t use the trains, and allow me to add a second sensor for my return journey without sacrificing the refresh interval during rush hours.
Is this possible or would it make things complicated?
Excellent job with this component. I have a few issues with it though which I’m unsure how to solve:
I can get multiple buses to my specific destination but the final destination for each bus is different, how can I do that without defining two configs?
On the contrary to 1 I can also get only one bus to my destination at another stop but there are multiple buses with the same final destination (which don’t get me to MY destination on the way).
Ultimately, I don’t want to specify a destination, rather I want to specify the bus number. This makes much more sense and I think it would suit way more peoples use cases if this were possible to do in the config.