Dashticz / dashticz_v2

Alternative dashboard for Domoticz
107 stars 62 forks source link

Wunderground - no more free APIs #341

Closed czacha338 closed 6 years ago

czacha338 commented 6 years ago

Hi,

New users, which can not get API key for Wunderground have to leave without weather forcast. I have found 2 solution, for them:

1. Solution:

Put into frame weather forecast from Forecast.io, example of url: http://forecast.io/embed/#lat=49.9816&lon=9.0865&name=Mainaschaff&color=#00aaff&font=Helvetica&fontcolor=#ffffff&units=si&text-color=#fff%22

2. Solution:

I have developed a java script which is using an api provided from https://openweathermap.org/ .

This openweathermap has only one disadvantage, if someone would like to get a daily weather forecast needs to pay. I prefer to use hourly forecast anyway, because it is more precise and easily to predict weather for next few hours. :) The whole javascript is compatible with your configuration, so it is easy to use it. I am not sure if user can use both weather forecasts, maybe then some changes in names of functions will be necessary. Unfortunately I cannot test it... Below how it look like: openweather

And right now changes in code (if you will like it you can marge to your branch): js/blocks.js

osmc@osmc:~/domoticz/www/dashticz_v2$ git diff js/blocks.js
diff --git a/js/blocks.js b/js/blocks.js
index b1f1786..43c2d2e 100644
--- a/js/blocks.js
+++ b/js/blocks.js
@@ -174,6 +174,15 @@ function handleStringBlock(block, columndiv, width, c) {
             $(columndiv).append('<div data-id="weather" class="block_' + block + ' containsweatherfull"</div');
             if (settings['wu_api'] !== "" && settings['wu_city'] !== "") loadWeatherFull(settings['wu_city'], settings['wu_country'], $('.weatherfull'));
             return;
+               //NEW WEATHER
+               case 'weather_owm':
+            if (typeof(loadWeatherFull) !== 'function') {
+                $.ajax({url: 'js/weather_owm.js', async: false, dataType: "script"});
+            }
+            $(columndiv).append('<div data-id="weather" class="block_' + block + ' containsweatherfull"</div');
+            if (settings['owm_api'] !== "" && settings['owm_city'] !== "") loadWeatherFull(settings['owm_city'], settings['owm_country'], $('.weatherfull'));
+            return;
+               //END OF NEW WEATHER
         case 'currentweather':
             if (settings['wu_api'] !== "" && settings['wu_city'] !== "") {
                 if (typeof(loadWeather) !== 'function') {
@@ -186,6 +195,21 @@ function handleStringBlock(block, columndiv, width, c) {
                 loadWeather(settings['wu_city'], settings['wu_country']);
             }
             return;
+               //NEW WEATHER
+        case 'currentweather_owm':
+            if (settings['owm_api'] !== "" && settings['owm_city'] !== "") {
+                if (typeof(loadWeather) !== 'function') {
+                    $.ajax({url: 'js/weather_owm.js', async: false, dataType: "script"});
+                }
+
+                $(columndiv).append('<div data-id="currentweather" class="mh transbg block_' + block + ' col-xs-' + width + ' containsweather"' +
+                    '<div class="col-xs-4"<div class="weather" id="weather"</div</div' +
+                    '<div class="col-xs-8"<strong class="title weatherdegrees" id="weatherdegrees"</strong<br /<span class="weatherloc" id="weatherloc"</span</div' +
+                    '</div');
+                loadWeather(settings['owm_city'], settings['owm_country']);
+            }
+            return;
+               //END OF NEW WEATHER
         case 'currentweather_big':
             if (settings['wu_api'] !== "" && settings['wu_city'] !== "") {
                 if (typeof(loadWeather) !== 'function') {
@@ -199,6 +223,21 @@ function handleStringBlock(block, columndiv, width, c) {
                 loadWeather(settings['wu_city'], settings['wu_country']);
             }
             return;
+               //NEW WEATHER
+               case 'currentweather_big_owm':
+            if (settings['owm_api'] !== "" && settings['owm_city'] !== "") {
+                if (typeof(loadWeather) !== 'function') {
+                    $.ajax({url: 'js/weather_owm.js', async: false, dataType: "script"});
+                }
+                $(columndiv).append('<div data-id="currentweather_big" class="mh transbg big block_' + block + ' col-xs-' + width + ' containsweather"' +
+                    '<div class="col-xs-1"<div class="weather" id="weather"</div</div' +
+                    '<div class="col-xs-11"<span class="title weatherdegrees" id="weatherdegrees"</span <span class="weatherloc" id="weatherloc"</span</div' +
+                    '</div');
+
+                loadWeather(settings['owm_city'], settings['owm_country']);
+            }
+            return;
+               //END OF NEW WEATHER
         case 'spotify':
             if (typeof(getSpotify) !== 'function') $.ajax({url: 'js/spotify.js', async: false, dataType: "script"});
             getSpotify(columndiv);

js/main.js

osmc@osmc:~/domoticz/www/dashticz_v2$ git diff js/main.js
diff --git a/js/main.js b/js/main.js
index d5f088b..0787106 100644
--- a/js/main.js
+++ b/js/main.js
@@ -346,6 +346,25 @@ function buildScreens() {
                                     loadWeather(settings['wu_city'], settings['wu_country']);
                                 }, (60000 * 30));
                             }
+
+                                                       //NEW WEATHER
+                                                       if (typeof(settings['owm_api']) !== 'undefined' && settings['owm_api'] !== "" && settings['owm_api'] !== 0 && typeof(settings['owm_city']) !== 'undefined' && settings['owm_city'] !== "") {
+                                $('.col2').prepend('<div class="mh transbg big block_currentweather_big col-xs-12 containsweather"<div class="col-xs-1"<div class="weather" id="weather"</div</div<div class="col-xs-11"<span class="title weatherdegrees" id="weatherdegrees"</span <span class="weatherloc" id="weatherloc"</span</div</div');
+                                if (typeof(loadWeatherFull) !== 'function') $.ajax({
+                                    url: 'js/weather_owm.js',
+                                    async: false,
+                                    dataType: 'script'
+                                });
+
+                                loadWeatherFull(settings['owm_city'], settings['owm_country'], $('#weatherfull'));
+                                loadWeather(settings['owm_city'], settings['owm_country']);
+
+                                setInterval(function () {
+                                    loadWeatherFull(settings['owm_city'], settings['owm_country'], $('#weatherfull'));
+                                    loadWeather(settings['owm_city'], settings['owm_country']);
+                                }, (60000 * 30));
+                            }
+                                                       //END OF NEW WEATHER

js/settings.js

osmc@osmc:~/domoticz/www/dashticz_v2$ git diff js/settings.js
diff --git a/js/settings.js b/js/settings.js
index 52eb8ee..c7005ca 100644
--- a/js/settings.js
+++ b/js/settings.js
@@ -458,6 +458,11 @@ if (typeof(settings['dashticz_refresh']) === 'undefined') settings['dashticz_ref
 if (typeof(settings['wu_api']) === 'undefined') settings['wu_api'] = '';
 if (typeof(settings['wu_country']) === 'undefined') settings['wu_country'] = 'NL';
 if (typeof(settings['wu_city']) === 'undefined') settings['wu_city'] = 'Amsterdam';
+//NEW WEATHER
+if (typeof(settings['owm_api']) === 'undefined') settings['wu_api'] = '';
+if (typeof(settings['owm_country']) === 'undefined') settings['wu_country'] = 'NL';
+if (typeof(settings['owm_city']) === 'undefined') settings['wu_city'] = 'Amsterdam';
+//END NEW WEATHER
 if (typeof(settings['boss_stationclock']) === 'undefined') settings['boss_stationclock'] = 'RedBoss';
 if (typeof(settings['use_fahrenheit']) === 'undefined') settings['use_fahrenheit'] = 0;
 if (typeof(settings['use_beaufort']) === 'undefined') settings['use_beaufort'] = 0;

js/weather_owm.js weather_owm.zip

And configuration in CONFIG.js: //weather new OWM

config['owm_api'] = 'xxx';
config['owm_city'] = 'Mainaschaff';
config['owm_name'] = '';
config['owm_country'] = 'de';
config['static_weathericons'] = 1;

columns[2] = {}
columns[2]['width'] = 6;
columns[2]['blocks'] = ['currentweather_big_owm','weather_owm'];

Best regards,

Adrian

DewGew commented 6 years ago

Put your pull request into beta instead of master.

czacha338 commented 6 years ago

Hi,

Sorry, I am new on github. :) I will try to make it right.

Best regards,

Adrian