Userreading mit STATEFORMAT umrechnen und ausgeben

Begonnen von Maxl, 19 April 2024, 17:27:15

Vorheriges Thema - Nächstes Thema

Maxl

Hallo,

ich möchte die readings temp, ph und rx in STATEFORMAT anzeigen, was auch soweit funktioniert, aber eigentlich (temp/=10, ph/=100) umgerechnet, ich hätte schon einiges probiert aber komme nicht dahinter wo ich die Berechnung im Code anstellen muss.
Hätte auch bereits Variable phval, rxval und temp angelegt, nur bringe ich diese nicht mit STATEFORMAT angezeigt. 

[code]define MQTT2_at_home_controllino_pool MQTT2_DEVICE at_home_controllino_pool
attr MQTT2_at_home_controllino_pool devStateIcon {my $onl = ReadingsVal($name,"online","false") eq "false" ? "rot" : ReadingsVal($name,"new_fw","false") eq "true" ? "gelb" : "gruen";;my $light = ReadingsVal($name,"state","off");;my $temp = round(ReadingsNum($name,'temp',0)/10,3);;my $phval = round(ReadingsNum($name,'ph',0)/100,3);;my $rxval = ReadingsNum($name,'rx',0);;my $show = '<a href="';;$show .= $onl eq "gelb" ? "/fhem?cmd.dummy=set $name x_update&XHR=1\">" : "http://".ReadingsVal($name,"ip","none").' "target="_blank">';;$show .= FW_makeImage("10px-kreis-".$onl)."</a>";;"<div> $show <a href=\"/fhem?cmd.dummy=set $name toggle&XHR=1\">".FW_makeImage($light)."</a> $reb<div> $temp $phval $rxval </div>" }
attr MQTT2_at_home_controllino_pool group Pool
attr MQTT2_at_home_controllino_pool readingList at_home_controllino_pool:at_home/controllino_pool/relay/0:.* relay_0\
at_home_controllino_pool:at_home/controllino_pool/relay/1:.* relay_1\
at_home_controllino_pool:at_home/controllino_pool/relay/2:.* relay_2\
at_home_controllino_pool:at_home/controllino_pool/relay/3:.* relay_3\
at_home_controllino_pool:at_home/controllino_pool/relay/4:.* relay_4\
at_home_controllino_pool:at_home/controllino_pool/relay/5:.* relay_5\
at_home_controllino_pool:at_home/controllino_pool/relay/6:.* relay_6\
at_home_controllino_pool:at_home/controllino_pool/relay/7:.* relay_7\
at_home_controllino_pool:at_home/controllino_pool/relay/8:.* relay_8\
at_home_controllino_pool:at_home/controllino_pool/relay/9:.* relay_9\
at_home_controllino_pool:at_home/controllino_pool/pumpspeed:.* pumpspeed\
at_home_controllino_pool:at_home/controllino_pool/weather:.* weather\
at_home_controllino_pool:at_home/controllino_pool/pooldata/temp:.* temp\
at_home_controllino_pool:at_home/controllino_pool/pooldata/relstat:.* relstat\
at_home_controllino_pool:at_home/controllino_pool/pooldata/ph:.* ph\
at_home_controllino_pool:at_home/controllino_pool/pooldata/rx:.* rx
attr MQTT2_at_home_controllino_pool room Wetter
attr MQTT2_at_home_controllino_pool setList relay_0:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/0/command $EVTPART1\
relay_1:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/1/command $EVTPART1\
relay_2:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/2/command $EVTPART1\
relay_3:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/3/command $EVTPART1\
relay_4:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/4/command $EVTPART1\
relay_5:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/5/command $EVTPART1\
relay_6:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/6/command $EVTPART1\
relay_7:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/7/command $EVTPART1\
relay_8:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/8/command $EVTPART1\
relay_9:iconSwitch,on,li_wht_off,off,li_wht_on at_home/controllino_pool/relay/9/command $EVTPART1\
weather:bad,good at_home/controllino_pool/weather $EVTPART1\
x_mqttcom at_home/controllino_pool/command $EVTPART1
attr MQTT2_at_home_controllino_pool stateFormat Temp.: temp °C , PH-Wert: ph , RX-Wert rx mV
attr MQTT2_at_home_controllino_pool webCmd relay_0:relay_1:relay_2:relay_3:relay_4:relay_5:relay_6:relay_7:relay_8:relay_9
#   CID        at_home_controllino_pool
#   DEF        at_home_controllino_pool
#   FUUID      662278b7-f33f-7117-2230-46b903db16a87080
#   IODev      MQTT2_FHEM_Server
#   LASTInputDev MQTT2_FHEM_Server
#   MQTT2_FHEM_Server_CONN MQTT2_FHEM_Server_192.168.1.112_49171
#   MQTT2_FHEM_Server_MSGCNT 544
#   MQTT2_FHEM_Server_TIME 2024-04-19 17:15:19
#   MSGCNT     544
#   NAME       MQTT2_at_home_controllino_pool
#   NR         67
#   STATE      Temp.: 187 °C , PH-Wert: 745 , RX-Wert 456 mV
#   TYPE       MQTT2_DEVICE
#   eventCount 548
#   READINGS:
#     2024-04-19 16:52:23   IODev           MQTT2_FHEM_Server
#     2024-04-19 17:15:19   ph              745
#     2024-04-19 17:15:19   pumpspeed       0
#     2024-04-19 17:15:19   relay_0         off
#     2024-04-19 17:15:19   relay_1         off
#     2024-04-19 17:15:19   relay_2         off
#     2024-04-19 17:15:19   relay_3         off
#     2024-04-19 17:15:19   relay_4         off
#     2024-04-19 17:15:19   relay_5         off
#     2024-04-19 17:15:19   relay_6         off
#     2024-04-19 17:15:19   relay_7         off
#     2024-04-19 17:15:19   relay_8         off
#     2024-04-19 17:15:19   relay_9         on
#     2024-04-19 17:15:19   relstat         0
#     2024-04-19 17:15:19   rx              456
#     2024-04-19 17:07:10   state           relay_1
#     2024-04-19 17:15:19   temp            187
#     2024-04-19 17:15:19   weather         good
#
setstate MQTT2_at_home_controllino_pool Temp.: 187 °C , PH-Wert: 745 , RX-Wert 456 mV
setstate MQTT2_at_home_controllino_pool 2024-04-19 16:52:23 IODev MQTT2_FHEM_Server
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 ph 745
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 pumpspeed 0
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_0 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_1 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_2 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_3 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_4 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_5 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_6 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_7 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_8 off
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relay_9 on
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 relstat 0
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 rx 456
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:07:10 state relay_1
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 temp 187
setstate MQTT2_at_home_controllino_pool 2024-04-19 17:15:19 weather good

[/code]
FHEM auf Raspberry mit HM, HMC und AVR Netios.

Adimarantis

So vielleicht?
attr .... stateformat {sprintf ("Temperature: %.1f°C PH: %.1f%%", ReadingsVal($name,"temp",0)/10, ReadingsVal($name,"ph",0)/10) }
Raspberry 4 + HM-MOD-RPI-PCB (pivCCU) + RfxTrx433XL + 2xRaspberry 1
Module: 50_Signalbot, 52_I2C_ADS1x1x , 58_RPI_1Wire, (50_SPI_MAX31865)

TomLee

Zitat... ich hätte schon einiges probiert aber komme nicht dahinter wo ich die Berechnung im Code anstellen muss.
Hätte auch bereits Variable phval, rxval und temp angelegt, nur bringe ich diese nicht mit STATEFORMAT angezeigt.


Hallo,

ZitatstateFormat
Ändert den Gerätestatus, dies ist z.Bsp. in der Ausgabe des list Kommandos zu sehen, oder in der Raumübersicht von FHEMWEB. Falls nicht gesetzt, dann wird das state Reading übernommen. Sonst werden alle Wörter im Wert des Attributes durch das entsprechende Reading des Gerätes ersetzt (soweit vorhanden). Falls der Wert in {} eingeschlossen ist, dann wird es als Perl Ausdruck ausgewertet. Die Auswertung passiert bei jeder Änderung eines Readings.
Die hier beschriebene "set magic" wird auch angewendet.
Hinweis: Manche Module aktualisieren STATE ganz oder teilweise direkt. In diesen Fällen kann es zu abweichenden Anzeigen kommen.

Man muß also auf die Perlebene wechseln, um dann mit den Funktionen ReadingsVal bzw. ReadingsNum die Werte auszulesen und mit ihnen zu rechnen.


Einfacher ist es hier im MQTT2_DEVICE-Kontext die Werte bevor sie in ein Reading geschrieben umzurechnen, dann spart man sich das in stateformat:
at_home_controllino_pool:at_home/controllino_pool/pooldata/ph:.* {{ph => $EVENT/100}}
at_home_controllino_pool:at_home/controllino_pool/pooldata/temp:.* {{temperature => $EVENT/10}}

Gruß

Thomas

Maxl

FHEM auf Raspberry mit HM, HMC und AVR Netios.