[gelöst] Reading mit Perl setzen geht nicht?

Begonnen von andies, 07 September 2018, 05:55:00

Vorheriges Thema - Nächstes Thema

andies

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.
FHEM 6.3 auf RaspPi4 (Raspbian:  6.6.28+; Perl: v5.36.0)
SIGNALduino (433 MHz) und HM-UART (868 MHz), Sonoff, Blitzwolf, Somfy RTS, CAME-Gartentor, Volkszähler, Keyence-Sensor, Homematic-Sensoren und -thermostat, Ferraris-Zähler für Wasseruhr, Openlink-Nachbau Viessmann

igami

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)}
Pi3 mit fhem.cfg + DbLog/logProxy
Komm vorbei zum FHEM Treffen im Kreis Gütersloh! Das nächste Mal im April 2020.

MAINTAINER: archetype, LuftdatenInfo, monitoring, msgDialog, Nmap, powerMap
ToDo: AVScene, FluxLED

andies

#2
Ah danke. Magic hatte ich auch (erfolglos) probiert.

Das geht nun:
setreading wetter precip_yesterday [wetter:precip_today]
FHEM 6.3 auf RaspPi4 (Raspbian:  6.6.28+; Perl: v5.36.0)
SIGNALduino (433 MHz) und HM-UART (868 MHz), Sonoff, Blitzwolf, Somfy RTS, CAME-Gartentor, Volkszähler, Keyence-Sensor, Homematic-Sensoren und -thermostat, Ferraris-Zähler für Wasseruhr, Openlink-Nachbau Viessmann