Start a new topic
Answered

Private Weather App, powered by Dark Sky, with Google Apps Script backend

I was unhappy with stock weather app, because it refreshes infrequently (three hours old "current" temperature? Seriously?). So I quickly put together my own. 


It's a "push" Indicator App, and the push data is provided by Google Apps Script set to run every 15 min. Those scripts are hosted by Google (for free). The script retrieves data from The Dark Sky Forecast API (https://developer.forecast.io/). It's free up to 1000 request per day, but you have to register and get API key you need to put into the script:


  

function getDarkSkyWeather() {
  var result = UrlFetchApp.fetch("https://api.forecast.io/forecast/<PUT YOUR FORECAST API KEY HERE>/35.00,-120.00?units=si&exclude=flags,hourly,daily,alerts");
  //Logger.log(result);
  var json = JSON.parse(result);
  //Logger.log(json.currently);
  return json;
}

function convertDarkSkyToLaMetric(darkSkyJson) {
  var temp = darkSkyJson.currently.temperature;
  var icon = darkSkyJson.currently.icon;
  var minutelySummary = darkSkyJson.minutely.summary;
  var minutelyIcon = darkSkyJson.minutely.icon;
  
  return {
    "frames": [
        {
            "index": 0,
            "text": Math.round(temp) + "°",
            "icon": pickIcon(icon)
        },
        {
            "index": 1,
            "text": minutelySummary,
            "icon": pickIcon(minutelyIcon)
        },
    ]
  }
}

function pickIcon(icon) {   // clear-day, clear-night, rain, snow, sleet, wind, fog, cloudy, partly-cloudy-day, or partly-cloudy-night
  switch (icon) {
      case "clear-day": return "a2282";
      case "cloudy": return "a2283";
      case "rain": return "a2284";
      case "sleet": return "a160";
      case "partly-cloudy-day": return "a2286";
      case "snow": return "a2289";
      case "clear-night": return "i2314";
      case "wind": return "a2440";
      case "fog": return "i2158";
      case "partly-cloudy-night": return "i2152";
      default: return "i73";
  }
}
      
function executePost() {
  var payload = convertDarkSkyToLaMetric(getDarkSkyWeather());
  var options = {
        "method" : "post",
        "payload" : JSON.stringify(payload),
        "contentType": "application/json",
        "headers" : {
            "X-Access-Token" : "<PUT YOUR LAMETRIC ACCESS TOKEN HERE>"
        }
  };
  var result = UrlFetchApp.fetch("https://developer.lametric.com/api/V1/dev/widget/update/com.lametric.<PUT YOUR APP ID HERE>/1", options);
  Logger.log(result);
}       

  

gs
(1.93 KB)

Best Answer


1. Here you can find information on updating apps. We've added instructions.


2. Currently it is not possible to use icons from LaMetric Weather App, but you can create your own.

Please follow instructions in User Guide (7.6. Searching and creating icons).


And some great news: in the next LaMetric firmware the weather data on LaMetric Weather App will be refreshed once in 1 and half hour. 


Now, if only I could figure two things, it would be perfect:


1. It sorta looks like device (and the app store) stuck with V1, while I have V2 published already. How do I force it to update to V2?


2. Is it possible to use same icons as stock weather app? They are much nicer than ones I found in the gallery...

Answer


1. Here you can find information on updating apps. We've added instructions.


2. Currently it is not possible to use icons from LaMetric Weather App, but you can create your own.

Please follow instructions in User Guide (7.6. Searching and creating icons).


And some great news: in the next LaMetric firmware the weather data on LaMetric Weather App will be refreshed once in 1 and half hour. 

I as a new user am very unhappy with the stock weather app, refreshing is way more than 1 and a half hour, and one and a half hour itself is way too long.


Definitely a no go. Is there another solution in sight?


Thanks from Switzerland.


Fex



I agree with Fex 100%. Our weather can change in 20 minutes from sunny to stormy and the temperature can drop 20° in that same amount of time. The data needs to be checked every 30 minutes to hour and I think a different source than worldweatheronline might need to be used. The national weather service office has JSON data as one of the options but I'm not sure if it covers outside of the US.

Newbee... 

How do I use your app for Dark Sky? I have an key and have made some pythonscript to gather weatherdata but i do not know how to use apps you sharing.

Thanks in advance.

Stefan

Stefan,


I am not sure what you are asking about. If you've made your own Python script then you don't need my Google Apps Script which is what I am sharing here. As for the private app I have running on the LaMetric device, it is nothing special, I just went to https://developer.lametric.com and put together a two-frame, "Indicator"-type app with "push" communications. See attached screenshot.

Hi and thanks for the rapid response!

Sorry that i was unclear. I have tried the apikey to the Dark Sky with a python script. That was what i meant. 

I want to learn how to make a app for the Lametric and your code looks like a good start. I have never used online tools to program, just vim in Linux :D . I am in the dev page now but not sure where to put you code. Can you do a how to with the steps? I feel very stupid now because it says it is very easy and do not understand were to start...

I hope you can help me but i understand if you have other things to do.

Kind regards

Stefan

Hello again. 

I think i have figure it out. Put the code in google script and will now test it.

A good new way for me to learn more!

Kind regards

Stefan

Thanks!

I have got it to work and start to understand the basics.

Stefan

Viktor Z

I am hooked on this :D

But i am stuck a little again. I can only use currently data, but in your gs there in minutly also. That re guest do not work. Do I need paid key for that?

Kind regards

Stefan 

Stefan,


No, I am not paying anything and "minutely" info is there in the response. It is spelled "minutely" though, not "minutly". Make sure you are not misspelling it in you code too. And make sure you do not "exclude" it from the request.

Also, maybe the provider simply have no data for your location. Documentation says:  

Never make any assumptions about the presence of data or lengths of arrays. For example, a lack of data in our data sources may cause data to be missing

 

Ok, i have to try other locations and so on. I ve got resspnse in my pythonscript on daily.summary but for wrong day. I am trying to get that right also. Can you i fyou have time try to get data from daily.summary for Kristianstad Sweden lat 56.03129 long 14.15242? I would like to get a short forecast for the tomorrow. 

kind regards Stefan

Login or Signup to post a comment