|
From: <mc...@us...> - 2013-05-20 18:24:28
|
Revision: 1743
http://openautomation.svn.sourceforge.net/openautomation/?rev=1743&view=rev
Author: mclb
Date: 2013-05-20 18:24:18 +0000 (Mon, 20 May 2013)
Log Message:
-----------
Sonnenstandsabh?\195?\164ngige Beschattung mittels Raffstores oder Rolll?\195?\164den
Added Paths:
-----------
wiregate/plugin/generic/berechne_sonnenstand.pl
wiregate/plugin/generic/beschattung_doit.pl
wiregate/plugin/generic/beschattung_freigabe.pl
Added: wiregate/plugin/generic/berechne_sonnenstand.pl
===================================================================
--- wiregate/plugin/generic/berechne_sonnenstand.pl (rev 0)
+++ wiregate/plugin/generic/berechne_sonnenstand.pl 2013-05-20 18:24:18 UTC (rev 1743)
@@ -0,0 +1,107 @@
+#############################################################################
+# Plugin: Berechnung Azimuth und Elevation per Standort
+# V1.0 2013-05-06
+# Copyright: Marcus Lichtenberger (ma...@li...)
+# License: GPL (v3)
+#
+# Das Ergebnis dieses Plugins kann in mehreren anderen Plugins verwendet werden.
+#
+#############################################################################
+#
+# \xC4nderungshistorie:
+# 20130506 - mclb - Erstellung
+#
+#############################################################################
+#
+# Offene Punkte:
+# - Dzt. keine bekannt
+#
+#############################################################################
+#
+# Abh\xE4ngigkeiten:
+# - Paket libastro-satpass-perl
+# - Astro::Coord::ECI;
+# - Astro::Coord::ECI::Sun;
+# - Astro::Coord::ECI::TLE;
+# - Astro::Coord::ECI::Utils qw{rad2deg deg2rad};
+# - Installation:
+# - Wiregate Web-IF unter Updates Paket installieren libastro-satpass-perl oder
+# - in der Konsole apt-get -install libastro-satpass-perl
+#
+#############################################################################
+#
+# plugin_info-Werte
+# - azimuth: Azimuth-Wert
+# - elevation: Elevation-Wert
+#
+#############################################################################
+
+# Module laden
+use Astro::Coord::ECI;
+use Astro::Coord::ECI::Sun;
+use Astro::Coord::ECI::TLE;
+use Astro::Coord::ECI::Utils qw{rad2deg deg2rad};
+
+my $gv_lat;
+my $gv_lon;
+my $gv_elev;
+my $show_debug;
+
+my $gv_azimuth;
+my $gv_elevation;
+
+# Read config file in conf.d
+my $confFile = '/etc/wiregate/plugin/generic/conf.d/'.basename($plugname,'.pl').'.conf';
+if (! -f $confFile)
+{
+ plugin_log($plugname, " no conf file [$confFile] found.");
+ return "no conf file [$confFile] found.";
+}
+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);
+ }
+ }
+}
+
+# Ruf mich alle 5 Minuten selbst auf und berechne Azimuth und Elevation neu
+$plugin_info{$plugname.'_cycle'} = 60;
+
+($gv_azimuth, $gv_elevation) = berechneSonnenstand($gv_lat, $gv_lon, $gv_elev);
+
+$plugin_info{'azimuth'} = $gv_azimuth;
+$plugin_info{'elevation'} = $gv_elevation;
+
+return 'Sonnenstand erfolgreich berechnet!';
+
+####################################################
+# Aufruf mit berechneSonnenstand($lat, $lon, $elev);
+####################################################
+sub berechneSonnenstand {
+ # Aktuelle Zeit
+ my $lv_time = time ();
+ # Die eigenen Koordinaten
+ my $lv_loc = Astro::Coord::ECI->geodetic(deg2rad(shift), deg2rad(shift), shift);
+ # Sonne instanzieren
+ my $lv_sun = Astro::Coord::ECI::Sun->universal($lv_time);
+ # Feststellen wo die Sonne gerade ist
+ my ($lv_azimuth, $lv_elevation, $lv_range) = $lv_loc->azel($lv_sun);
+ $lv_azimuth = rad2deg($lv_azimuth);
+ $lv_elevation = rad2deg($lv_elevation);
+ return ($lv_azimuth, $lv_elevation);
+}
\ No newline at end of file
Added: wiregate/plugin/generic/beschattung_doit.pl
===================================================================
--- wiregate/plugin/generic/beschattung_doit.pl (rev 0)
+++ wiregate/plugin/generic/beschattung_doit.pl 2013-05-20 18:24:18 UTC (rev 1743)
@@ -0,0 +1,439 @@
+#############################################################################
+# Plugin: Beschattung mit Raffstores/Roll\xE4den
+# V1.0 2013-05-06
+# Copyright: Marcus Lichtenberger (ma...@li...)
+# License: GPL (v3)
+#
+#############################################################################
+#
+# Plugin zur Beschattung eines Hauses mittels Raffstores oder Roll\xE4den
+# - Helligkeitsabh\xE4ngige Beschattung
+# - Beschattung je Sonnenstand
+# - Hochfahren der Beschattung, wenn Fenster ge\xF6ffnet wird
+# - Sperre der gesamten Beschattung bzw. jedes einzelnen Fensters mittels Bustelegramm
+# - Lamellennachf\xFChrung bei Raffstores
+# - Sommer- und Winter-Modus
+#
+#############################################################################
+#
+# \xC4nderungshistorie:
+# 20120804 - joda123 - rollo_beschattungsposition eingef\xFChrt: Rollos k\xF6nnen bei
+# Beschattung jetzt n% geschlossen werden (vorher immer 100%)
+# 20120805 - joda123 - Lokale Definitionen in conf Datei ausgelagert: Es sind keine
+# site-spezifischen Definitionen in diesem Script mehr erforderlich.
+# Alle lokalen Anpassungen in /etc/wiregate/plugin/generic/conf.d/beschattung_v2.conf
+# 20120808 - mclb - Lamellenbehandlung nur noch, wenn $gs_raffstore->{lamellenNachfuehrung} nicht NACHF_AUS ist
+# 20120808 - mclb - Neuen Header eingef\xFCgt (nun mit Hinweis auf GPL, damit auch Andere hier weiterentwickeln k\xF6nnen
+# 20120808 - mclb - Umbenennung von beschattung_v2 auf beschattung
+# 20120821 - mclb - Definition einer Konstante hat gefehlt
+# NACHF_100 gefixt
+# 20120920 - mclb - Winter-Modus (Aktivierbar \xFCber eigene GA; Im Winter-Modus k\xF6nnen die Lamellen an eine andere Stelle zur Beschattung gefahren werden)
+# 20120925 - mclb - Beschattung temperaturabh\xE4ngig aktivieren/deaktivieren
+# 20130506 - mclb - Aufteilen in 2 Plugins - 1. Freigabe, 2. Ausf\xFChrung
+#
+#############################################################################
+#
+# Offene Punkte:
+# - Beschattung abh\xE4ngig von der Raumtemperatur
+#
+#############################################################################
+#
+# Abh\xE4ngigkeiten:
+# - Plugin beschattung_freigabe
+#
+#############################################################################
+#
+# plugin_info-Werte
+#
+#############################################################################
+
+# Konstanten f\xFCr Aufrufart
+use constant EVENT_RESTART => 'restart';
+use constant EVENT_MODIFIED => 'modified';
+use constant EVENT_BUS => 'bus';
+use constant EVENT_SOCKET => 'socket';
+use constant EVENT_CYCLE => 'cycle';
+# Konstanten f\xFCr die Freigabe
+use constant FREIGABE_AUS => 0;
+use constant FREIGABE_EIN => 1;
+# Konstanten f\xFCr Nachf\xFChrung ein/aus
+use constant NACHF_AUS => 'AUS';
+use constant NACHF_EIN => 'EIN';
+use constant NACHF_100 => '100';
+# Konstanten f\xFCr Raffstore-Attribute
+use constant AKTIV => 'A';
+use constant INAKTIV => 'I';
+use constant SPERRE_AKTIV => 1;
+use constant SPERRE_INAKTIV => 0;
+use constant AUTOMATIK_EIN => 'EIN';
+use constant AUTOMATIK_AUS => 'AUS';
+# Konstanten f\xFCr die Trennung der dynamischen Raffstore-Definitionen
+use constant SEPARATOR1 => ';';
+use constant SEPARATOR2 => '->';
+# Konstanten f\xFCr Temperaturfreigabe
+use constant TEMPFREIGABE_EIN => 'EIN';
+use constant TEMPFREIGABE_AUS => 'AUS';
+
+# Variablendefinitionen
+my $gv_helligkeit;
+my $gv_zeitpunkt;
+my $gv_zeitdifferenz;
+my $gs_raffstore;
+my $gv_raffstore_dyn;
+my @gt_raffstores_dyn;
+my $gv_id;
+my $gv_aktiv;
+my $gv_sperre;
+my $gv_automatik;
+my $gv_startWinkel;
+my $gv_endWinkel;
+my $gv_rolloPos;
+my $gv_rolloBeschattungspos;
+my $gv_lamellePos;
+my $gv_lamellePosNeu;
+my $gv_index;
+my $gv_tempFreigabe;
+my $gv_temperatur;
+my $gv_temperaturFreigabe;
+# Zeitpunkt auslesen
+my $gv_sekunden;
+my $gv_minuten;
+my $gv_stunden;
+my $gv_monatstag;
+my $gv_monat;
+my $gv_jahr;
+my $gv_wochentag;
+my $gv_jahrestag;
+my $gv_sommerzeit;
+
+# Definition und Initialisierung der konfigurierbaren Werte
+my $show_debug = 0; # switches debug information that will be shown in the log
+my $gv_gaWinter = "";
+my $gv_gaFreigabe = "";
+my @gt_raffstores;
+
+# Read config file in conf.d
+my $confFile = '/etc/wiregate/plugin/generic/conf.d/'.basename($plugname,'.pl').'.conf';
+if (! -f $confFile)
+{
+ plugin_log($plugname, " no conf file [$confFile] found.");
+ return "no conf file [$confFile] found.";
+}
+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);
+ }
+ }
+}
+
+# Ruf mich alle 60 Sekunden selbst auf, damit ich pr\xFCfen kann, ob die Helligkeit \xFCber-/unterschritten wurde
+$plugin_info{$plugname.'_cycle'} = 60;
+# Ruf mich auf, wenn zwischen Sommer- und Winter-Modus gewechselt wird
+if ($gv_gaWinter ne '') {
+ $plugin_subscribe{$gv_gaWinter}{$plugname} = 1;
+}
+# Ruf mich auf, wenn sich die Freigabe \xE4ndert
+if ($gv_gaFreigabe ne '') {
+ $plugin_subscribe{$gv_gaFreigabe}{$plugname} = 1;
+}
+# Ruf mich auf, wenn sich an der Sperr-GA eines Raffstores etwas \xE4ndert
+# Ruf mich auf, wenn sich der Fenster-Status \xE4ndert
+foreach $gs_raffstore (@gt_raffstores) {
+ # Aufruf bei Sperr-GA
+ if ($gs_raffstore->{gaSperre} ne "") {
+ $plugin_subscribe{$gs_raffstore->{gaSperre}}{$plugname} = 1;
+ }
+ # Aufruf, wenn sich der Fenster-Status \xE4ndert (offen/geschlossen)
+ if ($gs_raffstore->{gaFensterStatus} ne "") {
+ $plugin_subscribe{$gs_raffstore->{gaFensterStatus}}{$plugname} = 1;
+ }
+ # Aufruf, wenn eine ben\xF6tigte Temperatur gesendet wird
+ if ($gs_raffstore->{gaTemperatur} ne "") {
+ $plugin_subscribe{$gs_raffstore->{gaTemperatur}}{$plugname} = 1;
+ }
+}
+
+# Dynamische Teile der Raffstore-Definition einlesen
+@gt_raffstores_dyn = split(SEPARATOR1, $plugin_info{$plugname.'_gt_raffstores_dyn'});
+foreach $gv_raffstore_dyn (@gt_raffstores_dyn) {
+ ($gv_id, $gv_aktiv, $gv_sperre, $gv_automatik, $gv_temperatur, $gv_temperaturFreigabe) = split(SEPARATOR2, $gv_raffstore_dyn);
+
+ # Wegen Update auf gt_raffstores hier eine for-Schleife
+ for ($gv_index=0; $gv_index<@gt_raffstores; $gv_index++) {
+ $gs_raffstore = $gt_raffstores[$gv_index];
+ if ($gs_raffstore->{id} eq $gv_id) {
+ if ($gv_aktiv ne '') {
+ $gs_raffstore->{aktiv} = $gv_aktiv;
+ }
+ if ($gv_sperre ne '') {
+ $gs_raffstore->{sperre} = $gv_sperre;
+ }
+ if ($gv_automatik ne '') {
+ $gs_raffstore->{automatik} = $gv_automatik;
+ }
+ if ($gv_temperatur ne '') {
+ $gs_raffstore->{valueTemperatur} = $gv_temperatur;
+ }
+ if ($gv_temperaturFreigabe ne '') {
+ $gs_raffstore->{temperaturFreigabe} = $gv_temperaturFreigabe;
+ }
+ $gt_raffstores[$gv_index] = $gs_raffstore;
+ last();
+ }
+ }
+}
+
+# Module laden
+use Astro::Coord::ECI;
+use Astro::Coord::ECI::Sun;
+use Astro::Coord::ECI::TLE;
+use Astro::Coord::ECI::Utils qw{rad2deg deg2rad};
+
+# Aus welchem Grund l\xE4uft das Plugin gerade
+my $gv_event=undef;
+if (!$plugin_initflag) {
+ $gv_event = EVENT_RESTART; # Restart des daemons / Reboot
+} elsif ($plugin_info{$plugname.'_lastsaved'} > $plugin_info{$plugname.'_last'}) {
+ $gv_event = EVENT_MODIFIED; # Plugin modifiziert
+} elsif (%msg) {
+ $gv_event = EVENT_BUS; # Bustraffic
+} elsif ($fh) {
+ $gv_event = EVENT_SOCKET; # Netzwerktraffic
+} else {
+ $gv_event = EVENT_CYCLE; # Zyklus
+}
+
+if ($gv_event eq EVENT_RESTART) {
+ #Default: Sommermodus
+ if (!exists $plugin_info{$plugname.'_winterModus'}) {
+ $plugin_info{$plugname.'_winterModus'} = 0;
+ }
+ if (!exists $gs_raffstore->{temperaturFreigabe}) {
+ $gs_raffstore->{temperaturFreigabe} = TEMPFREIGABE_AUS;
+ }
+} elsif ($gv_event eq EVENT_MODIFIED) {
+ # Default nicht beschatten, falls der Wert noch nicht existiert
+ if (!exists $plugin_info{$plugname.'_freigabe'}) {
+ $plugin_info{$plugname.'_freigabe'} = FREIGABE_AUS;
+ }
+ if (!exists $gs_raffstore->{temperaturFreigabe}) {
+ $gs_raffstore->{temperaturFreigabe} = TEMPFREIGABE_AUS;
+ }
+} elsif ($gv_event eq EVENT_BUS) {
+ if ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gv_gaFreigabe) {
+ plugin_log($plugname, '20 - Freigabe = '.$msg{'value'});
+ $plugin_info{$plugname.'_freigabe'} = $msg{'value'};
+ } elsif ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gv_gaWinter) {
+ # Umschalten zwischen Sommer- und Wintermodus
+ $plugin_info{$plugname.'_winterModus'} = $msg{'value'};
+ } elsif ($msg{'apci'} eq "A_GroupValue_Read" and $msg{'dst'} eq $gv_gaWinter) {
+ # R\xFCckmeldung, ob gerade Sommer- oder Wintermodus aktiv ist
+ knx_write($gv_gaWinter,$plugin_info{$plugname.'_winterModus'});
+ } else {
+ for ($gv_index=0; $gv_index < @gt_raffstores; $gv_index++) {
+ # Muss mittels for-Schleife (und nicht foreach) gemacht werden, weil ich die Werte in der Schleife updaten muss.
+ $gs_raffstore = $gt_raffstores[$gv_index];
+
+ if ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gs_raffstore->{gaSperre}) {
+ # Sperre wurde gesetzt oder aufgehoben
+ $gs_raffstore->{sperre} = $msg{'value'};
+ }
+ if ($msg{'apci'} eq "A_GroupValue_Read" and $msg{'dst'} eq $gs_raffstore->{gaSperre}) {
+ # Sperre wurde abgefragt
+ knx_write($gs_raffstore->{gaSperre}, $gs_raffstore->{sperre});
+ }
+ if ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gs_raffstore->{gaFensterStatus}) {
+ if ($msg{'value'} == 0) {
+ # Wird ein Fenster ge\xF6ffnet, dann Raffstore nach oben und Automatik aus
+ $gs_raffstore->{automatik} = AUTOMATIK_AUS;
+ $gv_rolloPos = knx_read($gs_raffstore->{gaRolloPosRM}, 5.001);
+ if ($gv_rolloPos != 0) {
+ knx_write($gs_raffstore->{gaRolloPos}, 0, 5.001);
+ }
+ if ($gs_raffstore->{lamellenNachfuehrung} ne NACHF_AUS) {
+ $gv_lamellePos = knx_read($gs_raffstore->{gaLamellePosRM}, 5.001);
+ if ($gv_lamellePos != 0) {
+ knx_write($gs_raffstore->{gaLamellePos}, 0, 5.001);
+ }
+ }
+ } elsif ($msg{'value'} == 1) {
+ # Wird ein Fenster geschlossen, dann Automatik aus
+ $gs_raffstore->{automatik} = AUTOMATIK_EIN;
+ }
+ }
+ if ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gs_raffstore->{gaTemperatur}) {
+ $gs_raffstore->{valueTemperatur} = $msg{'value'};
+ }
+ $gt_raffstores[$gv_index] = $gs_raffstore;
+ }
+ }
+} elsif ($gv_event eq EVENT_SOCKET) {
+} elsif ($gv_event eq EVENT_CYCLE) {
+ # Beschattungs-Automatik
+ plugin_log($plugname,'10 - Cycle-Aufruf, Sperre = '.$plugin_info{$plugname.'_sperre'}.', Freigabe = '.$plugin_info{$plugname.'_freigabe'}) if ($show_debug > 0);
+ if ($plugin_info{$plugname.'_sperre'} == SPERRE_INAKTIV) {
+ plugin_log($plugname,'11 - Beschattung') if ($show_debug > 0);
+ plugin_log($plugname,'11a - Freigabe = '.$plugin_info{$plugname.'_freigabe'}) if ($show_debug > 0);
+
+ # Automatik l\xE4uft grunds\xE4tzlich
+ foreach $gs_raffstore (@gt_raffstores) {
+ plugin_log($plugname,'12 - Aktiv = '.$gs_raffstore->{aktiv}.', Sperre = '.$gs_raffstore->{sperre}.', Automatik = '.$gs_raffstore->{automatik}) if ($show_debug > 0);
+
+ if ($gs_raffstore->{aktiv} eq AKTIV and
+ $gs_raffstore->{sperre} == SPERRE_INAKTIV and
+ $gs_raffstore->{automatik} eq AUTOMATIK_EIN) {
+
+ plugin_log($plugname,'13 - Beschattung aktiv; Freigabe = '.$plugin_info{$plugname.'_freigabe'}) if ($show_debug > 0);
+
+ # Automatik ist aktiv -> also mach nun deine Arbeit
+ if ($plugin_info{$plugname.'_freigabe'} eq FREIGABE_AUS) {
+ # Freigabe ist aufgrund der Helligkeit nicht notwendig -> Raffstore nach oben!
+
+ plugin_log($plugname,'14 - Freigabe AUS -> Raffstores nach oben') if ($show_debug > 0);
+
+ # Raffstores hoch
+ $gv_rolloPos = knx_read($gs_raffstore->{gaRolloPosRM}, 5.001);
+ if ($gv_rolloPos != 0) {
+ knx_write($gs_raffstore->{gaRolloPos}, 0, 5.001);
+ }
+ if ($gs_raffstore->{lamellenNachfuehrung} ne NACHF_AUS) {
+ $gv_lamellePos = knx_read($gs_raffstore->{gaLamellePosRM}, 5.001);
+ if ($gv_lamellePos != 0) {
+ knx_write($gs_raffstore->{gaLamellePos}, 0, 5.001);
+ }
+ }
+ } else {
+ plugin_log($plugname,'15 - Freigabe EIN -> Ausrichtungsabh\xE4ngig beschatten; Ausrichtung = '.$gs_raffstore->{ausrichtung}) if ($show_debug > 0);
+
+ if (exists($gs_raffstore->{ausrichtung})) {
+ #Startwinkel berechnen
+ $gv_startWinkel = $gs_raffstore->{ausrichtung} - 85;
+ if ($gv_startWinkel < 0) {
+ $gv_startWinkel = $gv_startWinkel + 360;
+ }
+ # Endwinkel berechnen
+ $gv_endWinkel = $gs_raffstore->{ausrichtung} + 85;
+ if ($gv_endWinkel > 360) {
+ $gv_endWinkel = $gv_endWinkel - 360;
+ }
+ }
+ if (exists($gs_raffstore->{startWinkel})) {
+ $gv_startWinkel = $gs_raffstore->{startWinkel};
+ }
+ if (exists($gs_raffstore->{endWinkel})) {
+ $gv_endWinkel = $gs_raffstore->{endWinkel};
+ }
+
+ # Muss aufgrund der Raumtemperatur beschattet werden?
+ if (exists $gs_raffstore->{minTemperatur} and
+ exists $gs_raffstore->{maxTemperatur} and
+ exists $gs_raffstore->{valueTemperatur} ) {
+
+ plugin_log($plugname,'15a - minTemperatur = '.$gs_raffstore->{minTemperatur}.', maxTemperatur = '.$gs_raffstore->{maxTemperatur}.', valueTemperatur = '.$gs_raffstore->{valueTemperatur}) if ($show_debug > 0);
+
+ if ($gs_raffstore->{valueTemperatur} < $gs_raffstore->{minTemperatur}) {
+ $gs_raffstore->{temperaturFreigabe} = TEMPFREIGABE_AUS;
+ }
+ if ($gs_raffstore->{valueTemperatur} > $gs_raffstore->{maxTemperatur}) {
+ $gs_raffstore->{temperaturFreigabe} = TEMPFREIGABE_EIN;
+ }
+ } else {
+ # Wenn keine explizite Temperaturfreigabelogik vorhanden, dann default freigegeben verwenden
+ $gs_raffstore->{temperaturFreigabe} = TEMPFREIGABE_EIN;
+ }
+
+ plugin_log($plugname,'16 - StartWinkel = '.$gv_startWinkel.', EndWinkel = '.$gv_endWinkel.', Azimuth = '.$plugin_info{'azimuth'}) if ($show_debug > 0);
+ plugin_log($plugname,'16a - TemperaturFreigabe = '.$gs_raffstore->{temperaturFreigabe}) if ($show_debug > 0);
+
+ # Aktuelle Sonnenposition verwenden um zu bestimmen, ob der Raffstore gerade beschattet werden muss
+ if ($plugin_info{'azimuth'} >= $gv_startWinkel and
+ $plugin_info{'azimuth'} <= $gv_endWinkel and
+ $gs_raffstore->{temperaturFreigabe} eq TEMPFREIGABE_EIN) {
+
+ # Beschattung aufgrund der Ausrichtung und Raumtemperatur
+
+ # Raffstore runter
+ $gv_rolloPos = knx_read($gs_raffstore->{gaRolloPosRM}, 5.001);
+ if ($plugin_info{$plugname.'_winterModus'} == 1) {
+ $gv_rolloBeschattungspos = $gs_raffstore->{rolloBeschattungsposWinter};
+ } else {
+ $gv_rolloBeschattungspos = $gs_raffstore->{rolloBeschattungspos};
+ }
+ if ($gv_rolloPos != $gv_rolloBeschattungspos) {
+ knx_write($gs_raffstore->{gaRolloPos}, $gv_rolloBeschattungspos, 5.001);
+ }
+ if ($gs_raffstore->{lamellenNachfuehrung} ne NACHF_AUS) {
+ $gv_lamellePos = knx_read($gs_raffstore->{gaLamellePosRM}, 5.001);
+ }
+
+ # Lamellennachf\xFChrung
+
+ if ($gv_minuten % 5 == 0) {
+ if ($gs_raffstore->{lamellenNachfuehrung} ne NACHF_AUS) {
+ if ($gs_raffstore->{lamellenNachfuehrung} eq NACHF_100) {
+ # Somit wird auf jeden Fall ganz zu gemacht.
+ $gv_lamellePos = 0;
+ $gv_lamellePosNeu = 100;
+ } else {
+ $gv_lamellePosNeu = (90 - $plugin_info{$plugname.'_elevation'})/90*100;
+ # Faktor f\xFCr die Abweichung der Sonne von der Ausrichtung des Fensters miteinbeziehen
+ $gv_lamellePosNeu = $gv_lamellePosNeu * (1 - (abs($plugin_info{'azimuth'} - $gs_raffstore->{ausrichtung}) * 0.01));
+ # Der Wert f\xFCr den Lamellenwinkel muss immer zwischen 0 und 100 sein! Alles dar\xFCber hinaus wird fix auf 0 bzw. 100 gesetzt.
+ if ($gv_lamellePosNeu < 0) { $gv_lamellePosNeu = 0; }
+ if ($gv_lamellePosNeu > 100) { $gv_lamellePosNeu = 100; }
+ }
+ # Nicht wegen jeder Kleinigkeit gleich nachstellen, erst nach einer gewissen Mindest\xE4nderung.
+ if (abs($gv_lamellePos - $gv_lamellePosNeu) > 5) {
+ knx_write($gs_raffstore->{gaLamellePos},$gv_lamellePosNeu,5.001);
+ }
+ }
+ }
+ } else {
+ # Keine Beschattung aufgrund der Ausrichtung
+
+ # Raffstore hoch
+ $gv_rolloPos = knx_read($gs_raffstore->{gaRolloPosRM}, 5.001);
+ if ($gv_rolloPos != 0) {
+ knx_write($gs_raffstore->{gaRolloPos}, 0, 5.001);
+ }
+ if ($gs_raffstore->{lamellenNachfuehrung} ne NACHF_AUS) {
+ $gv_lamellePos = knx_read($gs_raffstore->{gaLamellePosRM}, 5.001);
+ if ($gv_lamellePos != 0) {
+ knx_write($gs_raffstore->{gaLamellePos}, 0, 5.001);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+# Dynamische Werte der Raffstore-Definition im plugin_info merken
+@gt_raffstores_dyn = ();
+foreach $gs_raffstore (@gt_raffstores) {
+ unshift(@gt_raffstores_dyn, join(SEPARATOR2, $gs_raffstore->{id}, $gs_raffstore->{aktiv}, $gs_raffstore->{sperre}, $gs_raffstore->{automatik}, $gs_raffstore->{valueTemperatur}, $gs_raffstore->{temperaturFreigabe}));
+}
+$gv_raffstore_dyn = join(SEPARATOR1, @gt_raffstores_dyn);
+$plugin_info{$plugname.'_gt_raffstores_dyn'} = $gv_raffstore_dyn;
+
+if ($show_debug > 0) {
+ return $gv_raffstore_dyn;
+} else {
+ return 'Beschattungslogik erledigt!';
+}
\ No newline at end of file
Added: wiregate/plugin/generic/beschattung_freigabe.pl
===================================================================
--- wiregate/plugin/generic/beschattung_freigabe.pl (rev 0)
+++ wiregate/plugin/generic/beschattung_freigabe.pl 2013-05-20 18:24:18 UTC (rev 1743)
@@ -0,0 +1,238 @@
+#############################################################################
+# Plugin: Beschattung freigeben / einschalten
+# V1.0 2013-05-06
+# Copyright: Marcus Lichtenberger (ma...@li...)
+# License: GPL (v3)
+#
+#############################################################################
+#
+# \xC4nderungshistorie:
+# 20130506 - mclb - Erstellung
+#
+#############################################################################
+#
+# Offene Punkte:
+# - Dzt. keine bekannt
+#
+#############################################################################
+#
+# Abh\xE4ngigkeiten:
+# - Plugin berechne_sonnenstand
+#
+#############################################################################
+#
+# plugin_info-Werte
+# -
+#
+#############################################################################
+
+# Konstanten f\xFCr Aufrufart
+use constant EVENT_RESTART => 'restart';
+use constant EVENT_MODIFIED => 'modified';
+use constant EVENT_BUS => 'bus';
+use constant EVENT_SOCKET => 'socket';
+use constant EVENT_CYCLE => 'cycle';
+# Konstanten f\xFCr Beschattung ein/aus
+use constant BESCHATTUNG_AUS => 'AUS';
+use constant BESCHATTUNG_EIN => 'EIN';
+# Konstanten f\xFCr Beschattung Freigabe ein/aus
+use constant FREIGABE_AUS => 'AUS';
+use constant FREIGABE_EIN => 'EIN';
+
+# Variablendefinitionen
+my $gv_helligkeit;
+my $gv_azimuth;
+my $gv_elevation;
+my $gv_beschattungEin;
+my $gv_zeitpunkt;
+my $gv_zeitdifferenz;
+# Zeitpunkt auslesen
+my $gv_sekunden;
+my $gv_minuten;
+my $gv_stunden;
+my $gv_monatstag;
+my $gv_monat;
+my $gv_jahr;
+my $gv_wochentag;
+my $gv_jahrestag;
+my $gv_sommerzeit;
+
+# Definition und Initialisierung der konfigurierbaren Werte
+my $show_debug = 0; # switches debug information that will be shown in the log
+my $gv_gaHelligkeit = "";
+my $gv_gaSperre = "";
+my $gv_gaFreigabe = "";
+
+# Read config file in conf.d
+my $confFile = '/etc/wiregate/plugin/generic/conf.d/'.basename($plugname,'.pl').'.conf';
+if (! -f $confFile)
+{
+ plugin_log($plugname, " no conf file [$confFile] found.");
+ return "no conf file [$confFile] found.";
+}
+else
+{
+ plugin_log($plugname, " reading conf file [$confFile].") if( $show_debug > 0);
+ open(CONF, $confFile);
+ my @lines = <CONF>;
+ close($confFile);
+ my $result = eval("@lines");
+ if( $show_debug > 0 )
+ {
+ ($result) and plugin_log($plugname, "conf file [$confFile] returned result[$result]");
+ }
+ if ($@)
+ {
+ plugin_log($plugname, "conf file [$confFile] returned:") if( $show_debug > 0 );
+ my @parts = split(/\n/, $@);
+ if( $show_debug > 0 )
+ {
+ plugin_log($plugname, "--> $_") foreach (@parts);
+ }
+ }
+}
+
+# Ruf mich alle 60 Sekunden selbst auf, damit ich pr\xFCfen kann, ob die Helligkeit \xFCber-/unterschritten wurde
+$plugin_info{$plugname.'_cycle'} = 60;
+# Ruf mich auf, wenn sich die Helligkeit \xE4ndert, damit ich meine Helligkeits-Variable setzen kann
+if ($gv_gaHelligkeit ne '') {
+ $plugin_subscribe{$gv_gaHelligkeit}{$plugname} = 1;
+}
+# Ruf mich auf, wenn die Automatik gesperre oder freigegeben wird
+if ($gv_gaSperre ne '') {
+ $plugin_subscribe{$gv_gaSperre}{$plugname} = 1;
+}
+
+# Aus welchem Grund l\xE4uft das Plugin gerade
+my $gv_event=undef;
+if (!$plugin_initflag) {
+ $gv_event = EVENT_RESTART; # Restart des daemons / Reboot
+} elsif ($plugin_info{$plugname.'_lastsaved'} > $plugin_info{$plugname.'_last'}) {
+ $gv_event = EVENT_MODIFIED; # Plugin modifiziert
+} elsif (%msg) {
+ $gv_event = EVENT_BUS; # Bustraffic
+} elsif ($fh) {
+ $gv_event = EVENT_SOCKET; # Netzwerktraffic
+} else {
+ $gv_event = EVENT_CYCLE; # Zyklus
+}
+
+plugin_log($plugname, "0 - Event: ".$gv_event) if ($show_debug > 0);
+
+if ($gv_event eq EVENT_RESTART) {
+ # Default nicht beschatten, falls der Wert noch nicht existiert
+ if (!exists $plugin_info{$plugname.'_beschattungFreigabe'}) {
+ $plugin_info{$plugname.'_beschattungFreigabe'} = FREIGABE_AUS;
+ }
+ # Evtl. Sperre setzen, falls noch nicht existent
+ if (!exists $plugin_info{$plugname.'_sperre'}) {
+ $plugin_info{$plugname.'_sperre'} = SPERRE_INAKTIV;
+ }
+ # Evtl. Werte initialisieren, falls es sie noch nicht gibt.
+ if (!exists $plugin_info{$plugname.'_beschattungEin'}) {
+ $plugin_info{$plugname.'_beschattungEin'} = BESCHATTUNG_AUS;
+ }
+ if (!exists $plugin_info{$plugname.'_beschattungEinTime'}) {
+ ($gv_sekunden, $gv_minuten, $gv_stunden, $gv_monatstag, $gv_monat, $gv_jahr, $gv_wochentag, $gv_jahrestag, $gv_sommerzeit) = localtime(time);
+ $gv_zeitpunkt = $gv_minuten + ($gv_stunden*60);
+ $plugin_info{$plugname.'_beschattungEinTime'} = $gv_zeitpunkt;
+ }
+} elsif ($gv_event eq EVENT_MODIFIED) {
+ # Default nicht beschatten, falls der Wert noch nicht existiert
+ if (!exists $plugin_info{$plugname.'_beschattungFreigabe'}) {
+ $plugin_info{$plugname.'_beschattungFreigabe'} = FREIGABE_AUS;
+ }
+ # Evtl. Sperre setzen, falls noch nicht existent
+ if (!exists $plugin_info{$plugname.'_sperre'}) {
+ }
+ $plugin_info{$plugname.'_sperre'} = SPERRE_INAKTIV;
+ # Evtl. Werte initialisieren, falls es sie noch nicht gibt.
+ if (!exists $plugin_info{$plugname.'_beschattungEin'}) {
+ $plugin_info{$plugname.'_beschattungEin'} = BESCHATTUNG_AUS;
+ }
+ if (!exists $plugin_info{$plugname.'_beschattungEinTime'}) {
+ ($gv_sekunden, $gv_minuten, $gv_stunden, $gv_monatstag, $gv_monat, $gv_jahr, $gv_wochentag, $gv_jahrestag, $gv_sommerzeit) = localtime(time);
+ $gv_zeitpunkt = $gv_minuten + ($gv_stunden*60);
+ $plugin_info{$plugname.'_beschattungEinTime'} = $gv_zeitpunkt;
+ }
+} elsif ($gv_event eq EVENT_BUS) {
+ if ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gv_gaHelligkeit) {
+ # Aufruf durch Helligkeits-Telegramm
+ $gv_helligkeit = $msg{'value'};
+
+ # Azimuth und Elevation einlesen, damit ich bestimmen kann, ob beschattet werden muss, oder nicht.
+ $gv_elevation = $plugin_info{'elevation'};
+ $gv_azimuth = $plugin_info{'azimuth'};
+
+ plugin_log($plugname, "1 - Elevation: ".$gv_elevation." , Helligkeit: ".$gv_helligkeit) if ($show_debug > 0);
+
+ # Pr\xFCfen, ob das Telegramm etwas am aktuellen Status \xE4ndert und ggf. merken
+ if ($gv_elevation > 0 and $gv_elevation <= 10 and $gv_helligkeit >= 10000) { $gv_beschattungEin = 'J'; }
+ if ($gv_elevation > 10 and $gv_elevation <= 20 and $gv_helligkeit >= 20000) { $gv_beschattungEin = 'J'; }
+ if ($gv_elevation > 20 and $gv_elevation <= 30 and $gv_helligkeit >= 30000) { $gv_beschattungEin = 'J'; }
+ if ($gv_elevation > 30 and $gv_elevation <= 40 and $gv_helligkeit >= 40000) { $gv_beschattungEin = 'J'; }
+ if ($gv_elevation > 40 and $gv_elevation <= 50 and $gv_helligkeit >= 50000) { $gv_beschattungEin = 'J'; }
+ if ($gv_elevation > 50 and $gv_elevation <= 90 and $gv_helligkeit >= 75000) { $gv_beschattungEin = 'J'; }
+
+ if ($gv_elevation < 0) { $gv_beschattungEin = 'N'; }
+ if ($gv_elevation > 0 and $gv_elevation <= 10 and $gv_helligkeit < 10000) { $gv_beschattungEin = 'N'; }
+ if ($gv_elevation > 10 and $gv_elevation <= 20 and $gv_helligkeit < 20000) { $gv_beschattungEin = 'N'; }
+ if ($gv_elevation > 20 and $gv_elevation <= 30 and $gv_helligkeit < 30000) { $gv_beschattungEin = 'N'; }
+ if ($gv_elevation > 30 and $gv_elevation <= 40 and $gv_helligkeit < 40000) { $gv_beschattungEin = 'N'; }
+ if ($gv_elevation > 40 and $gv_elevation <= 50 and $gv_helligkeit < 50000) { $gv_beschattungEin = 'N'; }
+ if ($gv_elevation > 50 and $gv_elevation <= 90 and $gv_helligkeit < 75000) { $gv_beschattungEin = 'N'; }
+
+ plugin_log($plugname, "2 - Beschattung ein: ".$gv_beschattungEin) if ($show_debug > 0);
+
+ # Abh\xE4ngig vom letzten g\xFCltigen Wert den neuen beschattungEin setzen
+ if ($gv_beschattungEin eq 'J' and $plugin_info{$plugname.'_beschattungEin'} eq BESCHATTUNG_AUS) {
+ ($gv_sekunden, $gv_minuten, $gv_stunden, $gv_monatstag, $gv_monat, $gv_jahr, $gv_wochentag, $gv_jahrestag, $gv_sommerzeit) = localtime(time);
+ $gv_zeitpunkt = $gv_minuten + ($gv_stunden*60);
+ $plugin_info{$plugname.'_beschattungEin'} = BESCHATTUNG_EIN;
+ $plugin_info{$plugname.'_beschattungEinTime'} = $gv_zeitpunkt;
+ } elsif ($gv_beschattungEin eq 'N' and $plugin_info{$plugname.'_beschattungEin'} eq BESCHATTUNG_EIN) {
+ ($gv_sekunden, $gv_minuten, $gv_stunden, $gv_monatstag, $gv_monat, $gv_jahr, $gv_wochentag, $gv_jahrestag, $gv_sommerzeit) = localtime(time);
+ $gv_zeitpunkt = $gv_minuten + ($gv_stunden*60);
+ $plugin_info{$plugname.'_beschattungEin'} = BESCHATTUNG_AUS;
+ $plugin_info{$plugname.'_beschattungEinTime'} = $gv_zeitpunkt;
+ }
+ } elsif ($msg{'apci'} eq "A_GroupValue_Write" and $msg{'dst'} eq $gv_gaSperre) {
+ $plugin_info{$plugname.'_sperre'} = $msg{'value'};
+ }
+} elsif ($gv_event eq EVENT_SOCKET) {
+} elsif ($gv_event eq EVENT_CYCLE) {
+ # Aufruf durch Zyklus
+ $plugin_info{$plugname.'_beschattungFreigabeOld'} = $plugin_info{$plugname.'_beschattungFreigabe'};
+
+ $gv_azimuth = $plugin_info{'azimuth'};
+ $gv_elevation = $plugin_info{'elevation'};
+
+ # Pr\xFCfen, ob die Beschattung aktiviert oder deaktiviert werden muss
+ if ($plugin_info{$plugname.'_beschattungEin'} eq BESCHATTUNG_EIN and
+ $plugin_info{$plugname.'_sperre'} == 0 and
+ $plugin_info{$plugname.'_beschattungFreigabe'} eq FREIGABE_AUS) {
+
+ ($gv_sekunden, $gv_minuten, $gv_stunden, $gv_monatstag, $gv_monat, $gv_jahr, $gv_wochentag, $gv_jahrestag, $gv_sommerzeit) = localtime(time);
+ $gv_zeitpunkt = $gv_minuten + ($gv_stunden*60);
+ $gv_zeitdifferenz = $gv_zeitpunkt - $plugin_info{$plugname.'_beschattungEinTime'};
+ plugin_log($plugname, "3a - Zeit neu: ".$gv_zeitpunkt.", Zeit alt: ".$plugin_info{$plugname.'_beschattungEinTime'}.", Differenz: ".$gv_zeitdifferenz) if ($show_debug > 0);
+ if ($gv_zeitdifferenz > 5) {
+ $plugin_info{$plugname.'_beschattungFreigabe'} = FREIGABE_EIN;
+ knw_write($gv_gaFreigabe, 1);
+ }
+ } elsif ( ($plugin_info{$plugname.'_beschattungEin'} eq BESCHATTUNG_AUS or
+ $plugin_info{$plugname.'_sperre'} == 1) and
+ $plugin_info{$plugname.'_beschattungFreigabe'} eq FREIGABE_EIN) {
+
+ ($gv_sekunden, $gv_minuten, $gv_stunden, $gv_monatstag, $gv_monat, $gv_jahr, $gv_wochentag, $gv_jahrestag, $gv_sommerzeit) = localtime(time);
+ $gv_zeitpunkt = $gv_minuten + ($gv_stunden*60);
+ $gv_zeitdifferenz = $gv_zeitpunkt - $plugin_info{$plugname.'_beschattungEinTime'};
+ plugin_log($plugname, "3b - Zeit neu: ".$gv_zeitpunkt.", Zeit alt: ".$plugin_info{$plugname.'_beschattungEinTime'}.", Differenz: ".$gv_zeitdifferenz) if ($show_debug > 0);
+ if ($gv_zeitdifferenz > 15) {
+ $plugin_info{$plugname.'_beschattungFreigabe'} = FREIGABE_AUS;
+ knw_write($gv_gaFreigabe, 0);
+ }
+ }
+}
+
+return 'Freigabe erfolgreich berechnet!';
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|