Calculating Compass Point Wind Directions in the iOS Shortcuts App

2019-10-16 - Calculating Compass Point Wind Directions in the iOS Shortcuts App main.jpg

I was messing around with the Shortcuts App today creating a “morning report” shortcut that would pull in a bunch of things to verbally brief when starting off my morning. One of those things was weather. The built-in iOS app Shortcuts (at least it is built in as of iOS 13) has a ton of weather information at your fingertips. So pulling out the exact weather parameters of your choice to use as you wish within the Shortcuts app is super easy. But I ran into a bit of snag. I wanted to hear the current wind direct in terms of North, East, South and West instead of numerical, but that information wasn't a built-in parameter you could easily pull from any weather app within Shortcuts as they all have you a numerical 0-359 degree value. So I opted to create my own Shortcut that would take the numerical compass direction and convert it into:

  • North
  • North Northeast
  • Northeast
  • East Northeast
  • East
  • East Southeast
  • Southeast
  • South Southeast
  • South
  • South Southwest
  • Southwest
  • West Southwest
  • West
  • West Northwest
  • Northwest
  • North Northwest

When you are first waking up in the morning the last thing you want to do is have to convert a number into a direction. So I figured I would just create a simple shortcut to do the calculation for me. Unfortunately it was a little more complicated that I would have liked...

I’m going to go on a bit of a rant here. I have a little bit of coding background, both from a schooling standpoint and from professional experience. So my rant may seem a little bit misplaced as the Shortcuts app is made for people with ZERO coding background to be able to automate tasks. But with that being said, with every iteration of Shortcuts the app keeps getting more and more powerful. But at some point they (Apple) will hit an effectiveness wall unless they employ some more powerful scripting methods. Shortcuts has an enormous amount of potential, but unless more efficient coding logic options are added it is going to make creating complex too much of a hassle. End of rant…

With all that being said, I am still a huge fan of Shortcuts and really enjoy being able to automate things both in my daily life and in work related tasks in iOS.

So for calculating the N-S-E-W directions for the wind given a degree directionality input I simply created a series of “If” loops to find the right directional slot for the wind given the degree information I was fed from my iOS weather source. In my Shortcut I am using CARROT weather, but if you don’t have that app you can also use the built-in weather app in iOS (it uses information supplied by the Weather Channel). I chose not use to the built-in weather source as I was having issues being able to pull wind direction from that source. So for every “If” statement I had I looked at a range of degrees in which I would call a wind “North” vs “Northeast” vs “North Northeast” and used the “If” loops to set a variable to the text of my choosing based on the degree directionality I was given by the weather app. There is another way to do it within the Shortcuts app and that is to use a dictionary lookup. You can do this by dividing the wind direction in degrees by “45” and rounding down and taking that number and breaking up the wind directions into numerical dictionary lookups items. I chose to break up my wind directions a bit more by then just 8 directions and went for a full 16 different directions. I tend to go out on bike rides a lot so a North wind is a lot different than an a Northeast wind. Its nice to be prepared for the pain…

My quick sketch of how the degree directionality broke out on the compass

My quick sketch of how the degree directionality broke out on the compass

So here is my Shortcut if you want to download it and use it for your own purposes. The Shortcut doesn’t need any inputs. Just run it and It simply calls the CARROT weather app and gets the current wind direction based on your current location (if you would rather use the built-in weather source just go into the Shortcut and make the change) and returns one of the 16 text options I listed above as output. So you can call this Shortcut and use the text response in any way you see fit.

When the shortcut first runs and calls the weather app it gets back a numerical heading in degrees for the wind direction. This is where I also ran into to some “wonkiness” with Shortcuts. At first the Shortcuts app didn’t want to recognize the CARROT weather wind direction converted into a number as a number so it was trying to treat it as a variable. So the first “If” statement I tried to add would not let me evaluate the variable other than to see if the variable had a value or was empty. So I had to run the Shortcut and have it ping CARROT weather, and then finally it recognized that the value I was giving it was really a number. This is another example of where Shortcuts is trying to outsmart the user but in this case it ended up overly constraining my logic options while coding until I ran the partial shortcut so the app understood the type of data I was dealing with. Again, I shouldn’t complain but I’m going to.

Anyway, that is how I converted a degree directionality for wind source into a text-based wind direction.

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.