Neues Modul 98_FReplacer zum Ersetzen von Readings in Dateien (z.B. SVG)

Begonnen von StefanStrobel, 22 November 2014, 15:32:15

Vorheriges Thema - Nächstes Thema

StefanStrobel

Hallo,

98_FReplacer (ursprünglich FileReplacer) ist nun eingecheckt. Das Modul liest in definierbaren Intervallen eine Vorlagendatei (zum Beispeil eine SVG Grafik), erstetzt darin enthaltene Werte oder Platzhalter mit Readings oder dem Ergebnis von Perl Expressions (definierbar über Attribute) und erzeugt daraus eine neue Datei. Danach kann optional ein externes Programm aufgerufen werden, mit dem beispielsweise die erzeugte SVG-Grafik in eine PNG-Grafik umgewandelt werden kann.

Der ursprüngliche Anwendungsfall ist die Darstellung einer Fhem-Übersicht auf einem Kindle mit eInk Display. Ein Kindle kann dabei die meiste Zeit schlafen, beispielsweise alle 10 Minuten aufwachen und per WLAN eine PNG Grafik abholen, anzeigen und wieder einschlafen. Dadurch hält eine Akkuladung ca. eine Woche oder auch länger.

Eine typische Definition mit dem FReplacer Modul sieht folgendermaßen aus:


define fr FileReplacer /opt/fhem/www/images/template.svg /opt/fhem/www/images/status.svg 60

attr fr Rep01Reading WP:Status
attr fr Rep01Regex HausHeizung

attr fr Rep02Reading PWP:Temp_Delta
attr fr Rep02Regex PWPHeizung
attr fr Rep02Format Heizung: %s K
attr fr Rep02MaxAge 120:Heizung Aus
attr fr Rep02MinValue 0.4:Heizung Idle

attr fr Rep03Reading ZL:Temp_Abluft
attr fr Rep03Regex 22,5
attr fr Rep03Format %.1f

attr fr PostCommand bash -c 'inkscape /opt/fhem/www/images/status.svg -e=tmp.png;; convert tmp.png -type GrayScale -depth 8 /opt/fhem/www/images/status.png' >/dev/null 2>&1 &
attr fr ReplacementEncode UTF-8


Aus der Doku zu den Attributen:

Rep[0-9]+Regex
    defines the regex to be used for finding the right string to be replaced with the corresponding Reading / Expr result
Rep[0-9]+Reading
    defines a device and reading to be used as replacement value. It is specified as devicename:readingname
Rep[0-9]+MaxAge
    this can optionally be used together with RepReading to define a maximum age of the reading.
    It is specified as seconds:replacement. If the corresponding reading has not been updated for the specified number of seconds,
    then the replacement string is used instead of the reading to do the replacement and further Expr or Format attributes will be ignored for this value
Rep[0-9]+MinValue
    this can optionally be used together with RepReading to define a minimum value of the reading. It is specified as min:replacement.
    If the corresponding reading is too small, then the replacement string is used instead of the reading to do the replacement
    and further RepExpr or RepFormat attributes will be ignored for this value
Rep[0-9]+MaxValue
    this can optionally be used together with Reading to define a maximum value of the reading.
    It is specified as max:replacement. If the corresponding reading is too big, then the replacement string is used instead of the reading to do the replacement
    and further RepExpr or RepFormat attributes will be ignored for this value
Rep[0-9]+Expr
    defines an optional expression that can be used compute the replacement value.
    If RepExpr is used together with RepReading then Expr is evaluated after getting the Reading and the value of the reading can be used in the expression as $replacement.
    If only RepExpr is specified then Readings can be used with the perl function ReadingsVal() inside the expression.
    If neither RepExpr nor Reading is specified then the match for the correspondig Regex will be replaced with an empty string.
Rep[0-9]+Format
    defines an optional format string to be used in a sprintf statement to format the replacement before it is applied.
    Can be used with RepReading or RepExpr or both.


Im Wiki gibt es eine Seite mit Anleitung zum Vorbereiten des Kindle und weiteren Details: http://www.fhemwiki.de/wiki/Kindle_Display
Die ursprüngliche Diskussion im Forum ist hier: http://forum.fhem.de/index.php/topic,21821.0.html

Gruss
   Stefan