Moin,
Ich versuche mir ein Modul zu schreiben um ein Solaredge SMI-35 über Modbus TCP auszulesen.
Habe schon ein paar Werte ausgelesen, scheitere aber daran, dass Solaredge nicht mit floating-point arbeitet.
Das Komma verschiebt sich um einen bestimmten Wert (Scale-Factor) nach rechts/links, welcher in einem anderen Modbus Register zu finden ist und sich auch regelmäßig ändert.
Hier ein Auszug von der SunSpec Beschreibung
ZitatAs an alternative to floating point format, values are represented by Integer values with a signed scale factor applied. The scale factor explicitly shifts the decimal point to left (negative value) or to the right (positive value).
For example, a value "Value" may have an associated value "Value_SF" Value = "Value" * 10^ Value_SF for example:
For "Value" = 2071 and "Value_SF" = -2 Value = 2071*10^-2 = 20.71
For "Value" = 2071 and "Value_SF" = 2 Value = 2071*10^2 = 207100
Anbei ein Bild
Hier ein Auszug aus dem Modul
"h40100" => {
name => "I_DC_Power", # internal name of this register in the hardware doc
reading => "DC_current_W", # name of the reading for this value
len => 1, # number of Registers this value spans
#unpack => "s>", # defines the translation between data in the module and in the communication frame
#expr => '$val /100', # conversion of raw value to visible value
#format => '%.f', # format string for sprintf
polldelay => "x1", # only poll this Value if last read is older than 3*Iteration, otherwiese getUpdate will skip it
},
"h40101" => {
name => "I_DC_Power_SF", # internal name of this register in the hardware doc
reading => "SF_DC_current_W", # name of the reading for this value
len => 1, # number of Registers this value spans
unpack => "s>", # defines the translation between data in the module and in the communication frame
#expr => '$val /100', # conversion of raw value to visible value
#format => '%.f', # format string for sprintf
polldelay => "x1", # only poll this Value if last read is older than 3*Iteration, otherwiese getUpdate will skip it
},
Wie bekomme ich es jetzt auf Modulseite hin das Komma um den Scale-Factor zu verschieben?
Negative Werte verschieben das Komma nach Links und positive nach Rechts.
z.B.
Wert 23530 - SF -2 = Ausgabe in FHEM 235,30
Wert 12 - SF 2 = Ausgabe in FHEM 1200
Wäre nett wenn mir jemand von den Perl-Profs mir hier unter die Arme greifen könnte.
Mit freundlichen Grüßen
Ich antworte mir dann mal selbst.
Falls also jemand ein ähnliches Problem hat und der Kopf voll ist, hier meine Lösung.
"h40100" => {
name => "I_DC_Power", # internal name of this register in the hardware doc
reading => "DC_current_W", # name of the reading for this value
len => 1, # number of Registers this value spans
unpack => "s>", # defines the translation between data in the module and in the communication frame
expr => '$val *10** (ReadingsVal("$name","SF_DC_current_W",0))', # conversion of raw value to visible value
#format => '%.f', # format string for sprintf
polldelay => "x1", # only poll this Value if last read is older than 3*Iteration, otherwiese getUpdate will skip it
},
"h40101" => {
name => "I_DC_Power_SF", # internal name of this register in the hardware doc
reading => "SF_DC_current_W", # name of the reading for this value
len => 1, # number of Registers this value spans
unpack => "n!", # defines the translation between data in the module and in the communication frame
#expr => '$val /100', # conversion of raw value to visible value
#format => '%.f', # format string for sprintf
polldelay => "x1", # only poll this Value if last read is older than 3*Iteration, otherwiese getUpdate will skip it
},
Man könnte jetzt noch die Readings für den Scale-Factor mit einem Punkt davor versehen damit sie nicht im Frontend auftauchen, dies halte ich aber für unnötig.
Jetzt klappt es wie gewünscht.
Mit freundlichen Grüßen