AutoNotification Table has been updated twice since I started the Tasker weather tutorial and this resulted in few improvements. Instead of showing you the final version only, I’ll also show you my first solution. Mainly, because I promised you the subroutines.
The profile is rather simple when we are no longer connected to a home WIFI (feel free to add more networks or create the dynamic location profile) a request is made to pull the current weather update with data reaching 12h ahead.
Tasker weather tutorial – Weather API
Create an account with openweather.org. Their API is free for up to 60 calls a day, and it’s simple to use. Once you have the account get your API key and take a look at the link for the HTTP GET request.
A few things to point out, &units=imperial if you want F degrees, and &cnt=5 tells you how many 3h intervals you want to download (5=current + 4 x 3h). Substitute the YOUR_LONGITUDE and YOUR_LONGITUDE from google maps. The reason why I’m using a fixed location rather than using get location is, that I want to receive a weather update the minute I leave the home rather than waiting an additional minute for a GPS fix. Just in case I have to get back to get an umbrella.
The HTTP get will save a .json file containing a data use plain text as data type and save it as weather.json. The file will be created and saved.
To use this data we have to load it to the variable using Read File action.
The .json file is a very specific data format. Take a look at the http://jsonviewer.stack.hu/. Paste the data and take a look how data is organized and stored. This will help you understand how to access these cells using AutoTools Json Read action.
For my notification I’m using the following:
- list.main.temp() – temperature (mine in C)
- list.weather.main() – condition name
- list.dt() – Time in sec
- list.weather.icon() – icon code
- city.name – location name
As you can see, the apart from the city.name, all data is stored in arrays. This means we will get multiple values. To access the tree structure we have to uncheck the ‘simple’ option. We are unable to use the simple methods as names are not unique (see main and weather word). The AutoTools Json Read action will load the cells into the arrays, but it will change the name of the relevant variables. Ie: list.main.temp() will become list_temp_main().
The FOR loop. The time is stored as a value in seconds. I’m only interested in the HH:MM format to be displayed. I have to convert each variable inside the array to the correct value. The %time variable will take the value of each variable from the array %list_dt() and will perform the conversion using AutoTools Time action.
AutoTools Time is set to operate in seconds (not milliseconds) and will ‘get rid off’ the date from the converted value. I used the custom output array %timecdate() – this is where the value will be stored.
Before we can take care of another entry in the %list_dt() we have to store this value. I will push the value to the new array %wtime() starting from the bottom. I have 5 values so my I will be pushing all the values from the 5th position moving the previous entries up. This way the final order in %wtime() will be the same as %list_dt().
If you want to know more about loops, subprocesses and flow control check out this video:
By the time you see this, this loop will be obsolete and the AutoNotification Table supports pictures directly. I decided to keep this regardless as the subroutine exercise. I will skip the loop description, as it does things in the same fashion as A4-A7. Instead of converting the time we take each value in the array %list_weather_icon() and change the value of it to an emoticon that corresponds with the weather condition.
Perform Task action will take each value assigned to %icon from the FOR loop and it will pass it as %par1 to another task.
The task checks the value of the %par1 and sets the variable to a defined weather condition. Once the correct value is assigned the information is returned to the loop via Return action (%returnicon) and pushed inside a new array.
The values for the icons and weather conditions available has been taken from the API help.
EDIT extra vibration on the rainy days:
I have added another 2 actions to this loop. Variable %rainalarm is set to a specific vibration pattern. If the %icon contains 9-11 in the name (matches Regex), it’s gonna rain. A more pronounced vibration is set. Otherwise, vibration is less apparent. To get the AutoNotification to vibrate in an alternative way, use the %rainalarm in the vibration pattern option of the AutoNotification Table action.
My set up checks each value of the %icon within the loop for rain. But you can narrow it down to a specific time slot by using %wicon(x) where x is the time slot. %wicon1 would be the current weather update. If you want to go for specific time slots, the Variable set actions have to be placed outside of the loop.
A12 or A13
We have the data formatted correctly already, all we need is plug that into the AutoNotification Table. There are 2 ways we can substitute the icons. If you were using the subroutine, the icons are already stored in the relevant arrays and your text field will look like this:
(bear in mind I have added the breaks to make the formatting clear, it should all be on one line separated by comma)
If you want to use custom pictures, place the day and night icon set into one folder. Icons should be named according to the API documentation. Instead of supplying the arrays, you have to add the path to the file:
You can use the same method to substitute the icons for the big icon and notification icon. The %list_weather_main1 variable contains the current condition and it’s the best for that purpose. Lastly, add the %city_name to the sub-text field and set the number of columns to 5.
Now, you have yourself a nice weather notification. Time to enable the context and action on touch in the Tasker weather tutorial.
Tasker weather tutorial – Open Weather Google
AutoNotification Table action should have a ‘openweather’ action assigned on touch. We are going to use AutoApps command trigger to launch our Weather Intent task.
You can pass a simple intent to launch the weather app in the Google now by setting the intent as follows:
Extra: query: WEATHER
You can also use the AutoShare to open the weather screen directly. Open the plugin, click on Get more intents and click on the Google Weather to download autoconfig. It’s that simple and it looks much better.
Tell me the weather when I leave home!
The context for this file is very simple. I’m using ‘not connected to home WIFI’ as my condition. This means the moment I leave the house I get the quick weather update. Just in time to head back and get the umbrella if there is a need for it!
Dealing with temperature #UPDATE
This section has not been included in the original tutorial. The piece is long and scary as is, but due to questions often leading to converting 15.67°C to 16°C I decided to include the small tutorial and update the final file.
We are going to need another FOR loop. In the same way as before – each element from %list_main_temp() will be rounded up with ceil function. We have to iterate the array and perform the maths operation on a %final_temp variable, then push it to a new array %final_main_temp(). A notification has to be updated accordingly as well.This should result in nice integers rounded up and stored in correct order.
By the end of the Tasker weather tutorial, you should be a master of AutoNotification Table. This notification is perfect for displaying organised data. I hope you will find this write-up useful.