FHEM Forum

FHEM => Anfängerfragen => Thema gestartet von: andies am 07 September 2018, 05:55:00

Titel: [gelöst] Reading mit Perl setzen geht nicht?
Beitrag von: andies am 07 September 2018, 05:55:00
Ich habe ein device, das mir stündlich die Regenmenge anzeigt (precip_today). Ich möchte gern um Mitternacht den dann ermittelten Wert erfassen und für 24h anzeigen. Also habe ich ein userreading precip_yesterday definiert und mit at folgenden Befehl formuliert
defmod RegenSetzen at *23:57 setreading wetter precip_yesterday {sprintf("%.1f", ReadingsVal("wetter", "precip_today", 0))}

Statt des Wertes wird mir aber der Perl-Code selbst in das Reading geschrieben
precip_yesterday {sprintf("%.1f", ReadingsVal("wetter", "precip_today", 0))} 2018-09-06 23:57:00

Was mache ich da falsch?

Logfile sagt
2018.09.07 04:26:19 1: PERL WARNING: Argument "{sprintf("%.1f", ReadingsVal("wetter", "precip_today", 0..." isn't numeric in sprintf at (eval 1331560) line 1.
Titel: Antw:Reading mit Perl setzen geht nicht?
Beitrag von: igami am 07 September 2018, 06:06:59
Commandref-Auszug zu set:

From featurelevel 5.7 on the set and setreading command replaces:

    [device:name] with the reading, internal or attribute of the device, if both device and the reading, internal or attribute exists.
        You can use the r:, i: or a: prefix to restrict the search to one type, analogue to the devspec filtering.
        The suffix :d retrieves the first number
        The suffix :i retrieves the integer part of the first number.
        The suffix :r<n> retrieves the first number and rounds it to <n> decimal places. If <n> is missing, then rounds it to one decimal place.
        The suffix :t returns the timestamp (works only for readings)
        The suffix :sec returns the number of seconds since the reading was set.
    Example:
        set Lamp blink [blinkDummy:number] [r:blinkDummy:duration:d]
    [device:name:d] same as above, but only the number is retrieved
    [device:name:sec] same as above, but only the number is retrieved
    {(perlExpression)} with the result of perlExpression. The $DEV variable is additionally available, designating the set device name.

These replacements are also known as "set magic".

Zu beachten sind die runden Klammern bei {(perlExpression)}
Titel: Antw:Reading mit Perl setzen geht nicht?
Beitrag von: andies am 07 September 2018, 07:29:27
Ah danke. Magic hatte ich auch (erfolglos) probiert.

Das geht nun:
setreading wetter precip_yesterday [wetter:precip_today]