Earlier today I posted a tweet showing off a little shortcut I've made for Siri that can easily tell me when the next train departs a station. A few Twitterers have asked for a copy of the shortcut so I thought I'd better write a quick post about it. Here's the tweet with the example:
We're just asking Siri "When's the next train?" and she'll reply to say how many minutes until the next train departs a known station. My use case for this is so we can easily find out when a train will pass by our house - our son enjoys seeing the trains and waving to the driver's from the bridge and combining trains with a walk works well. This just tell us when we need to leave the house.
All the hard work happens well away from Siri and the Mac ecosystem using a combination of the Realtime Trains data and a little web service I've written that looks up the right information and composes some sentences for Siri to say.
Setting up an iOS Shortcut for Siri
These instructions outline how to set up a shortcut using iOS 13+. If you're using a different version of iOS, your mileage may vary!
- You'll need to install the Shortcuts app from the App Store.
- Press the Create Shortcut button to create a new shortcut.
- Press Add Action and search for Get Contents from URL and add this.
- For the URL enter https://trains.adam.ac/next/STATION. You should replace STATION with the code for your station - you can find this by going to Realtime Trains and searching for it - you'll see the code in the drop down search box. For example, for London Waterloo you would have WAT.
- Press the blue + button to add another action. This time search for Show Result and add this.
- You can now press the play (triangle) button to test your action and ensure that a message pops up with the text. Siri will speak the contents of this alert box if you ask her.
- Save the shortcut and enter a name such as When's the next train?
You should have a shortcut that looks a bit like this:
To use this on a HomePod, make sure that you have enabled Personal Requests.
At the moment, I don't have access to the detailed API from Realtime Trains so the data isn't being pulled in the best way possible - if anyone from RTT happens to be passing, if you could hook me up with the detailed API access, that'd be lovely! 😘
If you have any questions, just @ me on Twitter.