From 41665439f85b15309df61cc0207d94e36cb06436 Mon Sep 17 00:00:00 2001
From: rudolfkoenig <>
Date: Sun, 3 Sep 2017 15:20:42 +0000
Subject: [PATCH] 91_sequence: add delay and omit name options (by Petr, Forum
#75925)
git-svn-id: https://svn.fhem.de/fhem/trunk@14996 2b470e98-0d58-463d-a4d8-8e2adae1ed80
---
fhem/CHANGED | 1 +
fhem/FHEM/91_sequence.pm | 70 +++++++++++++++++++++++++++++++++++-----
2 files changed, 63 insertions(+), 8 deletions(-)
diff --git a/fhem/CHANGED b/fhem/CHANGED
index a30941f8f..9806481d0 100644
--- a/fhem/CHANGED
+++ b/fhem/CHANGED
@@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - feature: 91_sequence: add delay and omit name options (Forum #75925)
- bugfix: 74_AMADDevice: fix a lot of Bugs
- feature: 93_Log2Syslog: V3.1.0, get certinfo added
- bugfix: 73_AMADCommBridge: fix doubble set Command at Bridge
diff --git a/fhem/FHEM/91_sequence.pm b/fhem/FHEM/91_sequence.pm
index d97dc0252..ce72662c7 100644
--- a/fhem/FHEM/91_sequence.pm
+++ b/fhem/FHEM/91_sequence.pm
@@ -40,14 +40,15 @@ sequence_Define($$)
my $to = $def[$i+1];
eval { "Hallo" =~ m/^$re$/ };
return "Bad regexp 1: $@" if($@);
- return "Bad timeout spec $to"
- if(defined($to) && $to !~ m/^\d*.?\d$/);
+ return "Bad timeout spec $to" # timeout or delay:timeout
+ if (defined($to) && $to !~ m/^(\d+(\.\d+)?:)?\d+(\.\d+)?$/);
}
$hash->{RE} = $def[0];
$hash->{IDX} = 0;
$hash->{MAX} = int(@def);
$hash->{STATE} = "active";
+ $hash->{TS} = 0;
return undef;
}
@@ -70,6 +71,12 @@ sequence_Notify($$)
next if($n !~ m/^$re$/ && "$n:$s" !~ m/^$re$/);
RemoveInternalTimer($ln);
+
+ if($hash->{TS} > gettimeofday()) { # the delay stuff
+ sequence_Trigger($ln, "abort");
+ last;
+ }
+
my $idx = $hash->{IDX} + 2;
Log3 $ln, 5, "sequence $ln matched $idx";
my @d = split("[ \t]+", $hash->{DEF});
@@ -86,33 +93,37 @@ sequence_Notify($$)
setReadingsVal($hash, "state", "active", TimeNow());
DoTrigger($ln, $tt);
$idx = 0;
+ $hash->{TS} = 0;
} else {
- $hash->{RE} = $d[$idx];
- my $nt = gettimeofday() + $d[$idx-1];
+ my ($delay, $nt) = split(':', $d[$idx - 1]);
+ $hash->{TS} = gettimeofday() + $delay if (defined($nt) && $delay > 0);
+ $nt += gettimeofday() + $delay;
InternalTimer($nt, "sequence_Trigger", $ln, 0);
}
$hash->{IDX} = $idx;
- $hash->{RE} = $d[$idx];
+ $hash->{RE} = substr($d[$idx], 0, 1) eq ':' ? $n . $d[$idx] : $d[$idx];
last;
}
return "";
}
sub
-sequence_Trigger($)
+sequence_Trigger($$)
{
- my ($ln) = @_;
+ my ($ln, $arg) = @_;
my $hash = $defs{$ln};
my @d = split("[ \t]+", $hash->{DEF});
$hash->{RE} = $d[0];
my $idx = $hash->{IDX}/2;
$hash->{IDX} = 0;
+ $hash->{TS} = 0;
my $tt = "partial_$idx";
- Log3 $ln, 5, "sequence $ln timeout on $idx ($tt)";
+ $arg = "timeout" if(!$arg);
+ Log3 $ln, 5, "sequence $ln $arg on $idx ($tt)";
$tt .= $hash->{EVENTS} if(AttrVal($ln, "reportEvents", undef));
delete($hash->{EVENTS});
@@ -158,6 +169,28 @@ sequence_Undef($$)
define lampon notify lampseq:trigger set lamp on
+
+ Subsequent patterns can be specified without device name as
+ :<re2>
. This will reuse the device name which triggered
+ the previous sequence step:
+
+
+ define lampseq sequence Btn.:on 0.5 :off
+
+ <delay>:<timeout>
,
+ where "delay" sets time during which the next event shall not be received,
+ otherwise the sequence will be aborted. This can be used to capture press
+ and hold of a button. Example:
+ define lampseq sequence Btn1:on 2:3 Btn1:off
+
+
+ define lampseq sequence Btn.:on 0.5 :off
+
+ <delay>:<timeout>
spezifiziert
+ werden, dabei setzt delay die Zeit, wo kein passendes Event empfangen
+ werden darf, ansonsten wird sequence abgebrochen. Das kann verwendet
+ werden, um "press and hold" auszuwerten. Folgendes
+
+ define lampseq sequence Btn1:on 2:3 :off
+
+