DOIF Zeitberechnung in userreading

Begonnen von z0lt1, 28 Juli 2021, 08:55:24

Vorheriges Thema - Nächstes Thema

z0lt1

Hallo, mit folgender Definition schalte ich meinen Filter für x Stunden an
Internals:
   CFGFN     
   DEF        ([$SELF:P_mybutton] eq "on") (
set ChatBot message @Xxxxx Pool-Timer gestartet für [$SELF:P_hours] Stunden,
set pl_Switch.SFA on,
set pl_Switch.Chlorinator on
) (
set ChatBot message @Xxxxx Pool-Timer aus,
set pl_Switch.SFA off,
set pl_Switch.Chlorinator off,
set $SELF P_mybutton off
)

DOELSEIF ([$SELF:P_mybutton] eq "off") (
set pl_Switch.SFA off,
set pl_Switch.Chlorinator off
)
   FUUID      60fba0e7-f33f-d024-1e35-67bcffc41f1edcba
   MODEL      FHEM
   NAME       di_Timer.PoolFilterChlor
   NOTIFYDEV  di_Timer.PoolFilterChlor,global
   NR         12269
   NTFY_ORDER 50-di_Timer.PoolFilterChlor
   STATE      cmd_1
   TYPE       DOIF
   VERSION    24643 2021-06-16 07:26:15
   READINGS:
     2021-07-27 17:11:19   P_Ausschaltzeitpunkt (1*3600) set pl_Switch.SFA on
     2021-07-27 18:28:07   P_hours         2
     2021-07-27 20:28:09   P_mybutton      off
     2021-07-27 20:28:09   cmd             1.2
     2021-07-27 20:28:09   cmd_event       di_Timer.PoolFilterChlor
     2021-07-27 20:28:09   cmd_nr          1
     2021-07-27 20:28:09   cmd_seqnr       2
     2021-07-27 18:28:09   e_di_Timer.PoolFilterChlor_P_mybutton on
     2021-07-27 17:17:38   mode            enabled
     2021-07-27 20:28:09   state           cmd_1
     2021-07-27 20:28:09   wait_timer      no timer
   Regex:
     accu:
     collect:
     cond:
       di_Timer.PoolFilterChlor:
         0:
           P_mybutton ^di_Timer.PoolFilterChlor$:^P_mybutton:
         1:
           P_mybutton ^di_Timer.PoolFilterChlor$:^P_mybutton:
   attr:
     cmdState:
     wait:
       0:
         0
         [$SELF:P_hours]*3600
       1:
         0
     waitdel:
   condition:
     0          ::ReadingValDoIf($hash,'di_Timer.PoolFilterChlor','P_mybutton') eq "on"
     1          ::ReadingValDoIf($hash,'di_Timer.PoolFilterChlor','P_mybutton') eq "off"
   do:
     0:
       0            set ChatBot message @Zoltan_Fono Pool-Timer gestartet für [di_Timer.PoolFilterChlor:P_hours] Stunden, set pl_Switch.SFA on, set pl_Switch.Chlorinator on
       1            set ChatBot message @Zoltan_Fono Pool-Timer aus, set pl_Switch.SFA off, set pl_Switch.Chlorinator off, set di_Timer.PoolFilterChlor P_mybutton off
     1:
       0            set pl_Switch.SFA off, set pl_Switch.Chlorinator off
     2:
   helper:
     DEVFILTER  ^global$|^di_Timer.PoolFilterChlor$
     NOTIFYDEV  global|di_Timer.PoolFilterChlor
     event      P_mybutton: on
     globalinit 1
     last_timer 0
     sleepdevice di_Timer.PoolFilterChlor
     sleepsubtimer -1
     sleeptimer -1
     timerdev   di_Timer.PoolFilterChlor
     timerevent P_mybutton: on
     triggerDev di_Timer.PoolFilterChlor
     timerevents:
       P_mybutton: on
       e_di_Timer.PoolFilterChlor_P_mybutton: on
       cmd_nr: 1
       cmd_seqnr: 1
       cmd: 1.1
       cmd_event: di_Timer.PoolFilterChlor
       cmd_1_1
       wait_timer: 27.07.2021 20:28:09 cmd_1_2 di_Timer.PoolFilterChlor
     timereventsState:
       P_mybutton: on
       e_di_Timer.PoolFilterChlor_P_mybutton: on
       cmd_nr: 1
       cmd_seqnr: 1
       cmd: 1.1
       cmd_event: di_Timer.PoolFilterChlor
       cmd_1_1
       wait_timer: 27.07.2021 20:28:09 cmd_1_2 di_Timer.PoolFilterChlor
     triggerEvents:
       P_mybutton: on
       e_di_Timer.PoolFilterChlor_P_mybutton: on
       cmd_nr: 1
       cmd_seqnr: 1
       cmd: 1.1
       cmd_event: di_Timer.PoolFilterChlor
       cmd_1_1
       wait_timer: 27.07.2021 20:28:09 cmd_1_2 di_Timer.PoolFilterChlor
     triggerEventsState:
       P_mybutton: on
       e_di_Timer.PoolFilterChlor_P_mybutton: on
       cmd_nr: 1
       cmd_seqnr: 1
       cmd: 1.1
       cmd_event: di_Timer.PoolFilterChlor
       cmd_1_1
       wait_timer: 27.07.2021 20:28:09 cmd_1_2 di_Timer.PoolFilterChlor
   internals:
   readings:
     all         di_Timer.PoolFilterChlor:P_mybutton
   trigger:
   uiState:
   uiTable:
Attributes:
   fhem_widget_channels []
   group      Automatismen
   icon       clock
   readingList P_mybutton P_hours
   room       02_Pool
   setList    P_mybutton:on,off P_hours:1,2,3,4,5,6,7,8,9,10
   wait       0,[$SELF:P_hours]*3600:0
   webCmd     P_hours:P_mybutton
   webCmdLabel Stunden:Aktiv


Nun würde ich gerne beim Starten ein userReadings erzeugen in welchem der Abschaltzeitpubkt drin steht. Also aktueller Zeitpunkt + x Stunden.

rabehd

nur so als Anregung
{strftime("%H:%M", localtime([WeckerTablet:aWeckTime]+120))}
WeckerTablet:aWeckTime ist ein Reading in dem eine Unixzeit steht.
Statt 120 Sekunden musst Du Deine x stunden in Sekunden addieren.
Auch funktionierende Lösungen kann man hinterfragen.

Otto123

Hi,

setreading $SELF Abschaltzeitpunkt {(strftime("%H:%M:%S",localtime(time+ReadingsNum($SELF,'P_hours',99)*3600)))}
Quelle https://wiki.fhem.de/wiki/Zeitangaben,_rechnen_mit

Gruß Otto
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz

z0lt1

Danke euch beiden, wieder was dazu gelernt :-)

Beim $SELF in der ReadingsNum musste ich Anführungsstiche rummachen, sonst gab es eine Fehlermeldung.
setreading $SELF P_Abschaltzeitpunkt {(strftime("%H:%M:%S",localtime(time+ReadingsNum("$SELF","P_hours",99)*3600)))}

Otto123

richtig, habe ich nicht dran gedacht: Die Variable wird aufgelöst und dann steht der String in dem Perl Ausdruck, dann erst wird der ReadingsNum() Ausdruck ausgeführt. Damit das funktioniert muss man doppelte verwenden :)

Die DOIF Schreibweise in rabehd seinem Beispiel geht sicher auch - die verwirrt mich aber immer innerhalb eines Perlausdrucks  ::)
Viele Grüße aus Leipzig  ⇉  nächster Stammtisch an der Lindennaundorfer Mühle
RaspberryPi B B+ B2 B3 B3+ ZeroW,HMLAN,HMUART,Homematic,Fritz!Box 7590,WRT3200ACS-OpenWrt,Sonos,VU+,Arduino nano,ESP8266,MQTT,Zigbee,deconz