Can anyone help with templates for retrieving the “next fastest train” instead of the “next train” given in examples?
sorry, I don’t know much about repositories, I don’t understand what to do that!
Sorry that message was meant for another thread.!
Next_trains is an ordered list, so adapt the example in the docs for whichever train you want
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
Working on a table to show all train data, check it out
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?
Just need to add a service to update the scan interval, perhaps you could submit a PR?
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.
Thanks!
HI @mderrick it appears from the API (https://developer.transportapi.com/docs?raml=https://transportapi.com/v3/raml/transportapi.raml) that queries are by bus/train stops only, and I don’t see any queries for specific bus/train id. There might be another service online that provide the info you need and I suggest a Google
Cheers
I think maybe you mis understood what I mean. I still want to query via bus stop. However I want to get only a specific bus number for that stop INSTEAD of providing a destination because of the above scenarios.
The API groups results by bus number already so should be relatively easy I believe. Is this something you’d consider adding?
e.g:
- mode: bus
origin: 490004533N
route: 69,97 # No destination is required and multiple routes possible
I think this is significantly more useful as a destination of a given bus doesn’t mean it goes to where I need to go. Especially when two busses have the same destination but take different routes. I hope that makes sense now.
Thanks!
Matt
I agree this is a nice idea, however I’m moving house and getting married so not much spare time. Perhaps you can work on a PR?
Hey guys,
Loving this component so far, but finding the API limit to be a little tight, considering I need 4 buses and 2 train updates.
I’ve thought of two ways to make it work:
-
Limit the time the component refreshes - as in making it only update between 8am and 5pm.
-
Having the component actually update the info - by this I mean that when the transportAPI returns that the next bus is in 5 minutes, homeassistant actively starts counting down from 5 minutes, until the next transportAPI update arrives, and it changes to that. This would mean a glance at HA would give more accurate bus times, rather than delayed ones I currently have due to API limits.
Any thoughts on how to achieve either of these?
Thanks!
I do this to restrict sensor updates when no trains are scheduled. It seems to work ok for me but I don’t think it will be accurate for the first trains of the day. To be honest it isn’t a critical component for me so I’m not too bothered. It might give you food for thought though.
I hope it helps.
#================
#=== Automations
#================
automation:
#==================================
#=== Set up timing of sensor calls
#==================================
- alias: my_trains_sensor
initial_state: on
trigger:
- platform: homeassistant
event: start
action:
- service: script.set_interval_for_my_train_sensor
#============
#=== Scripts
#============
script:
#===================================================
#=== Set interval for the train sensor
#=== Reduce sensor calls when no train is scheduled
#=== 1000 api calls allowed per day
#=== equal to once every 87 seconds
#===================================================
set_interval_for_my_train_sensor:
sequence:
- service: homeassistant.turn_off
entity_id: script.update_my_train_sensor
- delay: "00:00:02"
- service_template: >
script.update_my_train_sensor
data_template:
interval: >
{% if states('sensor.next_train_to_xxx') == "No departures" or
states('sensor.next_train_to_xxx') | int > 30 %}
00:30:00
{% else %}
00:01:00
{% endif %}
#========================================================================
#=== Update the sensor and loop the script that sets the sensor interval
#========================================================================
update_my_train_sensor:
sequence:
- service: homeassistant.update_entity
entity_id: sensor.next_train_to_xxx
- delay: "{{ interval }}"
- service: script.set_interval_for_my_train_sensor
Hi Klogg, thanks so much for the input! Still relatively new so going to spend some time breaking that down and working out how to apply it to a time window rather than waiting for sensor to say “no departures”, but I’ll be sure to share if I succeed!
HI chaps, see this comment in HA release 0.81
- We have a new service
homeassistant.update_entity
to request the update of an entity, rather than waiting for the next scheduled update. This means you can set a really longscan_interval
in the platform_options and then update on demand, ideal for those services where you have low API limit.
Note, I created a PR to add this to the docs
Yes, thanks, this is pretty much what I do.
I set it to 1 minute normally but when the trains stop running it gets set to 30 minutes. This will cause a delay of up to 30 minutes before it gives the first train times every day. Not ideal and I can think of better ways to do it but it is of no consequence to me currently.
Anyway, thanks for this component I really like it.
Thanks, this looks like the exact thing I needed.
Following from this, I added this, I added the line “scan_interval: 2000” to my configuration.yaml for the transport sensor, and added the below to my automations.yaml
alias: Update Transport API
initial_state: on
trigger:
- platform: time
minutes: '/1'
seconds: 00
condition:
- after: '08:00:00'
before: '17:00:00'
condition: time
action:
- data:
entity_id: sensor.next_bus_to_X
service: homeassistant.update_entity
I can see that the automation is triggered in the logbook, but the sensor doesn’t update every minute - only every three/four, which is a problem for accurate bus times!
I think it might be to do with the specific uk-transport component, because I’ve set up the automation with other sensors and they work just fine.
Thanks!
Well it might be that there is no new data for the API to display