LightBlog

samedi 14 janvier 2017

Create an On-Demand Train Schedule/Delay Notifier with Tasker

Recently, we've shown you how to create profiles to save your parking spot or to start navigation while avoiding tolls/highways/ferries. Continuing our trend on commute-related Tasker scripts, we will create a script aimed at people who frequently use public transportation. This Tasker project will create a schedule of train departures and delays to give you the information you need to plan your commute. If Google Transit covers your particular locale, this profile should work for you.

For quite awhile now I have been trying to get the train schedules and delays on request.  I have noticed that Google Now can show you the train schedule and delay card, but the card isn't available until you actually reach the train station. I plan some of my journeys ahead of time and I find entering each train ticket to receive the "Leave Now" card very impractical. A few tests later I was able to display this card with a live train table on request, however, there were some caveats:


Limitations

Because Google Now tries to cleverly serve your information, cards are only displayed on your device when Google thinks you need it, not necessarily when you would actually like to see one. This means that there are situations when the card with the train schedules and delays may not be displayed even though you have a calendar event with a location in the same city within the next few hours! Removing the location from the event fixes that and the Google Now Card should report correctly.

While the train updates show up instantly, going back to the original location may take a few moments. Bear in mind that this will mess up your %LOC variable in Tasker until the next GPS fix is available. If these limitations do not bother you, then read on to implement this on-demand train schedule notifier!

You will need:
Android version: 4.0+,
Apps: Google App (with Google Now enabled)
Plugins:  AutoLocation, AutoToolsAutoVoice (optional)
Needs: Mock Location enabled (see developer options)


Train Schedule and Delays with Tasker

For the purpose of this tutorial I will split the request into two triggers:
Train schedules and delays Tasker

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 regular commutes. To start, we will need to use Google to find the exact coordinates for each station in question. Google Maps won't show you the GPS coordinates directly if a named location is displayed, but you can find it in the URL of the location. For example, the coordinates for Leeds Station is bolded in the URL below:

  http://ift.tt/2jjDxPC53.7943125,-1.5497304,17z/data=  

The Latitude is first (53.7943125) and the Longitude second (-1.5497304). We need to format it so we can 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 two Variable Set action.

A5

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

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 for). Select 'do math'. That action will trigger our canceling profile later.

Voice request

Voice Request

  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 profile 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 – this is how AutoLocation names the variable. The developer is aware of this and plans to fix it in his next update.)

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 the AutoLocation Mock Location action again to start the mock location service with Latitude = %alcoordenatelatitudes1 and Longitude = %alcoordenatelongitudes1 (I would limit my results to 1 for more precision).

A3

Lastly, I'm adding the same action Variable Set as mentioned earlier to trigger the end of location spoofing. Set the %LocationTimeout to %TIMES+180 (or however long you want to wait before timing out).

Cancel Location Spoofing

Cancel the location spoofing

  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 the AutoLocation Mock Location gets unchecked and canceled, and the variable %LocationTimeout is cleared.


Conclusion

Sadly the Train schedules and delay Tasker profile can't be used for now to get the same information from 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.

Download the project file on AndroidFileHost!

In order to import a Tasker project file, download the above file and save it anywhere in your internal storage. Open up Tasker and check to make sure that "beginner mode" is disabled in the preferences menu. Then, long-press on the "home" icon in the bottom left hand corner and click on "import". Find the prj.xml file you saved earlier, and select it to import it. You will now see a new tab in the bottom row containing all of the profiles and tasks we referenced in this article.

We hope you enjoy this little creation of ours, and let us know if you think we can make any enhancements!



from xda-developers http://ift.tt/2juZngX
via IFTTT

Aucun commentaire:

Enregistrer un commentaire