|
From: <chr...@us...> - 2014-03-10 15:25:58
|
Revision: 2143
http://sourceforge.net/p/openautomation/code/2143
Author: chris_ace
Date: 2014-03-10 15:25:53 +0000 (Mon, 10 Mar 2014)
Log Message:
-----------
neues Wetter-Plugin (Weather.pl) basierend auf Wunderground
Added Paths:
-----------
wiregate/plugin/generic/Weather.pl
wiregate/plugin/generic/conf.d/Weather.conf
Added: wiregate/plugin/generic/Weather.pl
===================================================================
--- wiregate/plugin/generic/Weather.pl (rev 0)
+++ wiregate/plugin/generic/Weather.pl 2014-03-10 15:25:53 UTC (rev 2143)
@@ -0,0 +1,159 @@
+# Weather Plugin
+# Version 0.01
+# by ctr (http://knx-user-forum.de/members/ctr.html)
+# based on
+# - Plugin zum Abfragen von Google Weather (by jensgulow)
+# - Wundergroundweather (by Bodo)
+# Copyright: ctr
+# License: GPL (v2)
+
+my $provider;
+my $city;
+my $country;
+my $lang;
+my $api;
+
+my $weather_update_ga;
+my $weather_temp_ga;
+my $weather_hum_ga;
+my $weather_clouds_ga;
+my $weather_wind_ga;
+my $weather_wind_speed_ga;
+my $weather_wind_dir_ga;
+
+my $weather_current_temp;
+my $weather_current_humidity;
+my $weather_current_clouds;
+my $weather_current_wind;
+my $weather_current_windchill;
+my $weather_current_wind_speed;
+my $weather_current_wind_dir;
+my $weather_current_sunrise;
+my $weather_current_sunset;
+my @weather_forecast_maxtemp;
+my @weather_forecast_mintemp;
+my @weather_forecast_clouds;
+my @weather_forecast_day;
+my @weather_forecast_pop;
+
+my $show_debug = 0;
+
+use Switch;
+
+my $confFile = '/etc/wiregate/plugin/generic/conf.d/'.basename($plugname,'.pl').'.conf';
+if (! -f $confFile)
+{
+ plugin_log($plugname, " no conf file [$confFile] found.");
+ return("error");
+}
+else
+{
+ plugin_log($plugname, " reading conf file [$confFile].") if( $show_debug > 1);
+ open(CONF, $confFile);
+ my @lines = <CONF>;
+ close($confFile);
+ my $result = eval("@lines");
+ if( $show_debug > 1 )
+ {
+ ($result) and plugin_log($plugname, "conf file [$confFile] returned result[$result]");
+ }
+ if ($@)
+ {
+ plugin_log($plugname, "conf file [$confFile] returned:") if( $show_debug > 1 );
+ my @parts = split(/\n/, $@);
+ if( $show_debug > 1 )
+ {
+ plugin_log($plugname, "--> $_") foreach (@parts);
+ }
+ }
+}
+
+
+
+
+if (not defined($plugin_info{$plugname.'_cycle'})) {
+ $plugin_info{$plugname.'_cycle'} = 1800; # Eigenen Aufruf-Zyklus setzen (Initialisierung/zyklisches prüfen)
+ # nicht zu klein, da die Daten sowieso in längeren Perioden refresht werden
+ # und das Plugin auf die CF schreibt.
+}
+
+sub Wunderground {
+ my $wunderground_baseurl = "http://api.wunderground.com/api/";
+ use LWP::Simple;
+ use XML::Simple;
+ my $url = $wunderground_baseurl.$api."/conditions/forecast/astronomy/lang:".$lang."/q/".$country."\/".$city."\.xml";
+ my $xml = get($url);
+ return "Couldn't get it!" unless defined $xml;
+ my $weather = XMLin($xml,SuppressEmpty => '');
+ # current weather
+ $weather_current_temp = $weather->{current_observation}->{temp_c};
+ ($weather_current_humidity) = ($weather->{current_observation}->{relative_humidity} =~ m/(\d{1,3})\D/);
+# $weather_current_wind = $weather->{current_observation}->{wind_string};
+ SELECT:{
+ if ($weather->{current_observation}->{wind_kph} < 1.08) { $weather_current_wind = "0"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 5.76) { $weather_current_wind = "1"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 12.24) { $weather_current_wind = "2"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 19.8) { $weather_current_wind = "3"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 28.8) { $weather_current_wind = "4"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 38.88) { $weather_current_wind = "5"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 50.04) { $weather_current_wind = "6"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 61.92) { $weather_current_wind = "7"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 74.88) { $weather_current_wind = "8"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 88.2) { $weather_current_wind = "9"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 102.6) { $weather_current_wind = "10"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} < 117.72) { $weather_current_wind = "11"; last SELECT; }
+ if ($weather->{current_observation}->{wind_kph} >= 117.72) { $weather_current_wind = "12"; last SELECT; }
+ }
+ $weather_current_wind_speed = $weather->{current_observation}->{wind_kph};
+ $weather_current_wind_dir = $weather->{current_observation}->{wind_dir};
+ if ($weather->{current_observation}->{weather}) {
+ $weather_current_clouds = $weather->{current_observation}->{weather};
+ } else {
+ $weather_current_clouds = "Klar";
+ }
+ $weather_current_windchill = $weather->{current_observation}->{windchill_c};
+ $weather_current_sunset = $weather->{moon_phase}->{sunset}->{hour}.":".$weather->{moon_phase}->{sunset}->{minute};
+ $weather_current_sunrise = $weather->{moon_phase}->{sunrise}->{hour}.":".$weather->{moon_phase}->{sunrise}->{minute};
+ #forecast
+ for (my $i = 0; $i <= 3; $i++) {
+ $weather_forecast_maxtemp[$i] = $weather->{forecast}->{simpleforecast}->{forecastdays}->{forecastday}->[$i]->{high}->{celsius};
+ $weather_forecast_mintemp[$i] = $weather->{forecast}->{simpleforecast}->{forecastdays}->{forecastday}->[$i]->{low}->{celsius};
+ $weather_forecast_clouds[$i] = $weather->{forecast}->{simpleforecast}->{forecastdays}->{forecastday}->[$i]->{conditions};
+ $weather_forecast_day[$i] = $weather->{forecast}->{simpleforecast}->{forecastdays}->{forecastday}->[$i]->{date}->{weekday};
+ $weather_forecast_pop[$i] = $weather->{forecast}->{simpleforecast}->{forecastdays}->{forecastday}->[$i]->{pop};
+ }
+} # Ende "sub Wunderground"
+
+
+sub Results {
+ $plugin_info{$plugname.'_current_temp'} = $weather_current_temp." °C";
+ if ($weather_hum_ga) { knx_write($weather_hum_ga,$weather_current_humidity,9); }
+ $plugin_info{$plugname.'_current_humidity'} = $weather_current_humidity." %";
+ if ($weather_clouds_ga) { knx_write($weather_clouds_ga,$weather_current_clouds,16); }
+ $plugin_info{$plugname.'_current_clouds'} = $weather_current_clouds;
+ if ($weather_wind_ga) { knx_write($weather_wind_ga,$weather_current_wind,16); }
+ $plugin_info{$plugname.'_current_wind'} = $weather_current_wind;
+ if ($weather_wind_speed_ga) { knx_write($weather_wind_speed_ga,$weather_current_wind_speed,16); }
+ $plugin_info{$plugname.'_current_wind_speed'} = $weather_current_wind_speed;
+ if ($weather_wind_ga) { knx_write($weather_wind_dir_ga,$weather_current_wind_dir,16); }
+ $plugin_info{$plugname.'_current_wind_dir'} = $weather_current_wind_dir;
+ $plugin_info{$plugname.'_current_sunset'} = $weather_current_sunset;
+ $plugin_info{$plugname.'_current_sunrise'} = $weather_current_sunrise;
+ for (my $i = 0; $i <= 3; $i++) {
+ $plugin_info{$plugname.'_forecast_maxtemp'.$i} = $weather_forecast_maxtemp[$i]." °C";
+ $plugin_info{$plugname.'_forecast_mintemp'.$i} = $weather_forecast_mintemp[$i]." °C";
+ $plugin_info{$plugname.'_forecast_clouds'.$i} = $weather_forecast_clouds[$i];
+ $plugin_info{$plugname.'_forecast_day'.$i} = $weather_forecast_day[$i];
+ $plugin_info{$plugname.'_forecast_pop'.$i} = $weather_forecast_pop[$i]." %";
+ }
+ knx_write($weather_update_ga,1,1);
+} # Ende "sub Results"
+
+
+if (lc $provider eq "wunderground" ) {
+ Wunderground();
+ Results();
+ return("Done");
+} else {
+ return("no valid provider defined");
+}
Added: wiregate/plugin/generic/conf.d/Weather.conf
===================================================================
--- wiregate/plugin/generic/conf.d/Weather.conf (rev 0)
+++ wiregate/plugin/generic/conf.d/Weather.conf 2014-03-10 15:25:53 UTC (rev 2143)
@@ -0,0 +1,213 @@
+# Weather.pl Config
+
+$provider = "Wunderground"; # Anbieter, derzeit unterstützt: Wunderground
+$city = ""; # Meine Stadt, hier statt ü,ä,ö einfach u,a,o nehmen oder ue,ae,oe
+$country = ""; # Mein Land
+$lang = "DL"; # Meine Sprache (DL = deutsch)
+$api = ""; # API, muss man sich bei Wunderground besorgen
+
+$weather_update_ga = ""; # Gruppenadresse zum signalisieren eines Updates (fuer Visu!), Pflichtfeld!
+#$weather_temp_ga = ""; # Gruppenadresse Temperatur (DPT9.001, Grad Celsius)
+#$weather_hum_ga = ""; # Gruppenadresse Luftfeuchte (DPT9.007, Prozent relative Luffeuchtigkeit)
+#$weather_clouds_ga = ""; # Gruppenadresse Wolken (DPT16, Text)
+#$weather_wind_ga = ""; # Gruppenadresse Wind (tbd, Beaufort)
+#$weather_wind_speed_ga = ""; # Gruppenadresse Windgeschwindigkeit (tbd, km/h)
+#$weather_wind_dir_ga = ""; # Gruppenadresse Windrichtung (tbd, Grad)
+
+
+$plugin_info{$plugname.'_cycle'} = 1800; # alle 30 Minuten ausfuehren
+
+
+
+#### CometVisu Example Config:
+#
+# <group name="Weather">
+# <layout colspan="6"/>
+# <group nowidget="true" align="center">
+# <layout colspan="1.65"/>
+# <group nowidget="true" align="center">
+# <layout colspan="4.35"/>
+# <text align="center">
+# <label>Aktuell</label>
+# </text>
+# </group>
+# <group nowidget="true" align="center">
+# <layout colspan="1.65"/>
+# <text>
+# <layout colspan="0.45"/>
+# <label>
+# <icon name="temp_temperature"/>
+# </label>
+# </text>
+# <wgplugin_info variable="Weather.pl_current_temp">
+# <layout colspan="1.2"/>
+# <label>
+# <icon name="it_internet"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <break/>
+# <text>
+# <layout colspan="0.45"/>
+# <label>
+# <icon name="temp_temperature"/>
+# </label>
+# </text>
+# <info format="%.1f °C">
+# <layout colspan="1.2"/>
+# <label>
+# <icon name="weather_station"/>
+# </label>
+# <address transform="DPT:9.001" mode="read">$temp_ga_weatherstation</address>
+# </info>
+# <break/>
+# <text>
+# <layout colspan="0.45"/>
+# <label>
+# <icon name="weather_wind_speed"/>
+# </label>
+# </text>
+# <info format="%.1f">
+# <layout colspan="1.2"/>
+# <label>
+# <icon name="weather_station"/>
+# </label>
+# <address transform="DPT:9.001" mode="read">$windspeed_ga_weatherstation</address>
+# </info>
+# <text>
+# <layout colspan="0.45"/>
+# <label>
+# <icon name="weather_humidity_rel"/>
+# </label>
+# </text>
+# <wgplugin_info variable="Weather.pl_current_humidity">
+# <layout colspan="1.2"/>
+# <label>
+# <icon name="it_internet"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_current_clouds">
+# <layout colspan="1.65"/>
+# <label>
+# <icon name="weather_cloudy_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# </group>
+# </group>
+# <group nowidget="true" align="center">
+# <layout colspan="4.35"/>
+# <group nowidget="true" align="center">
+# <layout colspan="4.35"/>
+# <text align="center">
+# <label>Vorhersage</label>
+# </text>
+# </group>
+# <group nowidget="true" align="center">
+# <layout colspan="1.45"/>
+# <wgplugin_info variable="Weather.pl_forecast_day0">
+# <layout colspan="1.45"/>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_maxtemp0">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="temp_temperature_max"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_mintemp0">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="temp_temperature_min"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_pop0">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="weather_rain_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_clouds0">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="weather_cloudy_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# </group>
+# <group nowidget="true" align="center">
+# <layout colspan="1.45"/>
+# <wgplugin_info variable="Weather.pl_forecast_day1">
+# <layout colspan="1.45"/>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_maxtemp1">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="temp_temperature_max"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_mintemp1">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="temp_temperature_min"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_pop1">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="weather_rain_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_clouds1">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="weather_cloudy_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# </group>
+# <group nowidget="true" align="center">
+# <layout colspan="1.45"/>
+# <wgplugin_info variable="Weather.pl_forecast_day2">
+# <layout colspan="1.45"/>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_maxtemp2">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="temp_temperature_max"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_mintemp2">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="temp_temperature_min"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_pop2">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="weather_rain_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# <wgplugin_info variable="Weather.pl_forecast_clouds2">
+# <layout colspan="1.45"/>
+# <label>
+# <icon name="weather_cloudy_light"/>
+# </label>
+# <address transform="DPT:1.001" mode="read">$weather_update_ga</address>
+# </wgplugin_info>
+# </group>
+# </group>
+# </group>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|