FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: fadi1 am 24 Februar 2021, 16:31:12

Titel: [Gelöst]suche map()
Beitrag von: fadi1 am 24 Februar 2021, 16:31:12
hallo

ich suche einen weg wie ich map() https://www.arduino.cc/reference/de/language/functions/math/map/ (https://www.arduino.cc/reference/de/language/functions/math/map/) in fhem umsetzen kann , wenn möglich ohne einer ESP32

meine derzeitige Lösung funktioniert zwar aber mit einer Funktion wie es map() macht wäre es schöner umzusetzen


GPIO4_DS18B20_0000058679a8:temperature:.* {

my $xxx = 0.000;
my $rrr = 1;

if ($EVTPART1 < "43.000")
      {
      $xxx=0.000;
      }
if ($EVTPART1 > "43.000")
      {
      $xxx = 0.003;
      }
if ($EVTPART1 > "44.000")
      {
      $xxx = 0.004;
      }
if ($EVTPART1 > "45.000")
      {
      $xxx = 0.005;
  $rrr = 0;
      }
if ($EVTPART1 > "46.000")
      {
      $xxx = 0.006;
  $rrr = 0;
      }
if ($EVTPART1 > "47.000")
      {
      $xxx = 0.007;
  $rrr = 0;
      }
if ($EVTPART1 > "48.000")
      {
      $xxx = 0.008;  
      $rrr = 0;
      }
if ($EVTPART1 > "49.000")
      {
      $xxx = 0.009;
  $rrr = 0;
      }
if ($EVTPART1 > "50.000")
      {
      $xxx = 0.010;
  $rrr = 0;
      }
if ($EVTPART1 > "51.000")
      {
      $xxx=0.015;
      $rrr = 0;
      }
if ($EVTPART1 > "52.000")
      {
      $xxx=0.020;
      $rrr = 0;
      }

# fhem("attr lueft_reset disable ". $rrr ."");
fhem("setreading dimm dimm_TLed_l " . $xxx . "");
fhem("setreading dimm dimm_L_lüfter " . $xxx*100 . "");

system("echo \"23=" . $xxx . "\" > /dev/pi-blaster");

}


Danke für eure Anregungen 
Titel: Antw:suche map()
Beitrag von: Beta-User am 24 Februar 2021, 16:47:07
Afaik gibt's dazu keine einfache Lösung, siehe evtl. dazu auch https://forum.fhem.de/index.php/topic,110442.0.html
Titel: Antw:suche map()
Beitrag von: CoolTux am 24 Februar 2021, 19:23:26
given ($zahl) {
  when (100) { $zahl2 = 1; next; };
  when (200) { $zahl2 = 2; next; };
      # usw...
      default { $zahl2 = $zahl }
    }


Schau mal ob Du damit weiter kommst.
Titel: Antw:suche map()
Beitrag von: pwlr am 24 Februar 2021, 23:14:31

Zitatich suche einen weg wie ich map() https://www.arduino.cc/reference/de/language/functions/math/map/ in fhem umsetzen kann , wenn möglich ohne einer ESP32

In dem Link ist unter "Anhang" die von map() verwendete Formel dokumentiert. Die könnte m.E. auch in einer Perl-Subroutine entsprechend umgesetzt werden.
Titel: Antw:suche map()
Beitrag von: Beta-User am 25 Februar 2021, 07:52:30
Mal weg von der map()-Frage:

Warum ermittelst du nicht deine beiden Parameter getrennt?

Ungetestet sollte etwa folgendes RAW rauskommen:
defmod n_test notify GPIO4_DS18B20_0000058679a8:temperature:.* {\
my $xxx = 0;;\
my $rrr = $EVTPART1 > 45 ? 0 : 1;;\
if ($EVTPART1 > 52) {\
    $xxx=0.020;;\
} elsif ($EVTPART1 > 43) {\
    $xxx = ($EVTPART1 - 40)/1000;;\
}\
fhem("setreading dimm dimm_TLed_l $xxx ;; setreading dimm dimm_L_lüfter " . $xxx*100);;\
system("echo \"23=" . $xxx . "\" > /dev/pi-blaster");;\
}
Titel: Antw:suche map()
Beitrag von: pwlr am 25 Februar 2021, 16:09:27
Moin,

eine sub in die myUtils stellen:
sub fhem_map($$$$$) {

#  map(value, fromLow, fromHigh, toLow, toHigh)
#see https://www.arduino.cc/en/pmwiki.php?n=Reference/Map

my($value,$fromLow,$fromHigh,$toLow,$toHigh) = @_;
my$result = (($value - $fromLow) * ( $toHigh - $toLow)) / ($fromHigh - $fromLow) + $toLow;
return $result;
};


und dann beispielsweise in der Command-Zeile aufrufen:
{fhem_map(50, 0, 100, 100, 200)}

oder eben in notify etc. entsprechend einbauen.
Titel: Antw:suche map()
Beitrag von: fadi1 am 25 Februar 2021, 23:57:15
Hallo
danke für die wertvollen Tipps 8)
ich habe mir jetzt eine Sub in myUtils erstellt und dafür den Code von "pwlr" genommen  funktioniert bestens Danke an euch alle.
ihr seit alle super 8),
ich bin noch Meilen von den Können entfernt.