I just came across an unofficial TransPerth API which gives access to Train, Bus and Ferry times as well as the ability to check your SmartRider balance.
I’m no developer but perhaps someone out there has the ability to integrate this to HA…
I finally got around to implementing this code and it seems to work, but where does the response end up? The script runs without issue but nothing else happens and I can’t find any entity with the response data.
Thank you so much for this. I have added this rest_command and some custom sentences to my voice assistant pipeline, and now I can ask my assist when the next train to Perth departs my local station. I like that the API tells you if there are delays.
I have an automation that triggers when I arrive at my local station and it runs the script then sends me a notification with how many minutes until the next train so I know if i need to go quickly or if I’ve got some time.
I thought about some interface or dashboard that said I need to leave in the next x minutes to make the train but they come so frequently and I have no real start time for work so there wasn’t any benefit.
alias: Notification - Train Time
description: ""
mode: single
triggers:
- entity_id: person.chris
zone: zone.edgewater_train_station
event: enter
id: Chris Arrived At Station
trigger: zone
conditions:
- condition: time
after: "06:00:00"
before: "10:30:00"
weekday:
- fri
- wed
- mon
- tue
- thu
actions:
- choose:
- conditions:
- condition: trigger
id:
- Chris Arrived At Station
sequence:
- repeat:
sequence:
- metadata: {}
data:
line: Yanchep Line
station: Edgewater Stn
response_variable: train_times_response
action: script.get_next_train_times
- variables:
next_train: "{{ train_times_response.to_perth | first }}"
second_train: "{{ train_times_response.to_perth[1] }}"
- metadata: {}
data:
title: Next Train To Perth
message: |-
{% if next_train is defined %}
Next train at {{ next_train.Departure }} in {{ next_train.mins_away }} mins ({{ next_train.StatusDetail }})
{% if next_train.mins_away | int <= 5 %}
The train after that is due at {{ second_train.Departure }} in {{ second_train.mins_away }} mins ({{ second_train.StatusDetail }})
{% endif %}
{% else %}
There are no trains to Perth on the Yanchep Line scheduled.
{% endif %}
action: notify.mobile_app_chris_mobile
- if:
- condition: template
value_template: "{{ train_times_response.to_perth | length == 0 }}"
then:
- stop: No trains scheduled
- delay:
hours: 0
minutes: >-
{{ max(train_times_response.to_perth[0].mins_away | int,
1.5 ) }}
seconds: 0
milliseconds: 0
while:
- condition: zone
entity_id: person.chris
zone: zone.edgewater_train_station
enabled: true