FHEM Forum

FHEM => Automatisierung => DOIF => Thema gestartet von: Stelaku am 01 April 2022, 22:43:43

Titel: [gelöst]DOIF perl del_Exec auf mehrere laufene timer
Beitrag von: Stelaku am 01 April 2022, 22:43:43
Hallo alle zusammen

Ich bin gerade ein wenig am herumspielen und baue meine FHEM DOIF nach und nach auf Perl mode um.
Ich stoße dabei erwartungsgemäß immer wieder auf Hürden, die ich aber bis jetzt irgendwie lösen konnte.
Aber jetzt frage ich mich, ob das Löschen laufender Timer nicht einfacher geht.
In meinen DOIF lasse ich über eine sub 12 Timer starten die alle 10 Sekunden eine Aktion auslösen.
Das funktioniert auch sehr gut, wenn ich jetzt aber in der laufenden Timer Zeit diese Aktionen verhindern möchte.
Also alle Timer löschen will
geht das ja mit.
del_Exec(<timername>)
Meine laufenden timer haben allle am Anfang des Namens TestRollo stehen. Da habe ich mir gedacht es könnte mit einen .*
am ende funktionieren ungefähr so.
del_Exec("TestRollo.*")
funktioniert leider nicht.
Ich habe es jetzt erstmal so gelöst das ich alle laufenden timer einzelt mit del_Exec lösche.
hier ein list von meinem DOIF
Internals:
   DEF        init {$_Pausen=ReadingsNum("$SELF","Pausen",0);$_timer=0}
Pause {([Zentrale_Rollo:"^Pausen:.*.sek$"]);
$_Pausen=ReadingsNum("$SELF","Pausen",0)
}
subs {
sub rauf {
my ($Rollo,$Befehl)=@_;;

  {set_Exec($Rollo,$_timer,"fhem('set $Rollo $Befehl')")
  ;$_timer = $_timer + $_Pausen;
  }
}
}
Rauf{
if ([$SELF:"^fahrt_hoch$"]){
set_Reading("Status","fahrt_hoch",1);
rauf ("TestRollo_Bad","cmd_1");
rauf ("TestRollo_Esszimmer_links","cmd_1");
rauf ("TestRollo_Esszimmer_rechts","cmd_1");
rauf ("TestRollo_Gast","cmd_1");
rauf ("TestRollo_Keller","cmd_1");
rauf ("TestRollo_Kueche","cmd_1");
rauf ("TestRollo_Schlafzimmer","cmd_1");
rauf ("TestRollo_Silke","cmd_1");
rauf ("TestRollo_Stephan","cmd_1");
rauf ("TestRollo_Stube_links","cmd_1");
rauf ("TestRollo_Stube_rechts","cmd_1");
set_Exec("ICON_Rauf",$_timer,'set_Reading("Status","hoch_stop",1)');
$_timer = 0;
}

}
Stop_hoch{
if([$SELF:"^hoch_stop$"]){
$_timer = 0;
del_Exec("TestRollo_Bad");
del_Exec("TestRollo_Esszimmer_links");
del_Exec("TestRollo_Esszimmer_rechts");
del_Exec("TestRollo_Gast");
del_Exec("TestRollo_Keller");
del_Exec("TestRollo_Kueche");
del_Exec("TestRollo_Schlafzimmer");
del_Exec("TestRollo_Silke");
del_Exec("TestRollo_Stephan");
del_Exec("TestRollo_Stube_links");
del_Exec("TestRollo_Stube_rechts");
del_Exec("ICON_Rauf");
set_Reading("Status","hoch_stop",1);
}
}

   FUUID      6245c5cb-f33f-134a-c4fb-5e47075dd804b7fe
   MODEL      Perl
   NAME       Zentrale_Rollo
   NOTIFYDEV  global,Zentrale_Rollo
   NR         451
   NTFY_ORDER 50-Zentrale_Rollo
   STATE      3:fahrt_hoch
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1:fahrt_hoch
<br>
2:fahrt_hoch
<br>

   TYPE       DOIF
   VERSION    24905 2021-09-01 18:35:54
   OLDREADINGS:
   READINGS:
     2022-04-01 18:39:47   Pausen          10 sek
     2022-04-01 22:25:47   Status          fahrt_hoch
     2022-04-01 17:37:18   TestRollo1      cmd_1
     2022-04-01 17:37:21   TestRollo2      cmd_2
     2022-04-01 17:37:24   TestRollo3      cmd_3
     2022-04-01 22:25:47   block_Pause     executed
     2022-04-01 22:25:47   block_Rauf      executed
     2022-04-01 22:25:47   block_Stop_hoch executed
     2022-04-01 22:25:32   block_init      executed
     2022-04-01 22:25:47   e_Zentrale_Rollo_events fahrt_hoch
     2022-04-01 22:25:32   mode            enabled
     2022-04-01 22:25:32   state           initialized
     2022-04-01 22:25:47   timer_ICON_Rauf 01.04.2022 22:27:37
     2022-04-01 22:25:47   timer_TestRollo_Esszimmer_links 01.04.2022 22:25:57
     2022-04-01 22:25:47   timer_TestRollo_Esszimmer_rechts 01.04.2022 22:26:07
     2022-04-01 22:25:47   timer_TestRollo_Gast 01.04.2022 22:26:17
     2022-04-01 22:25:47   timer_TestRollo_Keller 01.04.2022 22:26:27
     2022-04-01 22:25:47   timer_TestRollo_Kueche 01.04.2022 22:26:37
     2022-04-01 22:25:47   timer_TestRollo_Schlafzimmer 01.04.2022 22:26:47
     2022-04-01 22:25:47   timer_TestRollo_Silke 01.04.2022 22:26:57
     2022-04-01 22:25:47   timer_TestRollo_Stephan 01.04.2022 22:27:07
     2022-04-01 22:25:47   timer_TestRollo_Stube_links 01.04.2022 22:27:17
     2022-04-01 22:25:47   timer_TestRollo_Stube_rechts 01.04.2022 22:27:27
   Regex:
     accu:
     collect:
     cond:
       Zentrale_Rollo:
         0:
         1:
           &STATE     ^Zentrale_Rollo$
         2:
           &STATE     ^Zentrale_Rollo$
         3:
           &STATE     ^Zentrale_Rollo$
   attr:
     cmdState:
   condition:
     0          $hash->{var}{Pausen}=ReadingsNum("Zentrale_Rollo","Pausen",0);$hash->{var}{timer}=0
     1          (::EventDoIf('Zentrale_Rollo',$hash,'^Pausen:.*.sek$',1));
$hash->{var}{Pausen}=ReadingsNum("Zentrale_Rollo","Pausen",0)

     2         
if (::EventDoIf('Zentrale_Rollo',$hash,'^fahrt_hoch$',1)){
set_Reading("Status","fahrt_hoch",1);
rauf ("TestRollo_Bad","cmd_1");
rauf ("TestRollo_Esszimmer_links","cmd_1");
rauf ("TestRollo_Esszimmer_rechts","cmd_1");
rauf ("TestRollo_Gast","cmd_1");
rauf ("TestRollo_Keller","cmd_1");
rauf ("TestRollo_Kueche","cmd_1");
rauf ("TestRollo_Schlafzimmer","cmd_1");
rauf ("TestRollo_Silke","cmd_1");
rauf ("TestRollo_Stephan","cmd_1");
rauf ("TestRollo_Stube_links","cmd_1");
rauf ("TestRollo_Stube_rechts","cmd_1");
set_Exec("ICON_Rauf",$hash->{var}{timer},'set_Reading("Status","hoch_stop",1)');
$hash->{var}{timer} = 0;
}


     3         
if(::EventDoIf('Zentrale_Rollo',$hash,'^hoch_stop$',1)){
$hash->{var}{timer} = 0;
del_Exec("TestRollo_Bad");
del_Exec("TestRollo_Esszimmer_links");
del_Exec("TestRollo_Esszimmer_rechts");
del_Exec("TestRollo_Gast");
del_Exec("TestRollo_Keller");
del_Exec("TestRollo_Kueche");
del_Exec("TestRollo_Schlafzimmer");
del_Exec("TestRollo_Silke");
del_Exec("TestRollo_Stephan");
del_Exec("TestRollo_Stube_links");
del_Exec("TestRollo_Stube_rechts");
del_Exec("ICON_Rauf");
set_Reading("Status","hoch_stop",1);
}

   helper:
     DEVFILTER  ^global$|^Zentrale_Rollo$
     NOTIFYDEV  global|Zentrale_Rollo
     event      fahrt_hoch
     globalinit 1
     last_timer 0
     sleeptimer -1
     triggerDev Zentrale_Rollo
     triggerEvents:
       fahrt_hoch
       e_Zentrale_Rollo_events: fahrt_hoch
       block_Pause: executed
       Status: fahrt_hoch
       timer_TestRollo_Esszimmer_links: 01.04.2022 22:25:57
       timer_TestRollo_Esszimmer_rechts: 01.04.2022 22:26:07
       timer_TestRollo_Gast: 01.04.2022 22:26:17
       timer_TestRollo_Keller: 01.04.2022 22:26:27
       timer_TestRollo_Kueche: 01.04.2022 22:26:37
       timer_TestRollo_Schlafzimmer: 01.04.2022 22:26:47
       timer_TestRollo_Silke: 01.04.2022 22:26:57
       timer_TestRollo_Stephan: 01.04.2022 22:27:07
       timer_TestRollo_Stube_links: 01.04.2022 22:27:17
       timer_TestRollo_Stube_rechts: 01.04.2022 22:27:27
       timer_ICON_Rauf: 01.04.2022 22:27:37
       block_Rauf: executed
       block_Stop_hoch: executed
     triggerEventsState:
       fahrt_hoch
       e_Zentrale_Rollo_events: fahrt_hoch
       block_Pause: executed
       Status: fahrt_hoch
       timer_TestRollo_Esszimmer_links: 01.04.2022 22:25:57
       timer_TestRollo_Esszimmer_rechts: 01.04.2022 22:26:07
       timer_TestRollo_Gast: 01.04.2022 22:26:17
       timer_TestRollo_Keller: 01.04.2022 22:26:27
       timer_TestRollo_Kueche: 01.04.2022 22:26:37
       timer_TestRollo_Schlafzimmer: 01.04.2022 22:26:47
       timer_TestRollo_Silke: 01.04.2022 22:26:57
       timer_TestRollo_Stephan: 01.04.2022 22:27:07
       timer_TestRollo_Stube_links: 01.04.2022 22:27:17
       timer_TestRollo_Stube_rechts: 01.04.2022 22:27:27
       timer_ICON_Rauf: 01.04.2022 22:27:37
       block_Rauf: executed
       block_Stop_hoch: executed
   internals:
   perlblock:
     0          init
     1          Pause
     2          Rauf
     3          Stop_hoch
     init       0
   ptimer:
     ICON_Rauf:
       count      0
       name       ICON_Rauf
       sec        110
       subname    set_Reading("Status","hoch_stop",1)
       time       1648844857.09561
       hash:
     TestRollo_Bad:
       count      0
       name       TestRollo_Bad
       sec        0
       subname    fhem('set TestRollo_Bad cmd_1')
       time       1648844747.08328
       hash:
     TestRollo_Esszimmer_links:
       count      0
       name       TestRollo_Esszimmer_links
       sec        10
       subname    fhem('set TestRollo_Esszimmer_links cmd_1')
       time       1648844757.08406
       hash:
     TestRollo_Esszimmer_rechts:
       count      0
       name       TestRollo_Esszimmer_rechts
       sec        20
       subname    fhem('set TestRollo_Esszimmer_rechts cmd_1')
       time       1648844767.08527
       hash:
     TestRollo_Gast:
       count      0
       name       TestRollo_Gast
       sec        30
       subname    fhem('set TestRollo_Gast cmd_1')
       time       1648844777.08639
       hash:
     TestRollo_Keller:
       count      0
       name       TestRollo_Keller
       sec        40
       subname    fhem('set TestRollo_Keller cmd_1')
       time       1648844787.0875
       hash:
     TestRollo_Kueche:
       count      0
       name       TestRollo_Kueche
       sec        50
       subname    fhem('set TestRollo_Kueche cmd_1')
       time       1648844797.08861
       hash:
     TestRollo_Schlafzimmer:
       count      0
       name       TestRollo_Schlafzimmer
       sec        60
       subname    fhem('set TestRollo_Schlafzimmer cmd_1')
       time       1648844807.08974
       hash:
     TestRollo_Silke:
       count      0
       name       TestRollo_Silke
       sec        70
       subname    fhem('set TestRollo_Silke cmd_1')
       time       1648844817.09086
       hash:
     TestRollo_Stephan:
       count      0
       name       TestRollo_Stephan
       sec        80
       subname    fhem('set TestRollo_Stephan cmd_1')
       time       1648844827.09201
       hash:
     TestRollo_Stube_links:
       count      0
       name       TestRollo_Stube_links
       sec        90
       subname    fhem('set TestRollo_Stube_links cmd_1')
       time       1648844837.09315
       hash:
     TestRollo_Stube_rechts:
       count      0
       name       TestRollo_Stube_rechts
       sec        100
       subname    fhem('set TestRollo_Stube_rechts cmd_1')
       time       1648844847.09442
       hash:
   readings:
   trigger:
     all         Zentrale_Rollo
   uiState:
   uiTable:
   var:
     Pausen     10
     timer      0
Attributes:
   devStateIcon 1..*stop:control_arrow_up:fahrt_hoch
1.fahrt_runter:control_arrow_up:runter_stop
1.fahrt_hoch:control_arrow_up@red:hoch_stop

2..*stop:control_arrow_down:fahrt_runter
2.fahrt_runter:control_arrow_down@red:runter_stop
2.fahrt_hoch:control_arrow_down:hoch_stop


3.runter_stop:fts_shutter_100
3.hoch_stop:fts_shutter_10
3.fahrt_runter:fts_shutter_down@red
3.fahrt_hoch:fts_shutter_up@red
   devStateStyle style=text-align:right
   group      Zentrale
   readingList Status Pausen
   room       Automatik,Rollo,TestRollo
   setList    Status:
Pausen:0&nbsp;sek,1&nbsp;sek,2&nbsp;sek,3&nbsp;sek,4&nbsp;sek,5&nbsp;sek,6&nbsp;sek,7&nbsp;sek,8&nbsp;sek,9&nbsp;sek,10&nbsp;sek
   sortby     1
   stateFormat 3:Status
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
1:Status
<br>
2:Status
<br>

   webCmd     Pausen

vieleicht geht das ja noch etwas kürzer.

Viele grüße

Stephan
Titel: Antw:DOIF perl del_Exec auf mehrere laufene timer
Beitrag von: Damian am 01 April 2022, 23:01:15
Du kannst über eine for-Schleife deine Timer löschen, die Timernamen musst du in einer Liste dennoch angeben.
Titel: Antw:DOIF perl del_Exec auf mehrere laufene timer
Beitrag von: Stelaku am 02 April 2022, 07:03:09
vielen dank für den Tip.
Da werde ich mich mal die nächsten Tage mit beschäftigen.
gruß
Stephan
Titel: Antw:DOIF perl del_Exec auf mehrere laufene timer
Beitrag von: Stelaku am 02 April 2022, 16:57:09
Hallo Damian

Habs hinbekommen funktioniert klasse mit einer foreach Schleife

Stop_hoch{
if([$SELF:"^hoch_stop$"]){
$_timer = 0;
my @TIMER = ("TestRollo_Bad",
      "TestRollo_Esszimmer_links",
      "TestRollo_Esszimmer_rechts",
          "TestRollo_Gast",
      "TestRollo_Keller",
      "TestRollo_Kueche",
      "TestRollo_Schlafzimmer",
      "TestRollo_Silke",
      "TestRollo_Stephan",
      "TestRollo_Stube_links",
      "TestRollo_Stube_rechts",
      "ICON_Rauf");
foreach my $timerreset ( @TIMER ) {
del_Exec("$timerreset")};
set_Reading("Status","hoch_stop",1);
}
}


Nochmal vielen dank für Deinen Tip.

Gruß

Stephan