[erledigt] Frage zu 99_myUtils.pm

Begonnen von Helmi55, 17 Dezember 2018, 15:16:56

Vorheriges Thema - Nächstes Thema

Helmi55

Hallo
ich habe von hier etwas "gestohlen" https://forum.fhem.de/index.php/topic,53500.msg472864.html#msg472864.  (Danke dafür)
Nun wird die Windrichtung aber nicht angezeigt (zeigt immer nur Norden)
Nun meine Frage ob ich den Neuen "sub" richtig angelegt habe?

# Save this file as 99_myUtils.pm, and create your own functions in the new
# file. They are then available in every Perl expression.

package main;

use strict;
use warnings;
use POSIX;
use JSON;

sub
myUtils_Initialize($$)
{
  my ($hash) = @_;
}

# Enter you functions below _this_ line.

sub
replaceJSON ($$) {
   my ($valToReplace, $value) = @_;
   $value = InternalVal("Ofen", "value", $value);
   Log3 ("Ofen", 3, "replaceJSON Internalvalue: $value");
   fhem ("get Ofen revision");
   my $json = ReadingsVal("Ofen", "controlsJSON","");
   Log3 ("Ofen", 3, "replaceJSON configsJSON: $json");
   return if ($json eq "");
   my $decoded = decode_json($json);
   my $result;
   for my $key ( keys %$decoded ) {
      $result .= "$key=";
      if ($key eq $valToReplace) {
         $result .= $value."&";
      } else {
         $result .= $decoded->{$key}."&";
      }
   }
   chop($result);
   Log3("Ofen", 3, "replaceJSON Result: $result");
   return $result;
}
sub Twilight_CompassPoint_T($) {
  my ($azimuth) = @_;

  my $compassPoint = "unknown";

  if ($azimuth      < 22.5) {
     $compassPoint = "N";
  } elsif ($azimuth < 45)   {
     $compassPoint = "N-NO";
  } elsif ($azimuth < 67.5) {
     $compassPoint = "NO";
  } elsif ($azimuth < 90)   {
     $compassPoint = "O-NO";
  } elsif ($azimuth < 112.5){
     $compassPoint = "O";
  } elsif ($azimuth < 135)  {
     $compassPoint = "O-SO";
  } elsif ($azimuth < 157.5){
    $compassPoint = "SO";
  } elsif ($azimuth < 180)  {
    $compassPoint = "S-SO";
  } elsif ($azimuth < 202.5){
    $compassPoint = "S";
  } elsif ($azimuth < 225)  {
    $compassPoint = "S-SW";
  } elsif ($azimuth < 247.5){
    $compassPoint = "SW";
  } elsif ($azimuth < 270)  {
    $compassPoint = "W-SW";
  } elsif ($azimuth < 292.5){
    $compassPoint = "W";
  } elsif ($azimuth < 315)  {
    $compassPoint = "W-NW";
  } elsif ($azimuth < 337.5){
    $compassPoint = "NW";
  } elsif ($azimuth <= 361)  {
    $compassPoint = "N-NW";
  }
  return $compassPoint;
}

1;


Danke für eure Hilfe
Gruß Helmut
System1 fhem 6.1 auf RPi 4B mit 4GB, HMUSBConfig, DS9490R-1Wire, Busware USB 868, Pool-Solarsteuerung mit FHEM. System2 fhem 6.1 auf RPi 4B mit 4GB (Bullseye) mit Busware USB 868 und 433 und HMUARTLGW für Haussteuerung

https://www.flickr.com/photos/canonhelmi/

JoWiemann

Hilfreich wäre noch ein List vom Device in dem die sub eingesetzt wird.
Jörg Wiemann

Slave: RPi B+ mit 512 MB, COC (868 MHz), CUL V3 (433.92MHz SlowRF); FHEMduino, Aktuelles FHEM

Master: CubieTruck; Debian; Aktuelles FHEM

Helmi55

Sorry hab ich vergessen - ist ein NETATMO Windmesser

Internals:
   DEF        MODULE 70:ee:50:36:f1:c2 06:00:00:03:1c:b0
   Device     70:ee:50:36:f1:c2
   IODev      netatmo
   LAST_POLL  2018-12-17 15:34:11
   Module     06:00:00:03:1c:b0
   NAME       netatmo_M06_00_00_03_1c_b0
   NOTIFYDEV  global
   NR         487
   NTFY_ORDER 50-netatmo_M06_00_00_03_1c_b0
   STATE      Wind: 1 km/h (0 bft, N), Böen: 3 km/h (0 bft, N), Max: 11 km/h (0 bft, N)
   SUBTYPE    MODULE
   TYPE       netatmo
   dataTypes  WindStrength,WindAngle,GustStrength,GustAngle
   firmware   19
   last_message 2018-12-17 15:19:14
   last_seen  2018-12-17 15:19:14
   last_setup 2018-12-07 14:41:30
   model      NAModule2
   moduleName Windmesser
   openRequests 0
   rf_status  73
   status     ok
   READINGS:
     2018-12-17 15:34:11   active          ok
     2018-12-17 15:23:42   batteryPercent  100
     2018-12-17 15:23:42   batteryState    ok
     2018-12-17 15:23:42   batteryVoltage  6.115
     2018-12-17 15:29:03   gustangle       115
     2018-12-17 15:34:11   gustdirection   N
     2018-12-17 15:29:03   guststrength    3
     2018-12-17 15:34:11   guststrength_bft 0
     2018-12-17 15:29:03   windangle       90
     2018-12-17 14:13:32   windangle_max   249
     2018-12-17 15:34:11   winddirection   N
     2018-12-17 15:34:11   winddirection_max N
     2018-12-17 15:29:03   windstrength    1
     2018-12-17 15:34:11   windstrength_bft 0
     2018-12-17 14:13:32   windstrength_max 11
     2018-12-17 15:34:11   windstrength_max_bft 0
   helper:
     INTERVAL   300
     NEXT_POLL  1545057551
     last_status_store 1545056943
     readingNames:
       windstrength,windangle,guststrength,gustangle
Attributes:
   IODev      netatmo
   devStateIcon .*:no-icon
   interval   300
   room       netatmo
   stateFormat Wind: windstrength km/h (windstrength_bft bft, winddirection), Böen: guststrength km/h (guststrength_bft bft, gustdirection), Max: windstrength_max km/h (windstrength_max_bft bft, winddirection_max)
   userReadings guststrength_bft { int((ReadingsVal("netatmo_M06_00_00_03_1c_b0
","guststrength",0)*0.33227)**0.666666667+0.5);; },
windstrength_max_bft { int((ReadingsVal("netatmo_M06_00_00_03_1c_b0
","windstrength_max",0)*0.33227)**0.666666667+0.5);; },
windstrength_bft { int((ReadingsVal("netatmo_M06_00_00_03_1c_b0
","windstrength",0)*0.33227)**0.666666667+0.5);; },
winddirection {Twilight_CompassPoint_T(ReadingsVal("netatmo_M06_00_00_03_1c_b0
","windangle",0));; },
gustdirection {Twilight_CompassPoint_T(ReadingsVal("netatmo_M06_00_00_03_1c_b0
","gustangle",0));; }, 
winddirection_max {Twilight_CompassPoint_T(ReadingsVal("netatmo_M06_00_00_03_1c_b0
","windangle_max",0));; }


Danke
System1 fhem 6.1 auf RPi 4B mit 4GB, HMUSBConfig, DS9490R-1Wire, Busware USB 868, Pool-Solarsteuerung mit FHEM. System2 fhem 6.1 auf RPi 4B mit 4GB (Bullseye) mit Busware USB 868 und 433 und HMUARTLGW für Haussteuerung

https://www.flickr.com/photos/canonhelmi/

amenomade

Hast Du wirklich jedes Mal einen Zeilenumbruch nach ReadingsVal("netatmo_M06_00_00_03_1c_b0 ?
Pi 3B, Alexa, CUL868+Selbstbau 1/2λ-Dipol-Antenne, USB Optolink / Vitotronic, Debmatic und HM / HmIP Komponenten, Rademacher Duofern Jalousien, Fritz!Dect Thermostaten, Proteus

Helmi55

Servus tja leider als "Nichtwissender" hat sich das beim Kopieren eingeschlichen. Werde das heute noch ändern und sehen was dann passiert.
Melde mich am späten Nachmittag wieder
LG
Helmut
P.S. Ofen funktioniert tadellos - Danke
System1 fhem 6.1 auf RPi 4B mit 4GB, HMUSBConfig, DS9490R-1Wire, Busware USB 868, Pool-Solarsteuerung mit FHEM. System2 fhem 6.1 auf RPi 4B mit 4GB (Bullseye) mit Busware USB 868 und 433 und HMUARTLGW für Haussteuerung

https://www.flickr.com/photos/canonhelmi/

Helmi55

Servus
Danke du bist mein Retter - wieder etwas dazu gelernt.
Kaum macht man(n) es richtig funktioniert es.
Wünsche dir schöne Feiertage
LG
Helmut
System1 fhem 6.1 auf RPi 4B mit 4GB, HMUSBConfig, DS9490R-1Wire, Busware USB 868, Pool-Solarsteuerung mit FHEM. System2 fhem 6.1 auf RPi 4B mit 4GB (Bullseye) mit Busware USB 868 und 433 und HMUARTLGW für Haussteuerung

https://www.flickr.com/photos/canonhelmi/