On the heels of the first foray into Shortcuts with iOS, I happened to stumble across a suggestion in Shortcuts Gallery, that seemed to suggest that the phone could perform functions if it discovered itself in a particular environmental situation. Specifically, When AndysiPhone connects to “Mazda” and pointing to Bluetooth connections themselves. I poked around in this suggestion to learn there was an entire “Automation” section that I had completely glanced over.
I lease my Mazda CX-5, best car I’ve ever owned, by the way, and so I have a strict limit on the miles for the vehicle. Every morning when I use the car, I record the mileage so I can track it. Originally this was on pen-and-paper, but then I moved it into a text file, and after that, to Google Sheets. Then I discovered the Notes widget in IFTTT, and for the longest time I would call on the Notes widget in IFTTT, type in the mileage, and then hand it to IFTTT to add the mileage I entered, along with the date and time, to my Google Sheets. This worked well, when I had the presence of mind to remember to fire off the IFTTT widget, that is. Then after I had my first foray into Shortcuts, I discovered that my phone could recognize when it connected to my Mazda’s Bluetooth system. That event is the perfect trigger to ask for mileage! I knew that IFTTT was still good to help me automate Google Sheets, but I had to reconfigure how IFTTT worked so it would work with Shortcuts and not IFTTT’s own Notes widget. Here’s how I did it:
In the Automation section of Shortcuts, I created this. If the “When” section is met, the “Do” section executes. In this case, it’s a Shortcut.
The Shortcut begins with a “Ask for Input” from the Scripting group. Ask for a Number, because all I care about is mileage, and I only want a handy number entry pad.
Next I went to IFTTT, created a WebHook which is linked to my Google Sheets Mileage Intake Log. The WebHook is called “mileage_log”, and the key is a private string that you get from the WebHooks documentation in IFTTT. The Text object lets me configure the URL with the mileage added after “?value1=” at the end of the URL.
Then I set a variable based on the text in the Text Object, so it can be used as a variable moving forward.
Next is to grab the “URL” object from the Web group. I feed it the variable from above, which is really just making my phone emit a WebHook call to IFTTT with my mileage in it.
Next I use “Get Contents of URL” from the Web group to fetch the response from the WebHook call. I’m looking for “Congratulations” in the response from IFTTT.
The Text object is set to get this response from IFTTT, and there is a trick here, you need to set the type of the data for the Text object as Text, not URL, or anything else, it takes a long tap to find this hidden setting. Tricky…
I next used the If object from Scripting group. Here is where the trick gets you. If you don’t change the type of data that If receives, you will only get “If there is something” vs. “If there is nothing” and that’s it. What you want is “If A contains B” and the only way to get “contains” is if the input data is text! So here is where we evaluate the IFTTT WebHook response, find the “Congratulations” in the output, and then using the “Show Notification” from the Scripting group, I pop up a little alert showing “Success!”, then the If ends, and the Shortcut ends.
So now I won’t have to remember to hit a IFTTT Widget button when I start my car in the morning. The Bluetooth itself will be enough for my phone to notice and ask me for my mileage, and then pass everything to IFTTT, so it can add a timestamp, and pass that onto Google Sheets.