HomeTaskerTrain schedules and delays with Tasker

Train schedules and delays with Tasker

Get the Google Train updates before you reach the station

Train schedules and delays Tasker

There has been a  profile for driving, cycling and getting back to the car or saved location already. We are missing a public transport profile to close this experimental mini-series. The train schedules and delays Tasker project aim to give you the information you need. If Google Transit covers your country, this should work for you. You can check if your location is supported here:
https://maps.google.com/landing/transit/cities/
For a while now I have been trying to get the train schedules and delays available to me on request.  I have noticed, that Google Now gives you the train schedules and delays card, but the card isn’t available until you get to the train station. I plan some of my journeys but I find entering each train ticket very impractical to receive Leave Now Card.
A few tests later I was able to display this card with a live train table on request:

Limitations

Because Google is being clever and all that, Cards should be displayed on your device when Google thinks you need it, not when you would like to see one. This means that there are situations when the card with the schedules and delays may not be displayed when you have a calendar event with a location in the same city within next few hours.
Removing the location from the event works, and the  Google Now Card is reporting correctly.
While the train updates show up instantly, going back to the original location may take few moments. Bear in mind this will mess up your %LOC variable in Tasker until the next GPS fix is available.

Train schedules and delays Tasker Profile

For the purpose of this tutorial I will split the request into two triggers:

Dialog request

Manual Lookup
Manual Lookup
	Abort Existing Task
	A1: AutoTools Dialog [ Configuration:Dialog Type: List
		Title: Pick the train station
		Icon: /storage/emulated/0/
		Material-Icons-011017-121644/res/drawable-xxxhdpi/ic_train.png
		List Type: 0
		Texts: Yarn,Manchester
		Text Size: 20
		Text Color: #E3F2FD
		Button Text Color: #E64A19
		Image Width: 100
		Commands: 54.4939:-1.3516,53.4774:-2.2309
		Dim Background: true
		Top Margin: 16
		Bottom Margin: 16
		Bottom Buttons Top Margin: 16
		Bottom Buttons Bottom Margin: 16
		Close On Select: true
		Separator: ,
		Command Variable: atcommand
		Cancelable: true
Turn Screen On: true Timeout (Seconds):60 ] 
	A2: Variable Split [ Name:%atcommand Splitter:: Delete Base:Off ] 
	A3: Variable Set [ Name:%lat To:%atcommand1 
		Recurse Variables:Off Do Maths:Off Append:Off ] 
	A4: Variable Set [ Name:%lon To:%atcommand2 
		Recurse Variables:Off Do Maths:Off Append:Off ] 
	A5: AutoLocation Mock Location [ Configuration:
		Starting Mock Locations
		Persistent Notification: true
		Notification Title: We are set your location to %attext
		Notification Text: Don't worry it will get cancelled soon.
		Latitude: %lat
		Longitude: %lon
		Accuracy: 10 Timeout (Seconds):0 ] 
	A6: Variable Set [ Name:%LocationTimeout To:%TIMES+180
		Recurse Variables:Off Do Maths:On Append:Off ]


In this scenario, the coordinates for each station have to be assigned manually, this is a great way of adding your train stations for the commute or regular travels.
To start with this, we will need to use Google to find the exact coordinates for each station in question. Google maps won’t show you the coordinates directly if a named location is displayed, but you can find it in the URL of the location:

https://www.google.co.uk/maps/place/Leeds+Station/@53.7943125,-1.5497304,17z

The Latitude is first (53.7943125) and the Longitude second (-1.5497304). We need to format it so we could use it with the AutoTools Dialog action:

53.7943125:-1.5497304 (please note the colon)

A1

My AutoTools Dialog action stores the names of the stations in the Text field (separated by comma) and the associated coordinates are stored in the Commands field  (also separated by comma):

  • Yarm, Manchester
  • 54.4939:-1.3516,53.4774:-2.2309

The dialog will be closed once the option is selected.  You can find this behavior in advanced settings.

A2-A4

I need to split these when the appropriate option is pressed and separate the coordinates with the splitter ‘:’ (colon) Next, just store the %atcommand1 in %lat and %atcommand2 in %lon using Variable Set action.

A5

These values will be used in AutoLocation Mock Location action as Latitude and Longitude entries. I will also pass the %attext in the associated notification because I’m fancy like that!
Accuracy 10m is enough to get the Google Now triggered.

A6

Lastly, I will create a timeout by setting the variable %LocationTimeout to %TIMES+180 (or however long in seconds you wish to keep the fake location on) Select ‘do math‘. That action will trigger our canceling profile later.

Voice request

Lookup any Train station
Profile: Lookup any Train station
	Event: AutoVoice Recognized 
        [ Configuration:Command: "show me trains at*. (regex)" ]
Enter: AutoLocation lookup (81)
	A1: AutoLocation Info [ Configuration:Coordinates 
            Search Query: %avcommnofilter
Coordinates Max Results: 1 Timeout (Seconds):60 ] 
	A2: AutoLocation Mock Location [ Configuration:
            Starting Mock Locations
            Persistent Notification: true
            Notification Title: I'm pretending that you are at %avcommnofilter
            Notification Text: I will reset the location soon
            Latitude: %alcoordenatelatitudes1
            Longitude: %alcoordenatelongitudes1
Accuracy: 10 Timeout (Seconds):0 ] 
	A3: Variable Set [ Name:%LocationTimeout To:%TIMES+180
            Recurse Variables:Off Do Maths:On Append:Off ]

A1

The AutoLocation Info action is used to get the coordinates of the train station. I’m limiting the results to one entry only. This way I will know where in the %alcoordenatelatitudes() and %alcoordenatelongitudes() arrays (please note the spelling mistake in the variable – I will get this reported).

Profile

To pass the name of the train station I’m using the AutoVoice recognize event. The command filter is: show me trains at*. (regex)  (using the hard way option). The name of the train station will be stored in the %avcommnofilter variable, which is used to perform the AutoLocation Info action for the coordinates search.

A2

Once the coordinates are known, I simply use again AutoLocation Mock Location action to start the service  with Latitude = %alcoordenatelatitudes1 and the Longitude = %alcoordenatelongitudes1 (I’d limited my result to 1  for that precise reason)

A3

Lastly, I’m adding the same action variable set, to trigger the end of location spoofing. Set the %LocationTimeout to %TIMES+whatever seconds you wish.

Cancel the Location spoofing

End fake location
Profile: End fake location (84)
	Time: From %LocationTimeout
Enter: Cancel fake location (82)
	A1: AutoLocation Mock Location [ Configuration:
Stopping Mock Locations Timeout (Seconds):0 ] 
	A2: Variable Clear [ Name:%LocationTimeout Pattern Matching:Off ] 


A very simple task, in which AutoLocation Mock Location gets unchecked and cancelled and the variable %LocationTimeout cleared.

Conclusion

Sadly the Train schedules and delays Tasker profile can’t be used for now to get the same information from the coach stations. I hope this will change in the future. I find this project to be a very handy solution whenever I want to check the status of a train I’m trying to catch. What are your thoughts?

Project Download

Download project files here. Bear in mind that Patreon supporters have early access to project files and videos.

PayPal

Nothing says "Thank you" better than keeping my coffee jar topped up!

Patreon

Support me on Patreon and get an early access to tutorial files and videos.

image/svg+xml

Bitcoin (BTC)

Use this QR to keep me caffeinated with BTC: 1FwFqqh71mUTENcRe9q4s9AWFgoc8BA9ZU

New to Tasker?

Tasker Quick Start – Getting started with Tasker

0
From newb to not so newbie in 10 min

Best Tasker Projects

How to use Raspberry PI as WOL (wake on lan) server

0
While you could wake up your PC from a mobile directly, having a dedicated server capable of doing so is the best solution. The reason is simple. You can hook up as many devices as you wish with a single endpoint. This is why Raspberry Pi is perfect for this.

How to wake on LAN computers and put it to sleep with Power Menu,...

0
How to Wake on LAN properly via Android, Alexa, Google Assistant and Web

7 awesome Bluetooth keyboard shortcuts for Android

0
7 unique Android shortcuts that you can add to any Bluetooth keyboard.

Smart overnight charging with Tasker

0
Still keeping your phone plugged in overnight? Try smarter overnight charging with this profile

One thing that Join app can’t do and how to fix it with Tasker

0
It's not possible to share the clipboard automatically between join accounts registered to 2 different emails. But you can fix this with tasker.

Essential Guides

Tasker: Seconds into DD:HH:MM:SS (dynamic)

0
It's time to.... ok it's a pun, but I will show you how to master time and convert seconds to DD:HH:MM:SS dynamically

4 ways to organise Tasker projects

0
Keep your Tasker tidy!

A better way to store Tasker credentials

0
The more clever way of managing credentials

Annoyed with dozens of AutoApps populating your app drawer? Here is a fix!

0
Clear your app drawer from the clutter in seconds

Putting AutoTools pie chart to a good use – SSID logger

0
Who wants a piece of the pie (chart)?