Private Weather App, powered by Dark Sky, with Google Apps Script backend
V
Viktor Z
started a topic
about 8 years ago
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);
}
var minutelySummary = darkSkyJson.currently.summary;
var minutelyIcon = darkSkyJson.currently.icon;
var currentlywindSpeed = darkSkyJson.currently.windSpeed + " m/s";
var currentlywindIcon = "a3363";
var currentlywindRikt = darkSkyJson.currently.windBearing;
var vindriktIcon = "a12194";
var currentlyTrycket = darkSkyJson.currently.pressure + " hPa";
var TrycketIcon = "a2272";
var kommande = darkSkyJson.daily.summary;
return {
"frames": [
{
"index": 0,
"text": Math.round(temp) + "°",
"icon": pickIcon(icon)
},
{
"index": 1,
"text": minutelySummary,
"icon": pickIcon(minutelyIcon)
},
{
"index": 2,
"text": currentlywindSpeed,
"icon": currentlywindIcon
},
{
"index": 3,
"text": degToCompass(currentlywindRikt),
"icon": vindriktIcon
},
{
"index": 4,
"text": currentlyTrycket,
"icon": TrycketIcon
},
{
"index": 5,
"text": kommande,
"icon": TrycketIcon
}
]
}
}
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" : "xx"
}
};
var result = UrlFetchApp.fetch("xx", options);
Logger.log(result);
}
Stefan Rydberg
said
over 6 years ago
Ok.
Looks like i have to better lat long or something. Thanks.
I have to learn how to see the result i gs also....
Getting there...
Kind regards
Stefan
V
Viktor Z
said
over 6 years ago
You can use those Logger.log functions to see results. You can uncomment them, run your code and then click "View / Log" menu
Stefan Rydberg
said
over 6 years ago
Great!
Stefan Rydberg
said
over 6 years ago
It was the exclude that i have not seen....
Hourly works now, daily give wrong day.
Kind regards
Stefan
Kevin O
said
almost 7 years ago
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.
LaMetric Support
said
almost 8 years ago
Answer
1. Hereyou 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.
Stefan Rydberg
said
over 6 years ago
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
V
Viktor Z
said
over 6 years ago
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.
Viktor Z
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:
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.
- Oldest First
- Popular
- Newest First
Sorted by PopularStefan Rydberg
This is what i done
function getDarkSkyWeather() {
var result = UrlFetchApp.fetch("https://api.forecast.io/forecast/xxxx/56.03129,14.15242?lang=sv&units=auto&exclude=flags,hourly,daily,alerts");
//Logger.log(result);
var json = JSON.parse(result);
//Logger.log(json.currently);
return json;
}
function degToCompass(num) {
var val = Math.floor((num / 22.5) + 0.5);
var arr = ["N", "NNÖ", "NÖ", "ÖNÖ", "Ö", "ÖSÖ", "SÖ", "SSÖ", "S", "SSV", "SV", "VSV", "W", "VNV", "NV", "NNV"];
return arr[(val % 16)];
}
function convertDarkSkyToLaMetric(darkSkyJson) {
var temp = darkSkyJson.currently.temperature;
var icon = darkSkyJson.currently.icon;
var minutelySummary = darkSkyJson.currently.summary;
var minutelyIcon = darkSkyJson.currently.icon;
var currentlywindSpeed = darkSkyJson.currently.windSpeed + " m/s";
var currentlywindIcon = "a3363";
var currentlywindRikt = darkSkyJson.currently.windBearing;
var vindriktIcon = "a12194";
var currentlyTrycket = darkSkyJson.currently.pressure + " hPa";
var TrycketIcon = "a2272";
var kommande = darkSkyJson.daily.summary;
return {
"frames": [
{
"index": 0,
"text": Math.round(temp) + "°",
"icon": pickIcon(icon)
},
{
"index": 1,
"text": minutelySummary,
"icon": pickIcon(minutelyIcon)
},
{
"index": 2,
"text": currentlywindSpeed,
"icon": currentlywindIcon
},
{
"index": 3,
"text": degToCompass(currentlywindRikt),
"icon": vindriktIcon
},
{
"index": 4,
"text": currentlyTrycket,
"icon": TrycketIcon
},
{
"index": 5,
"text": kommande,
"icon": TrycketIcon
}
]
}
}
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" : "xx"
}
};
var result = UrlFetchApp.fetch("xx", options);
Logger.log(result);
}
Stefan Rydberg
Ok.
Looks like i have to better lat long or something. Thanks.
I have to learn how to see the result i gs also....
Getting there...
Kind regards
Stefan
Viktor Z
You can use those Logger.log functions to see results. You can uncomment them, run your code and then click "View / Log" menu
Stefan Rydberg
Great!
Stefan Rydberg
It was the exclude that i have not seen....
Hourly works now, daily give wrong day.
Kind regards
Stefan
Kevin O
LaMetric Support
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.
Stefan Rydberg
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
Viktor Z
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.
-
How to pull data from external site to display?
-
nodejs request "gets acces denied"
-
curl to python for eventghost
-
Push text from Eventghost to LaMetric via python
-
Basic API pull and json parse example....
-
A guide for starting an app?
-
A small wrapper to push your just created JIRA issues to your LaMetric.
-
Simple project to push home consumption data to be shown on a Lametric device
-
Interface to have Slack send messages to a LaMetric Time
-
Very simple module to push frames to LaMetric
See all 149 topics