Hallo an Alle,
Ich habe eine Homematic Wetterstation und möchte über einen Dummy die Windrichtung anzeigen.
Die Wetterstation gibt die aktuelle Richtung in Grad an, ich möchte aber dass das Dummy z.B. SSW anzeigt.
Über die Suchfunktion habe ich leider nichts passendes gefunden.
Ich würde nun so vorgehen mir ne Batterie mit if-Abfragen zu basteln.
Z.B. so: IF WERT zwischen 80 und 100 Grad dann ist Richtung = Osten
Mir stellt sich jetzt nur die Frage ob das auch eleganter geht, oder ob es vielleicht schon etwas gibt was ich dafür verwenden kann?
Dank euch schonmal im Vorraus
Grüsse
Markus
Du kannst einfach Twilight_CompassPoint() aufrufen:
Testhalber kannst du in der Oberfläche mit {Twilight_CompassPoint(35)} ausprobieren, ob es funktioniert.
################################################################################
sub Twilight_CompassPoint($) {
my ($azimuth) = @_;
my $compassPoint = "unknown";
if ($azimuth < 22.5) {
$compassPoint = "north";
} elsif ($azimuth < 45) {
$compassPoint = "north-northeast";
} elsif ($azimuth < 67.5) {
$compassPoint = "northeast";
} elsif ($azimuth < 90) {
$compassPoint = "east-northeast";
} elsif ($azimuth < 112.5){
$compassPoint = "east";
} elsif ($azimuth < 135) {
$compassPoint = "east-southeast";
} elsif ($azimuth < 157.5){
$compassPoint = "southeast";
} elsif ($azimuth < 180) {
$compassPoint = "south-southeast";
} elsif ($azimuth < 202.5){
$compassPoint = "south";
} elsif ($azimuth < 225) {
$compassPoint = "south-southwest";
} elsif ($azimuth < 247.5){
$compassPoint = "southwest";
} elsif ($azimuth < 270) {
$compassPoint = "west-southwest";
} elsif ($azimuth < 292.5){
$compassPoint = "west";
} elsif ($azimuth < 315) {
$compassPoint = "west-northwest";
} elsif ($azimuth < 337.5){
$compassPoint = "northwest";
} elsif ($azimuth <= 361) {
$compassPoint = "north-northwest";
}
return $compassPoint;
Hallo Dietmar,
dass funktioniert genau so wie ich es wollte :)
Recht Herzlichen Dank dafür!!
Hallo Zusammen,
Aufgrund wiederholter Anfragen poste ich nochmal meinen Code.
Folgende Zeilen habe ich in die 99_myUtils.pm eingefügt:
#########################################################
## Wandelt die Kompass daten der Wetterstation
## in Klartext Himmelsrichtung um
#########################################################
sub myTwilight_CompassPoint($) {
my ($azimuth) = @_;
my $compassPoint = "unknown";
if ($azimuth < 11.25) {
$compassPoint = "NORD";
} elsif ($azimuth < 33.75) {
$compassPoint = "NORD-NordOst";
} elsif ($azimuth < 56.25) {
$compassPoint = "NORD-OST";
} elsif ($azimuth < 78.75) {
$compassPoint = "OST-NordOst";
} elsif ($azimuth < 101.25){
$compassPoint = "OST";
} elsif ($azimuth < 123.75) {
$compassPoint = "OST-SüdOst";
} elsif ($azimuth < 146.25){
$compassPoint = "SÜD-OST";
} elsif ($azimuth < 168.75) {
$compassPoint = "SÜD-SüdOst";
} elsif ($azimuth < 191.25){
$compassPoint = "SÜD";
} elsif ($azimuth < 213.75) {
$compassPoint = "SÜD-SüdWest";
} elsif ($azimuth < 236.25){
$compassPoint = "SÜD-WEST";
} elsif ($azimuth < 258.75) {
$compassPoint = "WEST-SüdWest";
} elsif ($azimuth < 281.25){
$compassPoint = "WEST";
} elsif ($azimuth < 303.75) {
$compassPoint = "WEST-NordWest";
} elsif ($azimuth < 326.25){
$compassPoint = "NORD-WEST";
} elsif ($azimuth <= 348.75) {
$compassPoint = "NORD-NordWest";
} elsif ($azimuth <= 361) {
$compassPoint = "NORD";
}
return $compassPoint;
}
in der fhem.cfg werden dann 2 Dummies angelegt und gefüllt
define WindRichtung_grad dummy
attr WindRichtung_grad icon weather_directions
attr WindRichtung_grad room Wetter
define WindRichtung_text dummy
attr WindRichtung_text icon weather_directions
attr WindRichtung_text room Aussenbereich,Wetter
define WindRichtungNotify notify EXT_Wetterstation:windDirection.* {\
my $richtung_grad = (ReadingsVal("EXT_Wetterstation", "windDirection", 0));;\
my $richtung_text = myTwilight_CompassPoint($richtung_grad);;\
fhem("set WindRichtung_grad $richtung_grad");;\
fhem("set WindRichtung_text $richtung_text");;\
}
attr WindRichtungNotify icon weather_wind
attr WindRichtungNotify room Wetter