One line weather summary

Home ScreenThe following is the relevant code to get Tasker, AutoLocation, Zooper and Forecast.io to display the one line weather summary on your phone.

It’s possible to not need AutoLocation and use the Tasker lat/lng but I was after testing the application, and you could use a different widget tool like Minimalistic Text, or even just a notification in the status bar.

Step 1:
Sign up to the API at Forecast.io https://developer.forecast.io/register
You don’t need to provide card details as the you get 1000 calls per day, and you shouldn’t get close to using them all (my peak is only 84 calls). At worst it would just stop working for the rest of the day.
Make a note of your API key.

Step 2:
Build this profile in Tasker (note you need your API key from step 1 as !!!!YOURAPIKEY!!!!)

Profile: Update Weather Text (46)
State: AutoLocation Location [ Configuration:Location Report Name: Weather ]
Enter: Weather V2 (28)
A1: Flash [ Text:Getting weather Long:Off ] 
A2: HTTP Get [ Server:Port:https://api.forecast.io Path:forecast/!!!!YOURAPIKEY!!!!/%allatitude,%allongitude Attributes:units=uk Cookies: Timeout:10 Mime Type: Output File: Trust Any Certificate:Off ] 
A3: If [ %HTTPR = 200 ]
A4: JavaScriptlet [ Code:var info = JSON.parse(global("HTTPD"));
flash(info.minutely.summary);
setGlobal("FORESUM", info.minutely.summary); Libraries: Auto Exit:On Timeout (Seconds):45 ] 
A5: Zooper Widget Pro Variable [ Configuration:#TWEATHERTEXT# = %TIME %FORESUM Package:org.zooper.zwpro Name:Zooper Widget Pro Variable Timeout (Seconds):0 ] 
A6: End If 
A7: AutoLocation Location [ Configuration:Stopping Location Monitor
Location Report Name: Weather
Update Type: No Power Package:com.joaomgcd.autolocation Name:AutoLocation Location Timeout (Seconds):0 ]

Step 3:
Build this profile in Tasker

Profile: Display Unlocked (61)
Event: Display Unlocked
Enter: Get Location For Weather (62)
A1: AutoLocation Location [ Configuration:Starting Location Monitor
Location Report Name: Weather
Update Type: Balanced Package:com.joaomgcd.autolocation Name:AutoLocation Location Timeout (Seconds):0 ]

Step 4:
Have a Zooper widget which has a text field with the content #TWEATHERTEXT#

Step 5:
Turn your phone off, wait a few seconds, then turn back on and unlock.
If the Forecast.io call is working you should first see a toast with “Getting Weather”, followed by the one line text.
You can remove these once you are happy everything is working, they are both in Weather V2, the first is at the top, the second is within the Javascriptlet, just delete flash(info.minutely.summary);

22 thoughts on “One line weather summary

  1. Hi,
    Would you mind to post a link to an XML export of this useful profile.
    I did create Both Profiles on my phone, but for any reasons, i cannot get the %FORESUM variable populated…(not using zooper actual, just trying to FLASH the %FORESUM variable…)
    I am afraid the javascriptlet section is the culprit !! (mainly because i do not understand this particular section…)
    thanks.

  2. JavascriptLet should just be
    var info = JSON.parse(global("HTTPD"));
    flash(info.minutely.summary);
    setGlobal("FORESUM", info.minutely.summary);

    spread over three lines in the Code box at the top, don’t touch anything else.

  3. EDIT: Sorry, just look thru the JSON content, and found out that for my actual location: there is no “minutely”…but only “hourly” summary….
    I did the swap in javascriptlet section, then it work fine, now…
    sorry for previous comment…
    bye

  4. Cheers for spotting, it should be possible to put a couple of ifs in to check minutely.summary, then hourly.summary, then daily.summary but I’ve not been anywhere which didn’t report minutely

  5. So, I was having trouble getting %allatitude and %allongitude to populate. I fixed this by changing the task in Step 3 — in the Autolocation Location plugin settings, I checked the box for “Retrieve First Location” and adjusting the Timeout from 0 (none) to 5 seconds. With these changes on my system, this works very well! THANKS for the ideas and tips! The JSON is very useful as now I can retrieve a bunch of different metrics to make a more accurate and detailed weather report.

    The updated Step 3 for me looks like:
    Profile: Display Unlocked (61)
    Event: Display Unlocked
    Enter: Get Location For Weather (62)
    A1: AutoLocation Location [ Configuration:Starting Location Monitor
    Retrieve First Location: true
    Location Report Name: Weather
    Update Type: Balanced Package:com.joaomgcd.autolocation Name:AutoLocation Location Timeout (Seconds):5 ]

  6. Hi Ryan,
    Thanks for the profile. However, I am trying to implement precipProbablity in my weather. I was trying
    flash(precipProbablity.hourly.data);
    setGlobal(“FORESUM”, precipProbablity.hourly.data);

    and this is not giving anything. I must confess I am a java illiterate so not sure what I am doing wrong.
    May you kindly help?

  7. Ryan,
    One last thing! though the forcast.io’s api is working fine, it does not show you warning type (yellow/amber/red). Do you have any thought about it?

  8. Question about setGlobal(“FORESUM”, info.minutely.summary);

    Using the example above should it work if I was to use like this? Should it set all these global variables? The only Global variables I can find within tasker after running that is the top 3 in the list.

    Any ideas?

    Thanks

    setGlobal(“FCSUMMARY”, httpdata.currently.summary);
    setGlobal(“FCDAY”, httpdata.daily.summary);
    setGlobal(“FCHOUR”, httpdata.currently.summary);
    setGlobal(‘READOUT’, string);
    setGlobal(‘FCTIME’, httpdata.currently.time * 1000);
    setGlobal(‘FCFCTEMP’, httpdata.currently.apparentTemperature);
    setGlobal(‘FCCONDITION’, httpdata.currently.summary);
    setGlobal(‘FCWINDSPEED’, httpdata.currently.windSpeed);
    setGlobal(‘FCWINDDIRECTION’, httpdata.currently.windBearing);
    setGlobal(‘FCHUMIDITY’, httpdata.currently.humidity);
    setGlobal(‘FCRAIN’, httpdata.minutely.data[50].precipProbability * 100);
    setGlobal(‘FCMAXTEMP’, httpdata.currently.apparentTemperatureMax);
    setGlobal(‘FCMINTEMP’, httpdata.currently.apparentTemperatureMinp);
    setGlobal(‘FCCLOUDCOVER’, httpdata.currently.cloudCover);
    setGlobal(‘FCPRESSURE’, httpdata.currently.dewPoint);
    setGlobal(‘FCVISIBILITY’, httpdata.currently.visibility);
    setGlobal(‘FCDEWPOINT’, httpdata.currently.dewPoint);
    setGlobal(‘FCOZONE’, httpdata.currently.ozone);

  9. The two things which jump out, but might not be the issue. You have setGlobal(‘READOUT’, string); what is string? Could this be causing the script to stop? Also from this point you’ve gone from double quotes ” to single quotes ‘ so this might be it.

    Ps your FCSUMMARY and FCDAY are the same string, and watchout for precipitation values as there is no array if the probability is 0.

  10. The READOUT ,string was from the original file js file I have been using that was posted on another site. They were using it to hold all the values they were using to have tasker say whatever was in READOUT variable.

    Thanks for replying. I have 0 programming experience and have been trying to figure out how to get this working. I started out with what was posted here http://pastebin.com/V11khyt4 and I am on revision 32 just trying to figure it out. 🙂

    Thanks again.
    Now I just want to figure out how to get the time in the script to be in 12hr instead of 24hr format.
    The temp to not use a decimal “it doesn’t need to be that accurate”.
    Wind without decimal and the winddirection to be in a N,S,E,W format.

    A lot to do but it has kind of helped me understand somewhat how its working.

  11. For the temp look at using the round() function eg setGlobal(‘FCMAXTEMP’, round(httpdata.currently.apparentTemperatureMax));

    For wind direction something like
    windB = httpdata.currently.windBearing;
    if(windB <= 45 || windB > 315) windL = 'N';
    else if(windB <= 135) windL = 'E'; else if(windB <= 225) windL = 'S'; else windL = 'W'; setGlobal('FCWINDDIRECTION', windL);

    Finally how are you converting the time in to text?

  12. I’m just using what was in the script,

    // Extract time of api request from UNIX time
    time = new Date(httpdata.currently.time * 1000);
    day = weekday[time.getDay()];
    months = month[time.getMonth()];
    date = time.getDate();
    if (time.getMinutes() < 10) {
    clock = time.getHours() + ":00" + time.getMinutes();
    } else {
    clock = time.getHours() + ":" + time.getMinutes();
    }

    // Extract time for sunset
    time = new Date(httpdata.daily.data[0].sunsetTime * 1000);
    if (time.getMinutes() < 10) {
    sunset = time.getHours() + ":0" + time.getMinutes();
    } else {
    sunset = time.getHours() + ":" + time.getMinutes();
    }

    // Extract time for sunrise
    time = new Date(httpdata.daily.data[0].sunriseTime * 1000);
    if (time.getMinutes() < 10) {
    sunrise = time.getHours() + ":0" + time.getMinutes();
    } else {
    sunrise = time.getHours() + ":" + time.getMinutes();
    }

  13. You could do something like
    time = new Date(httpdata.daily.data[0].sunriseTime * 1000);
    mins = time.getMinutes();
    if(mins < 10) mins = "0" + mins; hours = time.getHours(); if(hours > 12) hours = hours - 12;
    sunrise = hours + ":" + mins;

  14. Well, I’m starting to wonder if there’s maybe something wrong with Tasker. The only variables it will set are the ones below and I’m not sure why but those variables only show up when I go to the Home tab in tasker and look at the variables there. The dont show up in the variable list inside my project folder.

    setGlobal(“FCSUMMARY”, httpdata.currently.summary);
    setGlobal(“FCDAY”, httpdata.daily.summary);
    setGlobal(“FCHOUR”, httpdata.currently.summary);
    setGlobal(“FCCONDITION”, httpdata.currently.summary);

  15. @Danny – I use this code to make my own weather widget. Tasker is not likely the problem. Remember that Tasker will now “show” variables that are not uppercase (by design). You can find me on Google+ – maybe we can hangout and discuss the problem?

Leave a Reply

Your email address will not be published. Required fields are marked *

Human test: Enter Ryan backwards