From d012133bf470cdc97d0075e9342242dba8cc7ebb Mon Sep 17 00:00:00 2001
From: rudolfkoenig
+
diff --git a/fhem/FHEM/10_FS20.pm b/fhem/FHEM/10_FS20.pm
index 76ada4b38..0770515b6 100755
--- a/fhem/FHEM/10_FS20.pm
+++ b/fhem/FHEM/10_FS20.pm
@@ -4,6 +4,7 @@ package main;
use strict;
use warnings;
+use SetExtensions;
my %codes = (
"00" => "off",
@@ -167,7 +168,7 @@ FS20_Set($@)
my $ret = undef;
my $na = int(@a);
- return "no set value specified" if($na < 2 || $na > 3);
+ return "no set value specified" if($na < 2);
return "Readonly value $a[1]" if(defined($readonly{$a[1]}));
if($na > 2 && $a[1] eq "dim") {
@@ -181,16 +182,14 @@ FS20_Set($@)
if(!defined($c)) {
# Model specific set arguments
+ my $list;
if(defined($attr{$name}) && defined($attr{$name}{"model"})) {
my $mt = $models{$attr{$name}{"model"}};
- return "Unknown argument $a[1], choose one of "
- if($mt && $mt eq "sender");
- return "Unknown argument $a[1], choose one of $fs20_simple"
- if($mt && $mt eq "simple");
+ $list = "" if($mt && $mt eq "sender");
+ $list = $fs20_simple if($mt && $mt eq "simple");
}
- return "Unknown argument $a[1], choose one of " .
- join(" ", sort keys %fs20_c2b) .
- " dim:slider,0,6.25,100";
+ $list = join(" ", sort keys %fs20_c2b) if(!defined($list));
+ return SetExtensions($hash, $list, @a);
}
@@ -538,6 +537,8 @@ four2hex($$)
toggle # between off and previous dim val
on-till # Special, see the note
+ The set extensions are also supported.
@@ -705,6 +710,10 @@ EnOcean_A5Cmd($$$)
attr eventMap BI:on B0:off
+ Note: set extensions are supported,
+ if the corresponding eventMap specifies
+ the on and off mappings.
+
set switch1 on
+
Examples:
set lamp on
@@ -546,6 +547,7 @@ four2hex($$)
set lamp on-for-timer 12
+
Notes:
diff --git a/fhem/docs/commandref_frame_DE.html b/fhem/docs/commandref_frame_DE.html
index 3031e4f62..b5fc4d5ad 100644
--- a/fhem/docs/commandref_frame_DE.html
+++ b/fhem/docs/commandref_frame_DE.html
@@ -800,19 +800,66 @@ Zeilen erstreckende Befehle, indem man keine \ am Zeilenende eingeben muss.
+
+ Note: devices with on/off functionality support the set extensions.
-
Class BASIC
+
Class BASIC
Send value (0-255) to this device. The interpretation is device dependent,
e.g. for a SWITCH_BINARY device 0 is off and anything else is on.
Remove the specified list of nodeIds from the assotion group groupId.
diff --git a/fhem/FHEM/SetExtensions.pm b/fhem/FHEM/SetExtensions.pm
new file mode 100644
index 000000000..789139dfb
--- /dev/null
+++ b/fhem/FHEM/SetExtensions.pm
@@ -0,0 +1,152 @@
+##############################################
+# $Id: $
+
+package main;
+use strict;
+use warnings;
+
+sub SetExtensions($$@);
+sub SetExtensionsFn($);
+
+sub
+SetExtensions($$@)
+{
+ my ($hash, $list, $name, $cmd, @a) = @_;
+
+ my %se_list = (
+ "on-for-timer" => 1,
+ "off-for-timer" => 1,
+ "on-till" => 1,
+ "off-till" => 1,
+ "blink" => 2,
+ "intervals" => 0,
+ );
+
+ my $hasOn = ($list =~ m/\bon\b/);
+ my $hasOff = ($list =~ m/\bon\b/);
+ if(!$hasOn || !$hasOff) {
+ my $em = AttrVal($name, "eventMap", undef);
+ if($em) {
+ $hasOn = ($em =~ m/:on\b/) if(!$hasOn);
+ $hasOff = ($em =~ m/:off\b/) if(!$hasOff);
+ }
+ $cmd = ReplaceEventMap($name, $cmd, 1) if($cmd ne "?"); # Fix B0-for-timer
+ }
+ if(!$hasOn || !$hasOff) { # No extension
+ return "Unknown argument $cmd, choose one of $list";
+ }
+
+ if(!defined($se_list{$cmd})) {
+ # Add only "new" commands
+ my @mylist = grep { $list !~ m/\b$_\b/ } keys %se_list;
+ return "Unknown argument $cmd, choose one of $list " .
+ join(" ", @mylist);
+ }
+ if($se_list{$cmd} && $se_list{$cmd} != int(@a)) {
+ return "$cmd requires $se_list{$cmd} parameter";
+ }
+
+ my $cmd1 = ($cmd =~ m/on.*/ ? "on" : "off");
+ my $cmd2 = ($cmd =~ m/on.*/ ? "off" : "on");
+ my $param = $a[0];
+
+ if($cmd eq "on-for-timer" || $cmd eq "off-for-timer") {
+ RemoveInternalTimer("SE $name $cmd");
+ return "$cmd requires a number as argument" if($param !~ m/^\d*\.?\d*$/);
+
+ if($param) {
+ DoSet($name, $cmd1);
+ InternalTimer(gettimeofday()+$param,"SetExtensionsFn","SE $name $cmd",0);
+ }
+
+ } elsif($cmd eq "on-till" || $cmd eq "off-till") {
+ my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($param);
+ return "$cmd: $err" if($err);
+
+ my $at = $name . "_till";
+ CommandDelete(undef, $at) if($defs{$at});
+
+ my @lt = localtime;
+ my $hms_till = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
+ my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
+ if($hms_now ge $hms_till) {
+ Log 4, "$cmd: won't switch as now ($hms_now) is later than $hms_till";
+ return "";
+ }
+ DoSet($name, $cmd1);
+ CommandDefine(undef, "$at at $hms_till set $name $cmd2");
+
+ } elsif($cmd eq "blink") {
+ my $p2 = $a[1];
+ delete($hash->{SE_BLINKPARAM});
+ return "$cmd requires 2 numbers as argument"
+ if($param !~ m/^\d+$/ || $p2 !~ m/^\d*\d?\d*$/);
+
+ if($param) {
+ DoSet($name, "on-for-timer", $p2);
+ $param--;
+ if($param) {
+ $hash->{SE_BLINKPARAM} = "$param $p2";
+ InternalTimer(gettimeofday()+2*$p2,"SetExtensionsFn","SE $name $cmd",0);
+ }
+ }
+
+ } elsif($cmd eq "intervals") {
+ my $at0 = "${name}_till";
+ my $at1 = "${name}_intervalFrom",
+ my $at2 = "${name}_intervalNext";
+ CommandDelete(undef, $at0) if($defs{$at0});
+ CommandDelete(undef, $at1) if($defs{$at1});
+ CommandDelete(undef, $at2) if($defs{$at2});
+
+ my $intSpec = shift(@a);
+ if($intSpec) {
+ my ($from, $till) = split("-", $intSpec);
+
+ my ($err, $hr, $min, $sec, $fn) = GetTimeSpec($from);
+ return "$cmd: $err" if($err);
+ my @lt = localtime;
+ my $hms_from = sprintf("%02d:%02d:%02d", $hr, $min, $sec);
+ my $hms_now = sprintf("%02d:%02d:%02d", $lt[2], $lt[1], $lt[0]);
+
+ if($hms_from le $hms_now) { # By slight delays at will schedule tomorrow.
+ SetExtensions($hash, $list, $name, "on-till", $till);
+
+ } else {
+ CommandDefine(undef, "$at1 at $from set $name on-till $till");
+
+ }
+
+ if(@a) {
+ my $rest = join(" ", @a);
+ my ($from, $till) = split("-", shift @a);
+ CommandDefine(undef, "$at2 at $from set $name intervals $rest");
+ }
+ }
+
+ }
+
+ return undef;
+}
+
+sub
+SetExtensionsFn($)
+{
+ my (undef, $name, $cmd) = split(" ", shift, 3);
+ return if(!defined($defs{$name}));
+
+
+ if($cmd eq "on-for-timer") {
+ DoSet($name, "off");
+
+ } elsif($cmd eq "off-for-timer") {
+ DoSet($name, "on");
+
+ } elsif($cmd eq "blink") {
+ DoSet($name, "blink", split(" ", $defs{$name}{SE_BLINKPARAM}, 2));
+
+ }
+
+}
+
+1;
diff --git a/fhem/docs/commandref_frame.html b/fhem/docs/commandref_frame.html
index 81bac499a..47b91c5b0 100644
--- a/fhem/docs/commandref_frame.html
+++ b/fhem/docs/commandref_frame.html
@@ -782,7 +782,45 @@ A line ending with \ will be concatenated with the next one, so long lines
Each device has different set parameters, see the corresponding device
section for details.
+
+
+ Some modules support a common list of set extensions, and point in
+ their documentation to this section. If the module itself implements one of
+ the following commands, then the module-implementation takes precedence.
+
+
+ Examples:
+
+ Issue the on command for the device, and after <seconds> the off
+ command. For issuing the off command an internal timer will be
+ scheduled, which is deleted upon a restart. To delete this internal
+ timer without restart specify 0 as argument.
+ see on-for-timer above.
+ Issue the on command for the device, and create an at definition with
+ <timedet> (in the form HH:MM[:SS]) to set it off. This definition
+ is visible, and its name is deviceName+"_till". To cancel the scheduled
+ off, delete the at definition.
+ see on-till above.
+ set the device on for <blink-period> then off for
+ <blink-period> and repeat this <number> times.
+ To stop blinking specify "0 0" as argument.
+
+ set switch on-for-timer 12.5
+
+ set switch on-till {sunset()}
+ set switch blink 3 1
+ set switch intervals 08:00-12:00 13:00-18:00
+
set <devspec> <type-specific>
set <name> ?
+ set switch on-for-timer 12.5
+ set switch on-till {sunset()}
+ set switch blink 3 1
+ set switch intervals 08:00-12:00 13:00-18:00
+
+