Skip to content

Instantly share code, notes, and snippets.

@somejavadev
Created February 20, 2018 12:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save somejavadev/0ff3ed73e30b77fe4bd275872747a4e7 to your computer and use it in GitHub Desktop.
Save somejavadev/0ff3ed73e30b77fe4bd275872747a4e7 to your computer and use it in GitHub Desktop.
Simple weather html to be used in a Grafana text panel. Weather gets refreshed on the global refresh of the dashboard.
<!--
A simple grafana weather panel combined by posts from this page: https://github.com/grafana/grafana/issues/1816
Just change the WOE_ID. Get one for your region here: http://www.woeidlookup.com/
-->
<script>
var WOE_ID = XXXX;
var callbackFunction = function (data) {
var wind = data.query.results.channel.wind;
$("#windspeed").text(wind.speed);
var astronomy = data.query.results.channel.astronomy;
$("#sunrise").text(astronomy.sunrise);
$("#sunset").text(astronomy.sunset);
var condition = data.query.results.channel.item.condition;
$("#temp").text(condition.temp);
$("#conditions").text(condition.text);
};
var getWeather = function () {
jQuery.get("https://query.yahooapis.com/v1/public/yql?q=select item, condition, wind, astronomy from weather.forecast where woeid =" + WOE_ID + " and u='c'&format=json", callbackFunction);
};
angular.element('#weatherPanel').injector().get('$rootScope').$on('refresh', function () {
getWeather();
});
getWeather();
</script>
<div id="weatherPanel">
Temperature: <span id="temp"/> &deg;C</br>
Sunrise: <span id="sunrise"/> </br>
Sunset: <span id="sunset"/> </br>
Wind Speed: <span id="windspeed"/> km/h </br>
Conditions: <span id="conditions"/> </br>
</div>
@MakeSenseIoT
Copy link

Doesn't work for me.the jQuery link not responding. How about angular?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment