From 461144761b1ca09be637f43ea3d7e41ab858c972 Mon Sep 17 00:00:00 2001 From: dirkh Date: Fri, 19 Oct 2007 09:29:00 +0000 Subject: [PATCH] - Softwarebuffer for FHT devices with queuing unsent commands and repeating commands by transmission failure - FHT low temperatur warning and setting for lowtemp-offset - Change naming for state into warnings git-svn-id: https://svn.fhem.de/fhem/trunk@101 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/CHANGED | 3 + fhem/FHEM/00_FHZ.pm | 23 +- fhem/FHEM/11_FHT.pm | 425 ++++- fhem/HISTORY | 10 + fhem/docs/commandref.html | 3262 +++++++++++++++++++------------------ fhem/docs/fhem.html | 516 +++--- fhem/fhem.pl | 52 +- 7 files changed, 2360 insertions(+), 1931 deletions(-) diff --git a/fhem/CHANGED b/fhem/CHANGED index 0fdd0c05d..f4a776db3 100644 --- a/fhem/CHANGED +++ b/fhem/CHANGED @@ -348,3 +348,6 @@ - feature: webpgm2 output reformatted - feature: webpgm2 can display multiple plots. - feature: FHT lime-protection code discovered by Dirk (7.10) + - feature: Softwarebuffer for FHT devices with queuing unsent commands and repeating commands by transmission failure (Dirk 17.10) + - feature: FHT low temperatur warning and setting for lowtemp-offset (Dirk 17.10) + - change: Change naming for state into warnings (Dirk 17.10) \ No newline at end of file diff --git a/fhem/FHEM/00_FHZ.pm b/fhem/FHEM/00_FHZ.pm index d6a40155b..984f2c4ee 100755 --- a/fhem/FHEM/00_FHZ.pm +++ b/fhem/FHEM/00_FHZ.pm @@ -68,7 +68,7 @@ FHZ_Initialize($) $hash->{SetFn} = "FHZ_Set"; $hash->{StateFn} = "FHZ_SetState"; $hash->{ParseFn} = "FHZ_Parse"; - $hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 filtertimeout repeater:1,0 showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6"; + $hash->{AttrList}= "do_not_notify:1,0 dummy:1,0 filtertimeout repeater:1,0 showtime:1,0 model:fhz1000,fhz1300 loglevel:0,1,2,3,4,5,6 softbuffer softrepeat softmaxretry"; } ##################################### @@ -160,6 +160,24 @@ FHZ_Get($@) return "$a[0] $a[1] => $v"; } +##################################### +# get the FHZ hardwarebuffer without logentry +# and as decimal value +sub getFhzBuffer() +{ + my $msg = "Timeout"; + + while (index($msg,"Timeout") >= 0) { # try getting FHZ buffer until no Timeout occurs + FHZ_Write($defs{FHZ}, "04", "c90185") if(!IsDummy("FHZ")); + $msg = FHZ_ReadAnswer($defs{FHZ}, "fhtbuf"); + } + + my $v = substr($msg, 16, 2); + $v = hex $v; + + return "$v"; +} + ##################################### sub FHZ_SetState($$$$) @@ -346,7 +364,8 @@ FHZ_ReadAnswer($$) my $buf = $hash->{PortObj}->input(); - Log 5, "FHZ/RAW: " . unpack('H*',$buf); +# Log 5, "FHZ/RAW: " . unpack('H*',$buf); +Log 4, "FHZ/RAW: " . unpack('H*',$buf); $mfhzdata .= $buf; next if(length($mfhzdata) < 2); diff --git a/fhem/FHEM/11_FHT.pm b/fhem/FHEM/11_FHT.pm index dfcdb5abb..2ae01e246 100755 --- a/fhem/FHEM/11_FHT.pm +++ b/fhem/FHEM/11_FHT.pm @@ -50,7 +50,8 @@ my %codes = ( "XX0069" => "measured-temp", # sum of next. two, never "really" sent "420069" => "measured-low", "430069" => "measured-high", - "440069" => "state", + "440069" => "warnings", + "450069" => "manu-temp", # Manuelle Temperatur keine ahnung was das bewirkt "600069" => "year", "610069" => "month", "620069" => "day", @@ -59,10 +60,9 @@ my %codes = ( "650069" => "init", "820069" => "day-temp", "840069" => "night-temp", - "850069" => "unknown_85", + "850069" => "lowtemp-offset", # Alarm-Temp.-Differenz "8a0069" => "windowopen-temp", "00002a" => "lime-protection", - "0000aa" => "code_0000aa", "0000ba" => "code_0000ba", "430079" => "code_430079", @@ -86,7 +86,7 @@ my %cantset = ( "measured-temp" => 1, "measured-high" => 1, "measured-low" => 1, - "state" => 1, + "warnings" => 1, "init" => 1, "lime-protection"=>1, @@ -104,12 +104,25 @@ my %nosetarg = ( "refreshvalues" => 1, ); +my %priority = ( + "desired-temp" => 1, + "mode" => 2, + "refreshvalues" => 3, + "holiday1" => 4, + "holiday2" => 5, + "day-temp" => 6, + "night-temp" => 7, +); + my %c2m = (0 => "auto", 1 => "manual", 2 => "holiday", 3 => "holiday_short"); -my %m2c; # Reverse c2m -my %c2b; # command->button hash (reverse of codes) -my %c2bset; # Setteable values +my %m2c; # Reverse c2m +my %c2b; # command->button hash (reverse of codes) +my %c2bset; # Setteable values my %defptr; +my $timerCheckBufferIsRunning = 0; # set to 1 if the timer is running +my $minFhzHardwareBufferSpace = 10; # min. bytes free in hardware buffer before sending commands +my $fhzHardwareBufferSpace = 0; # actual hardware buffer space in fhz ##################################### sub @@ -143,29 +156,115 @@ FHT_Initialize($) $hash->{AttrList} = "do_not_notify:0,1 model;fht80b dummy:0,1 showtime:0,1 loglevel:0,1,2,3,4,5,6"; } - -##################################### -sub -FHT_Set($@) +# Parse the incomming commands and send them via sendCommand to the FHZ +# or via toSendbuffer in the Softwarebuffer (queue) +# +sub FHT_Set($@) { - my ($hash, @a) = @_; - my $ret = undef; + my ($hash, @a) = @_; + my $ret = undef; + my $arg = "020183" . $hash->{CODE} . $c2bset{$a[1]}; + my $val = $a[2]; return "\"set $a[0]\" needs two parameters" if(@a < 2); return "Unknown argument $a[1], choose one of " . join(" ", sort {$c2bset{$a} cmp $c2bset{$b} } keys %c2bset) if(!defined($c2bset{$a[1]})); return "\"set $a[0]\" needs two parameters" - if(@a != 3 && !(@a == 2 && $nosetarg{$a[1]})); - - Log GetLogLevel($a[0],2), "FHT set " . join(" ", @a); - - my $arg = "020183" . $hash->{CODE} . $c2bset{$a[1]}; + if(@a != 3 && !(@a == 2 && $nosetarg{$a[1]})); if($a[1] eq "refreshvalues") { + + } elsif ($a[1] =~ m/-temp/) { + return "Invalid temperature, use NN.N" if($val !~ m/^\d*\.?\d+$/); + # additional check for temperature + return "Invalid temperature, must between 5.5 and 30.5" if($val < 5.5 || $val > 30.5); + + my $a = int($val*2); + $arg .= sprintf("%02x", $a); + $ret = sprintf("Rounded temperature to %.1f", $a/2) if($a/2 != $val); + $val = sprintf("%.1f", $a/2) if($a/2 != $val); + $val = sprintf("%.1f", $val); + + } elsif($a[1] =~ m/-from/ || $a[1] =~ m/-to/) { + return "Invalid timeformat, use HH:MM" if($val !~ m/^([0-2]\d):([0-5]\d)/); + my $a = ($1*6) + ($2/10); + $arg .= sprintf("%02x", $a); + + my $nt = sprintf("%02d:%02d", $1, ($2/10)*10); + $val = $nt if($nt ne $val); + $ret = "Rounded time to $nt" if($nt ne $val); + + } elsif($a[1] eq "mode") { + return "Invalid mode, use one of " . join(" ", sort keys %m2c) + if(!defined($m2c{$val})); + $arg .= sprintf("%02x", $m2c{$val}); + + } elsif ($a[1] eq "lowtemp-offset") { + return "Invalid lowtemperature-offset, use N" if($val !~ m/^\d*\.?\d+$/); + + # additional check for temperature + return "Invalid lowtemperature-offset, must between 1 and 5" if($val < 1 || $val > 5); + + my $a = int($val); + $arg .= sprintf("%02x", $a); + $ret = sprintf("Rounded temperature to %d.0", $a) if($a != $val); + $val = "$a.0"; + + } else { # Holiday1, Holiday2 + $arg .= sprintf("%02x", $val); + } + + my $dev = $hash->{CODE}; + my $def = $defptr{$dev}; + my $name = $def->{NAME}; + my $type = $a[1]; + my $sbCount = keys(%{$def->{SENDBUFFER}}); # Count of sendbuffer + + # get firsttime hardware buffer of FHZ if $fhzHardwareBufferSpace not set + $fhzHardwareBufferSpace = getFhzBuffer () if ($fhzHardwareBufferSpace == 0); + + # set default values for config value attr FHZ softbuffer + $attr{FHZ}{softbuffer} = 1 if (!defined($attr{FHZ}{softbuffer})); + + $val = "" if (!defined($val)); + + if ( ($sbCount == 0 && $fhzHardwareBufferSpace >= $minFhzHardwareBufferSpace) || $attr{FHZ}{softbuffer} == 0) { + sendCommand ($hash, $arg, $name, $type, $val); # send command direct to FHZ + } else { + + Log GetLogLevel($name,2), "FHT set $name $type $val (Enqueue to buffer)" if ($fhzHardwareBufferSpace >= $minFhzHardwareBufferSpace); + + Log GetLogLevel($name,2), "Can't send command set $name $type $val. " . + "No space left in FHZ hardware buffer." if($fhzHardwareBufferSpace < $minFhzHardwareBufferSpace); + + } + + # only if softbuffer not disabled via config + if ($attr{FHZ}{softbuffer} == 1) { + toSendbuffer ($hash, $type, $val, $arg, "", 0); # send command also to buffer + + if ($timerCheckBufferIsRunning == 0 && $init_done) { + $timerCheckBufferIsRunning = 1; # set $timerCheckBufferIsRunning to 1 to remeber a timer is running + InternalTimer(gettimeofday()+70, "timerCheckBuffer", $hash); # start internal Timer to periodical check the buffer + } + } + + return $ret; +} + + +# Send command to FHZ +# +sub sendCommand ($$$$$) +{ + + my ($hash, $arg, $name, $type, $val) = @_; + + if($type eq "refreshvalues") { # This is special. Without the sleep the next FHT won't send its data - if(!IsDummy($a[0])) { + if(!IsDummy($name)) { my $havefhz; $havefhz = 1 if($hash->{IODev} && defined($hash->{IODev}->{FD})); @@ -174,36 +273,40 @@ FHT_Set($@) IOWrite($hash, "04", "c90185"); # Check the fht buffer sleep(1) if($havefhz); } - return $ret; - - } elsif($a[1] =~ m/-temp/) { - return "Invalid temperature, use NN.N" if($a[2] !~ m/^\d*\.?\d+$/); - my $a = int($a[2]*2); - $arg .= sprintf("%02x", $a); - $ret = "Rounded temperature to " . $a/2 if($a/2 != $a[2]); - - } elsif($a[1] =~ m/-from/ || $a[1] =~ m/-to/) { - return "Invalid timeformat, use HH:MM" if($a[2] !~ m/^([0-2]\d):([0-5]\d)/); - my $a = ($1*6) + ($2/10); - $arg .= sprintf("%02x", $a); - - my $nt = sprintf("%02d:%02d", $1, ($2/10)*10); - $ret = "Rounded time to $nt" if($nt ne $a[2]); - - } elsif($a[1] eq "mode") { - return "Invalid mode, use one of " . join(" ", sort keys %m2c) - if(!defined($m2c{$a[2]})); - $arg .= sprintf("%02x", $m2c{$a[2]}); - - } else { # Holiday1, Holiday2 - $arg .= sprintf("%02x", $a[2]); - + } else { + IOWrite($hash, "04", $arg) if(!IsDummy($name)); } - IOWrite($hash, "04", $arg) if(!IsDummy($a[0])); - return $ret; + Log GetLogLevel($name,2), "FHT set $name $type $val"; + + # decrease $fhzHardwareBufferSpace for each command sending to the FHZ + $fhzHardwareBufferSpace = $fhzHardwareBufferSpace -5 if(!IsDummy($name)); } + +sub resendCommand ($) +{ + + my ($buffer) = @_; + my $hash = $buffer->{HASH}; + my $dev = $hash->{CODE}; + my $def = $defptr{$dev}; + my $nRetry = $buffer->{RETRY} + 1; + + if ($fhzHardwareBufferSpace > $minFhzHardwareBufferSpace) { + Log GetLogLevel($def->{NAME},2), "Resending command to FHT set " . $def->{NAME} . " " . $buffer->{TYPE} . " " . $buffer->{VAL} . + " (Retry $nRetry / ". $attr{FHZ}{softmaxretry} . ")"; + + sendCommand ($buffer->{HASH}, $buffer->{ARG}, $buffer->{NAME}, $buffer->{TYPE}, $buffer->{VAL}); + toSendbuffer ($buffer->{HASH}, $buffer->{TYPE}, $buffer->{VAL}, $buffer->{ARG}, $buffer->{KEY}, $nRetry); # send command also to buffer + + } else { + Log GetLogLevel($def->{NAME},2), "Can't send command \"set " . $def->{NAME} . " " . $buffer->{TYPE} . " " . $buffer->{VAL} . + "\". No space in FHZ hardware buffer left. Resending next time if free bufferspace available."; + } +} + + ##################################### sub FHT_SetState($$$$) @@ -249,27 +352,27 @@ FHT_Undef($$) } ##################################### -sub +sub FHT_Parse($$) { - my ($hash,$msg) = @_; + my ($hash, $msg) = @_; my $dev = substr($msg, 16, 4); my $cde = substr($msg, 20, 6); my $val = substr($msg, 26, 2) if(length($msg) > 26); + my $confirm = 0; + + $fhzHardwareBufferSpace = getFhzBuffer () if ($fhzHardwareBufferSpace == 0); if(!defined($defptr{$dev})) { Log 3, "FHT Unknown device $dev, please define it"; return "UNDEFINED FHT $dev"; } - my $def = $defptr{$dev}; # Unknown, but don't want report it. Should come with c409c401 - if($cde eq "00") { - return ""; - } + return "" if($cde eq "00"); if(length($cde) < 6) { my $name = $def->{NAME}; @@ -284,7 +387,18 @@ FHT_Parse($$) # it looks like a real message, and let the rest parse it Log 4, "FHT $def->{NAME} confirmation: $cde)"; $val = substr($cde, 2, 2); + + # get the free hardware buffer space in the FHZ after each confirmation message + $fhzHardwareBufferSpace = hex substr($cde, 4, 2); + + # increase $fhzHardwareBufferSpace at 5 because the confirmed command is deleted in the FHZ after confirmation + $fhzHardwareBufferSpace = $fhzHardwareBufferSpace + 5; + Log 4, "FHZ new FHT Buffer: $fhzHardwareBufferSpace"; + $cde = substr($cde, 0, 2) . "0069"; + + # set help var to remember this is a confirmation + $confirm = 1; } my $type; @@ -303,7 +417,6 @@ FHT_Parse($$) return $def->{NAME}; } - my $tn = TimeNow(); ########################### @@ -348,13 +461,26 @@ FHT_Parse($$) } elsif($type =~ m/.*-temp/) { $val = sprintf("%.1f (Celsius)", $val / 2) - } elsif($type eq "state") { + } elsif($type eq "warnings") { - my $nval; - $nval = "Bat: " . (($val & 1) ? "empty" : "ok"); - $nval .= ", Window: " . (($val & 32) ? "open" : "closed"); - $nval .= ", Fault: " . (($val & 16) ? "yes" : "no"); - $val = $nval; + my @nVal; + $nVal[0] = "Battery low" if ($val & 1); + $nVal[1] = "Window open" if ($val & 32); + $nVal[2] = "Fault on window sensor" if ($val & 16); + $nVal[3] = "Temperature to low" if ($val & 2); + + if ($val > 0) { + $val = ""; + foreach (@nVal) { + $val .= "$_; " if (defined($_)); + } + $val = substr($val, 0, length($val)-2); + } else { + $val = "none"; + } + + } elsif($type eq "lowtemp-offset") { + $val = sprintf("%d.0 (Celsius)", $val) } elsif($type =~ m/echo_/) { # Ignore these messages return ""; @@ -365,9 +491,192 @@ FHT_Parse($$) $def->{READINGS}{$type}{VAL} = $val; Log 4, "FHT $def->{NAME} ($type: $val)"; + + ########################################################################### + # here starts the processing the confirmation to control the softwarebuffer + # + + $attr{FHZ}{softbuffer} = 1 if (!defined($attr{FHZ}{softbuffer})); # set default values for config value attr FHZ softbuffer + + my $sbCount = keys(%{$def->{SENDBUFFER}}); # count the existing sendbuffer + my $nsCount = keys(%{$def->{NOTSEND}}); # count the existing failbuffer + + if ($confirm && ($sbCount > 0 || $nsCount > 0) && $attr{FHZ}{softbuffer} == 1) { + $type = "refreshvalues" if ($type eq "init"); + + my ($sbPr, $sbTs); + my $sbType = ""; + my $sbVal; + my $dKey; + + my ($val2) = split (/\s/, $val); + + # if the confirmation message for a command recive to late + # (the command moved to the notsend list yet) + # found the specific command ond delete them from the notsend list + foreach my $c (sort keys %{$def->{NOTSEND}}) { # go through the notsend list + ($sbPr, $sbTs, $sbType) = split (/:/, $c); + $sbVal = $def->{NOTSEND}->{$c}{VAL}; + $dKey = $c; + + $sbVal = $val2 if ($type eq "refreshvalues"); # refreshvalues have no value + if ($sbType eq $type && $sbVal eq $val2) { + + Log GetLogLevel($def->{NAME},2), "FHT $def->{NAME} late - confirmation ". + "($sbType: $sbVal) (delete from NOTSEND)"; + + delete($def->{NOTSEND}{$dKey}); # delete command from notsend list + last; # we can leave the loop because the command was deleted from the list + } + } + + # get the next entry from the buffer queue + foreach my $c (sort keys %{$def->{SENDBUFFER}}) { + ($sbPr, $sbTs, $sbType) = split (/:/, $c); + $sbVal = $def->{SENDBUFFER}->{$c}{VAL}; + $dKey = $c; + last; # exit foreach because we need the first entry only + } + + $sbVal = $val2 if ($type eq "refreshvalues"); # refreshvalues have no value + + # if the actual confirmation message part of the first command in the queue + if ($sbType eq $type && $sbVal eq $val2) { + delete($def->{SENDBUFFER}{$dKey}); # this buffer entry can deleted + + foreach my $c (sort keys %{$def->{SENDBUFFER}}) { # get the next buffer entry + my $nType = $def->{SENDBUFFER}->{$c}{TYPE}; + my $nArg = $def->{SENDBUFFER}->{$c}{ARG}; + my $nName = $def->{SENDBUFFER}->{$c}{NAME}; + my $nHash = $def->{SENDBUFFER}->{$c}{HASH}; + my $nVal = $def->{SENDBUFFER}->{$c}{VAL}; + my $nKey = $def->{SENDBUFFER}->{$c}{KEY}; + + sendCommand ($nHash, $nArg, $nName, $nType, $nVal); # nächsten Buffereintrag senden + toSendbuffer ($nHash, $nType, $nVal, $nArg, $nKey, 0); # send command also to buffer + + last; # exit foreach because we need the next entry only + } + } + } + + # + # end processing confirmation to control the softwarebuffer + ########################################################################### + $def->{CHANGED}[0] = "$type: $val"; $def->{STATE} = "$type: $val" if($type eq "measured-temp"); return $def->{NAME}; } +# check are commands in softwarebuffer +# ans send the next command to the FHZ +sub timerCheckBuffer ($) +{ + + Log 4, "Timer (Checking for unsend FHT commands)"; + + my ($hash) = @_; + my $bufCount = 0; # help counter + my $now = gettimeofday(); + my $ts = time; + + # set default values for config value attr FHZ softbuffer + $attr{FHZ}{softrepeat} = 240 if (!defined($attr{FHZ}{softrepeat})); + $attr{FHZ}{softmaxretry} = 3 if (!defined($attr{FHZ}{softmaxretry})); + + # loop to process all FHT devices + foreach my $d (keys %defptr) { + my $def = $defptr{$d}; # the actual FHT device + + # process all buffer entries + foreach my $c (sort keys %{$def->{SENDBUFFER}}) { + my ($rPr, undef, $rType) = split (/:/, $c); # priority and type + my $rVal = $def->{SENDBUFFER}{$c}{VAL}; # value + my $rTs = $def->{SENDBUFFER}{$c}{SENDTIME}; # the time of the sending moment to the FHT + my $rRetry = $def->{SENDBUFFER}{$c}{RETRY}; # retry counter + $rRetry ++ if ($fhzHardwareBufferSpace > $minFhzHardwareBufferSpace); # increase retrycounter if enough hardwarebuffer available + my $rKey = $c; # the bufferkey + + $rVal = "" if (!defined($rVal)); # set value to "" if value not defined (e.g. "refreshvalues" have no value) + $bufCount ++; # increase $bufCount + + my $buffer = $def->{SENDBUFFER}{$c}; # actual buffer entry + + # if the forst command in buffer to old, resend them again to the FHZ + if ($ts-$rTs > $attr{FHZ}{softrepeat}) { + if ($rRetry <= $attr{FHZ}{softmaxretry}) { # resend the command only if the max resend amount not reached + resendCommand ($buffer); # resend the actual command + } else { + # command resend fail after "softmaxretry" attempt to send + Log GetLogLevel($def->{NAME},2), $def->{NAME} . " $rType $rVal no confirmation after $rRetry retry"; + $def->{NOTSEND}{$rKey} = $def->{SENDBUFFER}{$rKey}; # put the buffer entry to the notsend list + $def->{NOTSEND}{$rKey}{RETRY} = $rRetry; + delete($def->{SENDBUFFER}{$rKey}); # delete command from buffer queue + } + } + last # exit foreach because we need only the first buffer value + } + } + + if ($bufCount > 0) { + Log 4, "Refresh FHT resend timer"; + InternalTimer(gettimeofday()+70, "timerCheckBuffer", $hash); # restart the internal Timer if any buffer contains commands + } else { + $timerCheckBufferIsRunning = 0; # remember timer is not running anymore + } +} + +# set given command tothe internal software buffer +# each command queued until the previous command become a confirmation +# +sub toSendbuffer ($$$$) +{ + + my ($hash, $type, $val, $arg, $nBufferKey, $retry) = @_; + + if (!$init_done || $attr{FHZ}{softbuffer} == 0) { + return + } + + my $dev = $hash->{CODE}; + my $def = $defptr{$dev}; + + my $tn = TimeNow(); # Readable time + my $ts = time; # Unix timestamp + my $pr = 9; # Default priority for command + my $sendTime = 0; # Timestamp for last sending command + my $sbCount = keys(%{$def->{SENDBUFFER}}); # Count of sendbuffer + + $pr = $priority{$type} if (defined($priority{$type})); # get priority for specific command type + $val = "" if (!defined($val)); + + if ($sbCount == 0) { + $pr = 0; # First command in buffer have always priority 0 (highest) + $sendTime = $ts; + } + + my $bufferKey = "$pr:$ts:$type"; #Default bufferkey + + # if bufferkey existing. delete the entry and save the entry with a new buffer + if ($nBufferKey ne "") { + $sendTime = $ts; + $bufferKey = $nBufferKey; + ($pr, $ts, $type) = split (/:/, $bufferKey); + delete($def->{SENDBUFFER}{$bufferKey}); # delete "old" bufferentry + + $bufferKey = "0:$ts:$type"; # new bufferkey für new bufferentry + } + + $def->{SENDBUFFER}{$bufferKey}{TIME} = $tn; + $def->{SENDBUFFER}{$bufferKey}{VAL} = $val; + $def->{SENDBUFFER}{$bufferKey}{NAME} = $def->{NAME}; + $def->{SENDBUFFER}{$bufferKey}{TYPE} = $type; + $def->{SENDBUFFER}{$bufferKey}{ARG} = $arg; + $def->{SENDBUFFER}{$bufferKey}{SENDTIME} = $sendTime; + $def->{SENDBUFFER}{$bufferKey}{RETRY} = $retry; + $def->{SENDBUFFER}{$bufferKey}{KEY} = $bufferKey; + $def->{SENDBUFFER}{$bufferKey}{HASH} = $hash; +} + 1; diff --git a/fhem/HISTORY b/fhem/HISTORY index bca1f05f5..2eb786a65 100644 --- a/fhem/HISTORY +++ b/fhem/HISTORY @@ -147,3 +147,13 @@ - weblinks added. Used by webpgm2 to display more than one plot at once - webpgm2 output reformatted. Using CSS to divide the screen area in 3 parts: command line, room-list and rest + +- Dirk Wed Oct 7 12:45:09 MEST 2007 + - FHT lime-protection code discovered + +- Dirk Wed Oct 18 23:28:00 MEST 2007 + - Softwarebuffer for FHT devices with queuing unsent commands and + repeating commands by transmission failure + - FHT low temperatur warning and setting for lowtemp-offset + - Change naming for state into warnings + Tagged as dirkh_20071019_0 \ No newline at end of file diff --git a/fhem/docs/commandref.html b/fhem/docs/commandref.html index 19d85b2c6..422cb0e77 100644 --- a/fhem/docs/commandref.html +++ b/fhem/docs/commandref.html @@ -1,1614 +1,1648 @@ - - - - - - fhem.pl command reference - - - - -

fhem.pl command reference

- -Introduction
-?,help
-attr
-defattr
-define
-delattr
-delete
-get
-include
-inform
-list
-modify
-quit
-reload
-rereadcfg
-save
-set
-setstate
-shutdown
-trigger
-sleep
-xmllist
-Perl specials
- - -

Introduction

-You can use all of the following commands in in two ways: - - -There are three types of commands: "fhem" commands (described in this document), -shell commands (they must be enclosed in double quotes ") and perl expressions -(enclosed in curly brackets {}). shell commands or perl expressions are needed for -complex at or notify arguments.

- -Shell commands will be executed in the -background, the perl program and the fhem commands will be executed in the main -"thread". -In order to make perl expressions easier to write, some special functions and -variables are available. See the section Perl special for a -description. -To trigger "fhem" commands from a shell script, use the client form of -fhem.pl (described above).

- -Multiple fhem commands are separated by semicolon (;). In order to use semicolon -in perl code or shell programs, they have to be escaped by the double semicolon -(;;).

- -Commands can be either typed in plain, or read from a file (e.g. the -configuration file at startup). The commands are either executed directly, or -later if they are arguments to the at and notify fhem commands.

- -If commands are read from a file, then a line ending with \ will be -concatenated with the next one, so long lines (e.g. perl oneliners) can be -split in multiple lines

- - - -

?, help

- - - - - -

attr

- - - -

defattr

- - - - - -

define

- - - - -

delattr

-
    - delattr <name> [<attrname>]
    -
    - Delete either a single attribute (see the attr command) - or all attributes for a device (if no <attrname> is defined).
    - - Examples: -
      - delattr lamp follow-on-for-timer
      - delattr lamp
      -
    -
    -
- - -

delete

-
    - delete <name>
    -
    - Delete something created with the define command. -
    - Examples: -
      - delete lamp
      -
    -
    -
- - -

get

-
- - - -

include

- - - -

inform

- - - -

list

- - - - -

modify

- - - -

quit

- - - - -

reload

- - - -

rereadcfg

- - - -

save

- - - - -

set

- - - - -

setstate

-
    - setstate <name> <value> -

    - Set the "STATE" for <name> as shown in paranthesis in the - list command - to <value> without sending any signals to the device - itself. This command is also used in the statefile. -

    - Examples: -
      -
      -    setstate lamp on
      -  
    -
    - Note: -
      -
    • The statefile uses another version of this command, don't be surprised. -
    • -
    -
- - - -

shutdown

-
    - shutdown -

    - Shut down the server (after saving the state information - ) -

    - Example: -
      - shutdown -
    -
- - - -

trigger

-
    - trigger <dev> <state> -

    - Trigger a notify definition. -

    - Example: -
      - trigger btn3 on -
    -
- - -

sleep

-
    - sleep <sec> -

    - Sleep for a given amount, millisecond accuracy. -

    - Example: -
      - sleep 0.5
      - notify btn3 set lamp toggle;;sleep 0.5;;set lamp toggle -
    -
    - Note: As the server is not multithreaded, everything is blocked for - the given amount.
    - -
- - - -

xmllist

-
    - xmllist -

    - Returns an XML tree of all definitions, all notify settings and all at - entries. It is not intended for human consumption. -

    - Example: -
      FHZ> xmllist
    -  <FHZINFO>
    -          <internal_LIST>
    -                  <internal name="global" state="internal" sets="" attrs="room configfile logfile modpath pidfilename port statefile userattr verbose version">
    -                          <INT key="DEF" value="<no definition>"/>
    -                          <INT key="NR" value="0"/>
    -                          <INT key="STATE" value="internal"/>
    -      [...]
    -
    -  
    -
- - - -

Perl specials

-
    -
  • To use fhem commands from the perl expression, use the function "fhem", - which takes a string argument, this string will be evaluated as an fhem - command chain.
    - Example: -
      - define n1 notify piri:on { fhem "set light on" } -
    -
  • -
  • - To make date and time handling easier, before evaluating a perl expression - the variables $sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst - are set (see perldoc -f localtime), with the exception that $month is in the - range of 1 to 12, and $year is also corrected by 1900 (as one would normally - expect). Additionally $we is 1 if it is weekend (i.e $wday == 0 || - $wday == 6), and 0 otherwise. - Example: -
      - define n2 notify piri:on { if($hour > 18 || $hour < 5) { fhem "set light on" } } -
    - -
  • - -
  • - Note: do not forget to escape the semicolon (;) with two semicolons - (;;), else your perl code will be interpreted as an fhem command and you - most certainly get syntax errors. -
  • - -
  • - The current value (the string you see in paranthesis in the output of the - list command) is available in the value hash; to access it - use $value{<devicename>}
    - If you need the old value (and time) of the currently triggered device, - then you can access it with $oldvalue{$dev}{TIME} and - $oldvalue{$dev}{VAL}.
    -
  • - -
  • - To access the numerical value of an FS20 command (e.g. toggle), use the - hash fs20_c2b. E.g. { Log 2, $fs20_c2b{"toggle"} } -
  • - -
  • - If you add the 99_SUNRISE.pm from the contrib directory to your module - directory (NOTE: you have to install the Perl module - DateTime::Event::Sunrise first), then you have access to the follwing - functions:
    -
      - sunset_rel()
      - sunset_abs()
      - sunrise_rel()
      - sunrise_abs()
      - isday()
      -
    - The _rel functions should be used as "at" spec, and the _abs functions as - argument to the on-till argument of the set command.
    - isday returns 1 if the sun is visible, and 0 else. -
  • - -
- - - + + + + + + fhem.pl command reference + + + + +

fhem.pl command reference

+ +Introduction
+?,help
+attr
+defattr
+define
+delattr
+delete
+get
+include
+inform
+list
+modify
+quit
+reload
+rereadcfg
+save
+set
+setstate
+shutdown
+trigger
+sleep
+xmllist
+Perl specials
+ + +

Introduction

+You can use all of the following commands in in two ways: +
    +
  • In the configuration file, which must be specified if you startup the + server. Example:
    +
      + fhem.pl ~/.fhem +
    +
    + A minimal configuration file would look like: +
    +      attr global logfile /tmp/fhem.log
    +      attr global statefile /tmp/fhem.save  
    +      attr global verbose 3                   
    +      attr global port 7072                   
    +      attr global modpath /usr/local/lib
    +      define FHZ FHZ /dev/tts/USB0        
    +
    +      define lamp FS20 8765 01
    + For other configuration files see the examples subdirectory.
    +
    +
  • + +
  • Through the TCP/IP connection, which you can either use in a "session" + (via telnet) or single client command (via fhem.pl). Example: +
      + telnet localhost 7072
      + <NL>
      (This newline switches into "prompt" mode)
      + <command>...
      + quit

      +
    + or +
      + fhem.pl 7072 "set lamp off" +
    +
  • +
+ +There are three types of commands: "fhem" commands (described in this document), +shell commands (they must be enclosed in double quotes ") and perl expressions +(enclosed in curly brackets {}). shell commands or perl expressions are needed for +complex at or notify arguments.

+ +Shell commands will be executed in the +background, the perl program and the fhem commands will be executed in the main +"thread". +In order to make perl expressions easier to write, some special functions and +variables are available. See the section Perl special for a +description. +To trigger "fhem" commands from a shell script, use the client form of +fhem.pl (described above).

+ +Multiple fhem commands are separated by semicolon (;). In order to use semicolon +in perl code or shell programs, they have to be escaped by the double semicolon +(;;).

+ +Commands can be either typed in plain, or read from a file (e.g. the +configuration file at startup). The commands are either executed directly, or +later if they are arguments to the at and notify fhem commands.

+ +If commands are read from a file, then a line ending with \ will be +concatenated with the next one, so long lines (e.g. perl oneliners) can be +split in multiple lines

+ + + +

?, help

+
    + ?
    + help
    +
    + Get a list of all commands and short description for each one +
+ + + + +

attr

+
    + attr <name> <attrname> [<value>]
    + or
    + attr at <at-spec-regexp> <attribute>
    + +
    Set an attribute to something defined by define. + There are some special attributes used by the fhem.pl itself or the + web-frontends, but you can define your own to use them in other applications. + You have to define them first with userattr, see + below.
    + + Use "attr <name> ?" to get a list of possible attributes. +

    + + Following are attributes of the global device:
    + +
      + + +
    • configfile
      + Contains the name of the configuration file. If save is called without argument, then the output will + be written to this file. +

    • + + +
    • lastinclude
      + If this attribute is set, then the last command of the generated + configfile (see the save command) will be
      + include <lastinclude-value>
      + This file is needed, as the save command will write only defines and + attributes to the config file, any other commands / includes will be + lost. E.g. it makes sense to set the FHTcode in + this file or the coordinates of your house via + sunrise_coord +

    • + +
      +
    • logfile
      + Specify the logfile to write. You can use "-" for + stdout, in this case the server won't background itself.
      + The logfile name can also take wildcards for easier logfile rotation, + see the FileLog section. +

    • + + +
    • modpath
      + Specify the path to the modules directory FHEM. The path + should not contain the directory FHEM. Every file there with the + name pattern <number>_<name>.pm will be loaded in the order + of the number. +

    • + + +
    • pidfilename
      + Write the process id of the perl process to the specified file. The + server runs as a daemon, and some distributions would like to check by + the pid if we are still running. The file will be deleted upon + shutdown. +

    • + + +
    • pidfilename
      + Works for the global "device"
      +

    • + + +
    • port
      + Listen on the TCP/IP port <number> for incoming + connections. To offer at least a little bit of security, the server + will only listen for connections from the localhost per default. If + there is a second value "global" then the server will listen for + non-localhost connections too. +

    • + + +
    • statefile
      + Set the filename where the state and certain at + information will be saved before shutdown. If it is not specified, then + no information will be saved. +

    • + + +
    • title
      + Used by the web frontend fhemweb.pl (webpgm2) as a Page title. +

    • + + +
    • userattr
      + A space separated list which contains the names of additional + attributes. Without specifying them you will not be able to set them + (in order to prevent typos). +

    • + + +
    • verbose
      + Set the verbosity level. Possible values: +
        +
      • 0 - it will only tell you when the server was started, or + stopped
      • +
      • 1 - it logs all error messages or unknown packets
      • +
      • 2 - it logs all signals received or sent in a "digested" + format,
      • +
      • 3 - it logs the signals for undefined devices,
      • +
      • 4 - it logs the TCP/IP connections and the called programs with + parameters,
      • +
      • 5 - is for debugging.
      • +
      + Recommended level is 3 for normal use. +
    • +
    + +
    + Attributes used by all devices: +
      + +
    • comment
      + Add an arbitrary comment. + + +
    • room
      + Filter/group devices. Recognized by web-pgm2 and web-pgm3. + Devices in the room hidden will not appear in the web output.

    • + + +
    • showtime
      + Used in the webfrontend pgm2 to show the time of last activity + instead of the state in the summary view. Useful e.g. for FS20 PIRI + devices. +
    • +
    + +
    + Attributes used by some device types: +
      + +
    • archivecmd / archivedir / nrarchive
      + Can be applied to FileLog devices.
      + When a new FileLog file is opened, the FileLog archiver wil be called. + This happens only, if the name of the logfile has changed (due to + time-specific wildcards, see the FileLog + section), and there is a new entry to be written into the file. +
      + + If the attribute archivecmd is specified, then it will be started as a + shell command (no enclosing " is needed), and each % in the command + will be replaced with the name of the old logfile.
      + + If this attribute is not set, but nrarchive and/or archivecmd is set, + then all superfluous logfiles will be moved to archivedir (or deleted if + archivedir is not set).

    • + + +
    • disable
      + Can be applied to at/notify/FileLog devices.
      + Disables the corresponding at/notify or FileLog device. Note: + If applied to an at, the command will not be executed, + but the next time will be computed.

    • + + +
    • do_not_notify
      + Can be applied to FHZ/FS20/FHT/HMS/KS300/WS300 devices.
      + Disable FileLog/notify/inform notification for a device. This affects + the received signal, the set and trigger commands.

    • + + +
    • dummy
      + Can be applied to FS20/FHT devices.
      + Set the device attribute dummy to define devices which should not + output any radio signals. Associated notifys will be executed if + the signal is received. Used e.g. to react to a code from a sender, but + it will not emit radio signal if triggered in the web frontend. + Implemented for FS20 and FHT devices.

    • + + +
    • filtertimeout
      + Can be applied to FHZ devices.
      + Ignore duplicate messages for this amount of time. The time is in + seconds, fractions are allowed. It affects installations with more then + one FHZ device or repeater, see the repeater + entry. +

    • + + +
    • follow-on-for-timer
      + Can be applied to FS20 devices.
      + the program automatically schedules a "setstate off" for the time + specified as argument to the on-for-timer command (for the specified + device only). +

    • + + +
    • loglevel
      + Can be applied to FHZ/FS20/FHT/HMS/KS300/WS300 devices.
      + Set the device loglevel to e.g. 6 if you do not wish messages from a + given device to appear in the global logfile (FHZ/FS20/FHT). E.g. to + set the FHT time, you should schedule "set FHZ time" every minute, but + this in turn makes your logfile unreadable. These messages will not be + generated if the FHZ attribute loglevel is set to 6.

    • + + +
    • logtype
      + Can be applied to FileLog devices.
      + Used by the pgm2 webfrontend to offer gnuplot images made from the + logs. The string is made up of tokens separated by comma (,), each + token specifies a different gnuplot program. The token may contain a + colon (:), the part before the colon defines the name of the program, + the part after is the string displayed in the web frontend. Currently + following types of gnuplot programs are implemented:
      +
        +
      • fs20
        + Plots on as 1 and off as 0. The corresponding filelog definition + for the device fs20dev is:
        + define FileLog fslog fs20dev /var/log/fs20dev-%Y-%U.log +
      • +
      • fht
        + Plots the measured-temp/desired-temp/actuator lines. The + corresponding filelog definitions (for the FHT device named + fht1) looks like:
        + define FileLog fhtlog1 fht1:.*(temp|actuator).* + /var/log/fht1-%Y-%U.log +
      • +
      • ks300_1
        + Plots the temperature and rain (per hour and per day) of a + ks300. The corresponding filelog definitions (for the KS300 + device named ks300) looks like:
        + define FileLog ks300log ks300:.*H:.* + /var/log/ks300-%Y-%U.log +
      • +
      • ks300_2
        + Plots the humidity and wind values of a + ks300. The corresponding filelog definition is the same as + above, both programs evaluate the same log. +
      • +
      • text
        + Shows the logfile as it is (plain text). +
      • +
      + The corresponding gnuplot files (up to the "text" one) must be + installed, see the fhemweb.pl configuration for the destination + directory.
      + + Example:
      + attr fhtlog1 logtype ks300_1:Temp/Rain,ks300_2:Hum/Wind,text:Raw-data +

    • + + + +
    • model
      + Can be applied to FHZ/FS20/FHT/HMS/KS300/WS300 devices.
      + The model attribute denotes the model type of the device. + The attributes will (currently) not be used by the fhem.pl directly. + It can be used by e.g. external programs or web interfaces to + distinguish classes of devices and send the appropriate commands + (e.g. "on" or "off" to a fs20st, "dim..%" to fs20du etc.). + The spelling of the model names are as quoted on the printed + documentation which comes which each device. This name is used + without blanks in all lower-case letters. Valid characters should be + a-z 0-9 and - (dash), + other characters should be ommited. Here is a list of "official" + devices:
      +
        +
      • FHT: fht80b
      • +
      • FS20: + fs20hgs + fs20pira + fs20piri + fs20s20 + fs20s8 + fs20s4 + fs20s4a + fs20s4m + fs20s4u + fs20s4ub + fs20sd + fs20sn + fs20sr + fs20ss + fs20str + fs20tfk + fs20tfk + fs20tk + fs20uts + fs20ze + + fs20as1 + fs20as4 + fs20di + fs20du + fs20ms2 + fs20rst + fs20sa + fs20sig + fs20st + fs20sv + fs20sv + fs20usr + +
      • + +
      • HMS: hms100-t hms100-tf hms100-wd hms100-mg hms100-tfk rm100-2
      • +
      • KS300: ks300
      • +
      • WS300: ws300pc
      • +
      • EM1010: em1010pc
      • +
      +

    • + + +
    • repeater
      + Can be applied to FHZ devices.
      + Set the attribute "repeater" for an FHZ device to 1 to ignore events + received from a FS20 repeater. In fact we are not sure that they are + repeater messages, we just ignore messages which were sent out by our + device for the next 3 seconds (see the next attribute) +

    • + + +
    • skip_next
      + Can be applied to at devices.
      + Used for at commands: skip the execution of the command the next time.

    • + + +
    • softbuffer
      + Can be applied to FHZ devices.
      + Used to disable the FHZ softbuffer for FHT deviced (enabled by default).
      + Note: By disabling the softbuffer FHEM works like in version 4.1. It is posible to lost commands to FHT devices by overflow the FHZ hardwarebuffer or on transmission failures.
      +
      +
    • +
    • softrepeat
      + Can be applied to FHZ devices.
      + Used to set the repeating time while FHEM tries to resend a FHT command which failed (default 240).
      + Note: Don't set this time to small. In this case it is posible that the FHZ Hardwarebuffer runs full in a short time. Than it is posible it takes long time to process the following commands. Normaly it should not necesary to change this value.
      +
      +
    • +
    • softmaxretry
      + Can be applied to FHZ devices.
      + Used to set the maximal retries in which FHEM try to resend a failed command to FHT devices (default 3).
      + Note: Don't set this value to height. In this case it is posible that the FHZ Hardwarebuffer runs full in a short time. Than it is posible it takes long time to process the following commands. Normaly it should not necesary to change this value.
      +
      +
    • +
    + + Examples: +
      + attr global verbose 3
      + attr lamp room kitchen
      + attr lamp dummy
      + attr lamp loglevel 6
      +
      + attr FHZ softbuffer 0 # disable the softbuffer for FHT devices
      + attr FHZ softrepeat 300 # resend failed commands to FHT devices after 300 seconds
      + attr FHZ softmaxretry 4 # stop resending failed commands to FHT devices after 4 retries.
    +
    + + Notes:
    +
      +
    • See delattr to delete attributes.
    • +
    +
+ + +

defattr

+
    + defattr [<attrname> [<value>]]
    + +
    Set the default attribute. Each device defined from now on will receive + this attribute (see the attr entry for details on + attribute names and values).
    + If no attrname is specified, then the default attribute list will be deleted. +

    + + Example to set the attribute "room kitchen" and "loglevel 4" to + each of the lamps: +
      + defattr room kitchen
      + defattr loglevel 4
      + define lamp1 FS20 1234 11
      + define lamp2 FS20 1234 12
      + define lamp3 FS20 1234 13
      + defattr
      +
    +
    + + Notes:
    +
      +
    • There is no way to delete a single default-attribute from the list
    • +
    +
+ + + + +

define

+
    + define <name> <type> <type-specific>
    +
    + Define a device. You need devices if you want to manipulate them (e.g. + set on/off), and the logfile is also more readable if it contains e.g. + "lamp off" instead of "Device 5673, Button 00, Code 00 (off)".
    + Use "define <name> ?" to get a list of possible types. +
    + + +

    Type FHZ

    +
      + define <name> FHZ <serial-device>
      +
      + Specifies the serial port to communicate with the FHZ 1000 PC. The name(s) + of the serial-device(s) depends on your distribution. The program can + service multiple devices, FS20 and FHT device commands will be sent out + through the last FHZ device defined before the definition of the FS20/FHT + device. To change the association, use the set command + activefor. Important: this definition must occur after the + modpath command but before any other (FHZ related) device definition, + else you'll see "no I/O device found" messages.
      + If the serial-device is called none, then no device will be opened, so you + can experiment without hardware attached.
      + + Set the attribute "repeater" for this device to 1 to ignore events received + from a FS20 repeater. In fact we are not sure that they are repeater + messages, we just ignore messages which were sent out by our device for the + next 3 seconds (or configured otherwise by filtertimeout). +
      + For GNU/Linux you may want to read our hints for GNU/Linux about multiple USB devices. +
    +
    + + +

    Type FS20

    +
      + define <name> FS20 <housecode> <button> + [fg <fgaddr>] [lm <lmaddr>] [gm FF] +

      + + <housecode> is a four digit hex number, + corresponding to the housecode address, <button> is + a two digit hex nunmber, corresponding to a button of the transmitter.
      +
    • The optional fg specifies the function group, the first digit of the 2 + digit adress must be F.
    • +
    • The optional lm specifies the local master, the last digit of the 2 + digit adress must be F.
    • +
    • The optional gm specifies the global master, the adress must be FF.
    • +
      + + Examples: +
        + define lamp FS20 7777 00 fg F1
        + define roll1 FS20 7777 01 +
      +
    +
    + + +

    Type FHT

    +
      + define <name> FHT <housecode> +

      + + <housecode> is a four digit hex number, + corresponding to the adress of the FHT80b device. +
      + + Examples: +
        + define wz FHT 3232
        +
      +
      + See the section set for more. +
    +
    + + +

    Type HMS

    +
      + define <name> HMS <housecode> +

      + + <housecode> is a four digit hex number, + corresponding to the adress of the HMS device. +
      + + Examples: +
        + define temp HMS 1234
        +
      + Notes:
      +
        +
      • There is _NO_ guarantee that the code will work as expected in all + circumstances, the authors are not liable for any damage occuring as a + result of incomplete or buggy code
      • + +
      • Currently supported devices are the HMS100T, HMS100TF, HMS100WD and + the RM100-2.
      • + +
      • The housecode of the HMS devices may change if the battery is renewed. + In order to make life easier, you can define a "wildcard" device for each + type of HMS device. First the real device-id will be checked, then the + wildcard device id. The wildcards are: +
          +
        • 1000 for the HMS100TF
        • +
        • 1001 for the HMS100T
        • +
        • 1002 for the HMS100WD
        • +
        • 1003 for the RM100-2
        • +
        • 1006 for the HMS100MG
        • +
        +
      • + +
      • Some battery low notifications are not yet implemented (RM100, HMS100WD).
      • +
      • Please test your installation before relying on the functionality.
      • +
      +
      +
    +
    + + +

    Type KS300

    +
      + define <name> KS300 <housecode> [ml/raincounter [wind-factor]] +

      + + <housecode> is a four digit hex number, + corresponding to the adress of the KS300 device, right now it is ignored. + The ml/raincounter defaults to 255 ml, but it must be specified if you wish + to set the wind factor, which defaults to 1.0. + +
      + + Examples: +
        + define ks1 KS300 1234
        +
      +
      +
    +
    + + +

    Type WS300

    +
      + define WS300Device WS300 <serial device>
      + or
      + define <devname> WS300 [0-9]
      +
      + The first line is mandatory if you have a WS300 device: it defines the + input device with its USB port. The name of this device is fixed and must + be WS300Device. It must be the first defined WS300 device.
      + + For each additional device (with number 0 to 9) you have to define another + WS300 device, with an arbitrary name. The WS300 device which reports the + readings will be defined with the port number 9, an optional KS300 with the + port number 8.

      + + Examples: +
      +      define WS300Device  WS300   /dev/ttyUSB1
      +      define ash2200.1    WS300   0
      +      define ks300        WS300   8
      +      define ws300        WS300   9
      +    
      +
    +
    + + +

    Type EM

    +
      + define <name> EM <em1010pc-device> +

      + + Define a EM1010PC USB device. From the software point of view there should + be no problems if you attach/define more than one EM1010PC, but it is + unknown if the low-level radio protocol supports this.
      Currently there + is no way to read the internal log of the EM1010PC, use the program + em1010.pl in the contrib directory for this purpose.

      + + Examples: +
        + define em EM /dev/elv_em1010pc
        +
      +
      +
    + + +

    Type EMWZ

    +
      + define <name> EMWZ <device-number> +

      + + Define up to 4 EM1000WZ attached to the EM1010PC. The device number must + be between 1 and 4 (else you have a differnt device connected to the + EM1010PC). Defining an EMWZ will schedule an internal task, which reads the + status of the device every 5 minutes, and triggers notify/filelog commands. +

      + + Example: +
        + define emwz EMWZ 1
        +
      +
      +
    + + +

    Type EMEM

    +
      + define <name> EMEM <device-number> +

      + + Define up to 4 EM1000EM attached to the EM1010PC. The device number must + be between 5 and 8. + Defining an EMEM will schedule an internal task, which reads the + status of the device every 5 minutes, and triggers notify/filelog commands. +
      Note: Currently this device does not support a "set" function. +

      + + Example: +
        + define emem EMEM 5
        +
      +
      +
    + + +

    Type SCIVT

    +
      + define <name> SCIVT <SCD-device> +

      + + Define a SCD series solar controler device. Details see here. + You probably need a Serial to USB controller like the PL2303. +
      + Defining an SCIVT device will schedule an internal task, which reads the + status of the device every 5 minutes, and triggers notify/filelog commands. +
      Note: Currently this device does not support a "set" function, only + a single get function which reads the device status immediately. +

      + + Example: +
        + define scd SCIVT /dev/ttyUSB2
        +
      +
      +
    + + +

    Type FileLog

    +
      + define <name> FileLog <filename> <regexp> +

      + + Log events to <filename>. The log format is +
      +      YYYY:MM:DD_HH:MM:SS <device> <event>
      + The regexp will be checked against the (complete!) device name + or against the (complete!) devicename:event combination. +
      + <filename> may contain one or more of the following + wildcards (a subset of the Unix date command arguments): +
        +
      • %d day of month (01..31)
      • +
      • %m month (01..12)
      • +
      • %Y year (1970...) +
      • %w day of week (0..6); 0 represents Sunday +
      • %j day of year (001..366) +
      • %U week number of year with Sunday as first day of week (00..53) +
      • %V week number of year with Monday as first day of week (01..53) +
      + + Examples: +
        + define lamplog FileLog /var/tmp/lamp.log lamp
        + define wzlog FileLog /var/tmp/wz-%Y-%U.log + wz:(measured-temp|actuator).*
        +
      +
      +
    + + +

    Type at

    +
      + define <name> at <timespec> <command>
      +
      + Start an arbitrary fhem.pl command at a later time.
      + <timespec> format: [+][*{N}]<timedet>
      +
        + The optional + indicates that the specification is + relative(i.e. it will be added to the current time).
        + The optional * indicates that the command should be + executed repeatedly.
        + The optional {N} after the * indicates,that the command + should be repeated N-times only.
        + <timedet> is either HH:MM, HH:MM:SS or {perlfunc()}, where perlfunc + must return a HH:MM or HH:MM:SS date. +
      +
      + + Examples: +
      +    # absolute ones:
      +    define a1 at 17:00:00 set lamp on                            # fhem command
      +    define a2 at 17:00:00 { Log 1, "Teetime" }                   # Perl command
      +    define a3 at 17:00:00 "/bin/echo "Teetime" > /dev/console"   # shell command
      +    define a4 at *17:00:00 set lamp on                           # every day
      +
      +    # relative ones
      +    define a5 at +00:00:10 set lamp on                  # switch the lamp on in 10 seconds
      +    define a6 at +00:00:02 set lamp on-for-timer 1      # Blink once in 2 seconds
      +    define a7 at +*{3}00:00:02 set lamp on-for-timer 1  # Blink 3 times
      +
      +    # Blink 3 times if the piri sends a command
      +    define n1 notify piri:on.* define a8 at +*{3}00:00:02 set lamp on-for-timer 1
      +
      +    # Switch the lamp on from sunset to 11 PM 
      +    # Copy 99_SUNRISE.pm in the FHEM directory to have sunset_rel()
      +    { sunrise_coord("8.686", "50.112", "Europe/Berlin") }
      +    define a9 at +*{sunset_rel()} set lamp on
      +    define a10 at *23:00:00 set lamp off
      +
      +    # More elegant version, works for sunset > 23:00 too
      +    define a11 at +*{sunset_rel()} set lamp on-till 23:00
      +
      +    # Only do this on weekend
      +    define a12 at +*{sunset_rel()} { fhem("set lamp on-till 23:00") if($we) }
      +
      +    # Switch lamp1 and lamp2 on from 7:00 till 10 minutes after sunrise
      +    define a13 at *07:00 set lamp1,lamp2 on-till {sunrise_abs(+600)}
      +
      +    # Switch the lamp off 2 minutes after sunrise each day
      +    define a14 at +*{sunrise_rel(+120)} set lamp on
      +    
      + + Notes:
      +
        +
      • if no * is specified, then a command will be executed + only once, and then the at entry will be deleted. In + this case the command will be saved to the statefile (as it + considered volatile, i.e. entered by cronjob) and not to the + configfile (see the save command.) +
      • + +
      • if the current time is greater then the time specified, then the + command will be executed tomorrow. This is why the relative forms + of the sunset/sunrise functions should be used with the relative + (+) flag
      • + +
      • In order to use the sunrise_rel()/sunset_rel() functions, copy the + 99_SUNRISE.pm file from the contrib into the modules (FHEM) + directory, and put { sunrise_coord(long, lat, tz) } into your config + file, as in the above example. If you are not using sunrise_coord, then + the coordinates for Frankfurt am Main, Germany will be used. + You also have to install the Datetime::Event::Sunrise perl module. +
      • + +
      • For even more complex date handling you either have to call fhem from + cron or filter the date in a perl expression, see the last example and + the section Perl special. +
      • +
      +
      +
    + + +

    Type notify

    +
      + define <name> notify <pattern> <command> +

      + Execute a command when received an event for the definition <pattern>. If + <command> is enclosed in {}, then it is a perl expression, if it is + enclosed in "", then it is a shell command, else it is a "plain" fhem.pl + command (chain). See the trigger command for + testing it. + + Examples: +
        + define b3lampV1 notify btn3 set lamp %
        + define b3lampV2 notify btn3 { fhem "set lamp %" }
        + define b3lampV3 notify btn3 "/usr/local/bin/setlamp "%""
        + define b3lampV3 notify btn3 set lamp1 %;;set lamp2 %
        + define wzMessLg notify wz:measured.* "/usr/local/bin/logfht @ "%""
        + define LogHToDB notify .*H:.* {DbLog("@","%")}
        + define LogUndef notify UNDEFINED "send-me-mail.sh "%""
        +
      +
      + + Notes: +
        +
      • The character % will be replaced with the received event, + e.g. with on or off or measured-temp: 21.7 + (Celsius)
        It is advisable to put the % into double + quotes, else the shell may get a syntax error.
        + To use % or @ in the text itself, use the double mode (%% or @@)
      • + +
      • The character @ will be replaced with the device + name.
      • + +
      • <pattern> may also be a compound of + definition:event to filter for events.
      • + +
      • <pattern> must completely (!) + match either the device name, or the compound of the device name and the + event. The event is either the string you see in the list output in paranthesis after the device name, or the + string you see when you do a detailed list of the device.
      • + +
      • To use database logging, copy the file contrib/91_DbLog.p into your + modules directory, and change the $dbconn parameter in the file.
      • + +
      • Each undefined device (FS20, HMS, FHT) will be reported with the + device name "UNDEFINED". The % parameter will contain the type (FS20, + HMS100T, etc) and device number, separated by a space.
      • + +
      +
    + + +

    Type weblink

    +
      + define <name> weblink [link|fileplot] <argument> +

      + This is a placeholder used with webpgm2 to be able to integrate links + into it, and to be able to put more than one gnuplot picture on one page. + It has no set or get methods. + + Examples: +
        + define wl_1 weblink link http://www.fhem.de
        + define wl_2 weblink fileplot <logdevice>:<gnuplot-file>:<logfile>
        +
      +
      + + Notes: +
        + Normally you won't have to define fileplot weblinks manually, as fhemweb.pl + (webpgm2) makes it easy for you, just plot a logfile (see logtype) and convert it to weblink. Now you can + group these weblinks by putting them into rooms. + If you convert the current logfile to a weblink, it will always refer to the + current file (and not the one you originally specified). +
      +
    + +
+ + + +

delattr

+
    + delattr <name> [<attrname>]
    +
    + Delete either a single attribute (see the attr command) + or all attributes for a device (if no <attrname> is defined).
    + + Examples: +
      + delattr lamp follow-on-for-timer
      + delattr lamp
      +
    +
    +
+ + +

delete

+
    + delete <name>
    +
    + Delete something created with the define command. +
    + Examples: +
      + delete lamp
      +
    +
    +
+ + +

get

+
    + get <name> <type-specific> +

    + Ask a value directly from the device, and wait for an answer. In general, you + can get a list of possible commands by
    get <device> ? +
    + Right now only the FHZ module supports this function. + +

    Type FHZ:

    +
      + get FHZ <value> +

      + where value is one of:
      +
      +      init1
      +      init2
      +      init3
      +      serial
      +      fhtbuf
      + Notes: +
        +
      • The mentioned codes are needed for initializing the FHZ1X00
      • +
      • The answer for a command is also displayed by list FHZ +
      • +
      • + The FHZ1000PC has a message buffer for the FHT, as it + only can send messages to it every 2 (or so) minutes. If the buffer + is full, then newly issued ones will be dropped. fhtbuf + returns the free memory in this buffer (in hex), my maximum is 2c (42 + bytes).
      • +
      +
    + +

    Type EM:

    +
      + get EM <value> +

      + where value is either version or time. +
    + +

    Type EMWZ:

    +
      + get EMWZ status +

      + This is the same command which is scheduled every 5 minutes internally. +
    +
+ + + +

include

+
    + include <filename>
    +
    + Read in the file, and process every line as a fhem command. Makes + configuration files more modular and enables to reread them. +
    +
+ + +

inform

+
    + inform [on|off]
    +
    + If set to on, and a device state changes, send a notification to the current + client. This command can be used by other programs/modules to receive a + notification. +
    +
+ + +

list

+
    + list [name] +

    + Output a list of all definitions, all notify settings and all at + entries. This is one of the few commands which return a string in a + normal case. +

    + Example: +
      FHZ> list
    +
    +  Type list  for detailed info.
    +
    +  Internal:
    +    global               (Internal)
    +
    +  FHZ:
    +    FHZ                  (fhtbuf: 23)
    +
    +  FS20:
    +    Btn4                 (on-old-for-timer)
    +    Roll1                (on)
    +    Stehlampe            (off)
    +
    +  FHT:
    +    fl                   (measured-temp: 21.1 (Celsius))
    +
    +  KS300:
    +    out1                 (T: 2.9  H: 74  W: 2.2  R: 8.2  IR: no)
    +
    +  at:
    +    at_rollup            (Next: 07:00:00)
    +
    +  notify:
    +    ntfy_btn4            (active)
    +
    +  FileLog:
    +    avglog               (active)
    +
    +  
    + If specifying name, then a detailed status for name + will be displayed, e.g.: +
      FHZ> list fl
    +
    +  Internals:
    +    CODE       5102
    +    DEF        5102
    +    NAME       fl
    +    NR         15
    +    STATE      measured-temp: 21.1 (Celsius)
    +    TYPE       FHT
    +    IODev      FHZ
    +  Attributes:
    +    room       Heizung
    +  Readings:
    +    2006-11-02 09:45:56   actuator        19%
    +    2006-10-28 15:10:58   code_0000aa     17
    +    2006-10-07 10:52:09   code_0000ba     0
    +    2006-11-02 10:40:08   code_4b004b     0
    +    2006-11-02 08:24:46   code_7e0067     0
    +    2006-11-02 04:13:35   day-temp        21.0 (Celsius)
    +    2006-11-02 06:03:37   desired-temp    21.0 (Celsius)
    +    2006-11-02 04:13:31   fri-from1       06:00
    +    2006-11-02 04:13:31   fri-to1         23:50
    +    2006-11-02 04:11:30   init            255
    +    2006-11-02 04:13:36   lowtemp-offset  2.0 (Celsius)
    +    2006-11-02 10:40:06   measured-high   0
    +    2006-11-02 10:40:06   measured-low    211
    +    2006-11-02 10:40:06   measured-temp   21.1 (Celsius)
    +    2006-11-02 04:13:39   mode            auto
    +    2006-11-02 04:13:25   mon-from1       06:00
    +    2006-11-02 04:13:25   mon-to1         23:00
    +    2006-11-02 04:13:35   night-temp      18.0 (Celsius)
    +    2006-11-02 04:13:32   sat-from1       08:00
    +    2006-11-02 04:13:33   sat-to1         23:50
    +    2006-11-02 04:13:34   sun-from1       08:00
    +    2006-11-02 04:13:34   sun-to1         23:00
    +    2006-11-02 04:13:29   thu-from1       06:00
    +    2006-11-02 04:13:29   thu-to1         23:00
    +    2006-11-02 04:13:26   tue-from1       06:00
    +    2006-11-02 04:13:26   tue-to1         23:00
    +    2006-11-02 10:40:07   warnings        Battery low
    +    2006-11-02 04:13:27   wed-from1       06:00
    +    2006-11-02 04:13:28   wed-to1         23:00
    +    2006-11-02 04:13:36   windowopen-temp 12.0 (Celsius)
    +Send buffer:
    2007-10-19 00:31:24 desired-temp 22.5 + 2007-10-19 00:33:20 mode auto
    +
    +
+ + + +

modify

+
    + modify <name> <type-dependent-options> +

    + + Used to modify some definitions. Useful for changing some at or notify definitions. If specifying + one argument to an at type deinition, only the time part will be changed. In + case of a notify type definition, only the regex part will be changed. All + other values (state, attributes, etc) will remain intact. +

    + Example: +
      + define lampon at 19:00 set lamp on
      + modify lampon *19:00
      + modify lampon 19:00 set lamp on-for-timer 16
      +
    +
+ + +

quit

+
    + quit +

    + If used in a TCP/IP session, terminate the client session.
    + If used in a script, terminate the parsing of the current script. +

    + Example: +
      + quit +
    +
+ + + +

reload

+
    + reload <module> +

    + Reload the given module from the module directory. Mainly intended to reload + the 99_PRIV file (or equivalent) in order to test perl-scripts. +

    + Example: +
      + reload 99_PRIV +
    +
+ + +

rereadcfg

+
    + rereadcfg +

    + Re-read the configuration file. + Note: The statefile will be saved first, then the config file will be read + (all devices will be initialized again), and at last the statefile will be reloaded again. +

    + Example: +
      + rereadcfg +
    +
+ + +

save

+
    + save [<configfile>] +

    + Save first the statefile, then the + configfile information. If a parameter is specified, + it will be used instead the global configfile attribute.

    + Notes: +
      +
    • save only writes out definitions and attributes, but no commands + which were previously part of the config file. Put such commands in the + lastinclude file. +
    +
+ + + +

set

+
    + set <name> <type-specific> +

    + Set parameters of a device / send signals to a device. You can + get a list of possible commands by
    set <name> ? +
    + Instead of <name> you can also use an enumeration (separated by comma) + or ranges (separated by -), see the FS20 examples. + + +

    Type FHZ:

    + + + + +

    Type FS20:

    +
      + set <name> <value> [<time>] +

      + where value is one of:
      +
      +      dim06%
      +      dim12%
      +      dim18%
      +      dim25%
      +      dim31%
      +      dim37%
      +      dim43%
      +      dim50%
      +      dim56%
      +      dim62%
      +      dim68%
      +      dim75%
      +      dim81%
      +      dim87%
      +      dim93%
      +      dim100%
      +      dimdown
      +      dimup
      +      dimupdown
      +      off
      +      off-for-timer
      +      on     		# dimmer: set to value before switching it off
      +      on-for-timer      # see the note
      +      on-old-for-timer  # set to previous (before switching it on) 
      +      ramp-on-time      # time to reach the desired dim value on dimmers
      +      ramp-off-time     # time to reach the off state on dimmers
      +      reset
      +      sendstate
      +      timer
      +      toggle            # between off and previous dim val
      +      on-till           # Special, see the note
      +      
      + + Examples: +
        + set lamp on
        + set lamp1,lamp2,lamp3 on
        + set lamp1-lamp3 on
        + set lamp on-for-timer 12
        +
      +
      + Notes: +
        +
      • Use reset with care: the device forgets even the housecode. +
      • +
      • As the FS20 protocol needs about 0.22 seconds to transmit a + sequence, a pause of 0.22 seconds is inserted after each command. +
      • +
      • The FS20ST switches on for dim*%, dimup. It does not respond to + sendstate.
      • +
      • If the timer is set (i.e. it is not 0) then on, dim*, + and *-for-timer will take it into account (at least by the FS20ST). +
      • +
      • The time argument ranges from 0.25sec to 4 hours and + 16 minutes. + As the time is encoded in one byte there are only 112 distinct + values, the resolution gets coarse with larger values. The program + will report the used timeout if the specified one cannot be set + exactly. The resolution is 0.25 sec from 0 to 4 sec, 0.5 sec from 4 + to 8 sec, 1 sec from 8 to 16 sec and so on. If you need better + precision for large values, use at which has a 1 + sec resolution.
      • +
      • If the attribute follow-on-for-timer is set for the device and the + on-for-timer command is sent to the device with a time parameter, + the program automatically schedules a "setstate off" for the + specified time.
      • +
      • on-till requires an absolute time in the "at" format (HH:MM:SS, HH:MM + or {}, where the perl-code returns a time specification). + If the current time is greater then the specified time, then the + command is ignored, else an "on" command is generated, and for the + given "till-time" an off command is scheduleld via the at command. +
      • +
      +
    + + + +

    Type FHT:

    +
      + set <name> <valuetype> <value> +

      + where value is one of:
      +
      +    mon-from1
      +    mon-to1
      +    mon-from2
      +    mon-to2
      +    tue-from1
      +    tue-to1
      +    tue-from2
      +    tue-to2
      +    wed-from1
      +    wed-to1
      +    wed-from2
      +    wed-to2
      +    thu-from1
      +    thu-to1
      +    thu-from2
      +    thu-to2
      +    fri-from1
      +    fri-to1
      +    fri-from2
      +    fri-to2
      +    sat-from1
      +    sat-to1
      +    sat-from2
      +    sat-to2
      +    sun-from1
      +    sun-to1
      +    sun-from2
      +    sun-to2
      +    mode
      +    holiday1
      +    holiday2
      +    desired-temp
      +    day-temp
      +    night-temp
      +    year
      +    month
      +    day
      +    hour
      +    minute
      +    refreshvalues
      +    lowtemp-offset
      +
      + Notes: +
        +
      • All *-temp values need a temperature + as argument, which will be rounded to 0.5 Celsius.
        + Temperature values +must between 5.5 and 30.5 Celsius. Value 5.5 set the actuator to OFF, value 30.5 set the actuator to ON
      • +
      • mode is one of auto, manual, holiday or + holiday_short.
        If the mode is holiday, then +
          +
        • holiday1 sets the end-day of the holiday
        • +
        • holiday2 sets the end-month of the holiday
        • +
        + For holiday_short +
          +
        • holiday1 sets the time, in 10-minute steps
        • +
        • holiday2 sets number of days from now on.
        • +
        +
      • +
      • The *-from1/*-from2/*-to1/*-to2 valuetypes need a time + spec as argument in the HH:MM format. They define the periods, where + the day-temp is valid. The minute (MM) will be rounded to 10, and + 24:00 means off.
      • +
      • refreshvalues does not need an argument, but sends a + plea to the FHT device, so it may send its parameters. If you want + to get these values regularly, then schedule:
        + at +*01:00:00 set <name> refreshvalues
      • +
      • lowtemp-offset need a temperature + as argument, which will be rounded to 1.0 Celsius.
        + Temperature values must between 1.0 and 5.0 Celsius.
        + The + lowtemp-offset is used for temperature warning (to low temperature in a room within more than 1,5 hours after the last desired-temp changing). The low temperatur warning it relates to the actual desired temperature.
        +
      • +
      • The FHT is very economical (or lazy), it receives messages from the + FHZ1x00 every 2 minutes (or so). Don't be surprized if your command + is accepted 10 minutes later by the device. See the related + fhtbuf entry in the get + section.
        +
      • For FHT devices, FHEM have an internal software buffer for sending commands step by step. This buffer should prevent lost commands. In case of transmission failures FHEM tries to resend commands. You can see the queued unsent and the failed commands with the list command. If a command don't picked up from a FHT device within a given time, the command sends again until softmaxretry reached.
        +
      • To prevent long time waiting for sending important command, there is a priority list. Commands send in this importance:
        +desired-temp, mode, refreshvalues,holiday1,holiday2,day-temp,night-temp, [all other commands]
        +
        +
      +
    + + +

    Type WS300:

    +
      + set WS300Device <interval(min.)> <height(m)> <rainvalume(ml)> +

      + Set some WS300 configuration parameters. +
    + + +

    Type EMWZ:

    +
      + set EMWZdevice <param> <value>

      + where param is one of: +
        +
      • rperkw
        + Number of rotations for a KiloWatt of the EM1000WZ device (actually + of the device where the EM1000WZ is attached to). Without setting + this correctly, all other readings will be incorrect. +
      • alarm
        + Alarm in WATT. if you forget to set it, the default value is + rediculously low (random), and if a value above this threshold is + received, the EM1010PC will start beeping once every minute. It can + be very annoying. +
      • price
        + The price of one KW in EURO (use e.g. 0.20 for 20 Cents). It is used + only on the EM1010PC display, it is of no interest for FHEM. +
      +
    + + +
+ + + +

setstate

+
    + setstate <name> <value> +

    + Set the "STATE" for <name> as shown in paranthesis in the + list command + to <value> without sending any signals to the device + itself. This command is also used in the statefile. +

    + Examples: +
      +
      +    setstate lamp on
      +  
    +
    + Note: +
      +
    • The statefile uses another version of this command, don't be surprised. +
    • +
    +
+ + + +

shutdown

+
    + shutdown +

    + Shut down the server (after saving the state information + ) +

    + Example: +
      + shutdown +
    +
+ + + +

trigger

+
    + trigger <dev> <state> +

    + Trigger a notify definition. +

    + Example: +
      + trigger btn3 on +
    +
+ + +

sleep

+
    + sleep <sec> +

    + Sleep for a given amount, millisecond accuracy. +

    + Example: +
      + sleep 0.5
      + notify btn3 set lamp toggle;;sleep 0.5;;set lamp toggle +
    +
    + Note: As the server is not multithreaded, everything is blocked for + the given amount.
    + +
+ + + +

xmllist

+
    + xmllist +

    + Returns an XML tree of all definitions, all notify settings and all at + entries. It is not intended for human consumption. +

    + Example: +
      FHZ> xmllist
    +  <FHZINFO>
    +          <internal_LIST>
    +                  <internal name="global" state="internal" sets="" attrs="room configfile logfile modpath pidfilename port statefile userattr verbose version">
    +                          <INT key="DEF" value="<no definition>"/>
    +                          <INT key="NR" value="0"/>
    +                          <INT key="STATE" value="internal"/>
    +      [...]
    +
    +  
    +
+ + + +

Perl specials

+
    +
  • To use fhem commands from the perl expression, use the function "fhem", + which takes a string argument, this string will be evaluated as an fhem + command chain.
    + Example: +
      + define n1 notify piri:on { fhem "set light on" } +
    +
  • +
  • + To make date and time handling easier, before evaluating a perl expression + the variables $sec, $min, $hour, $mday, $month, $year, $wday, $yday, $isdst + are set (see perldoc -f localtime), with the exception that $month is in the + range of 1 to 12, and $year is also corrected by 1900 (as one would normally + expect). Additionally $we is 1 if it is weekend (i.e $wday == 0 || + $wday == 6), and 0 otherwise. + Example: +
      + define n2 notify piri:on { if($hour > 18 || $hour < 5) { fhem "set light on" } } +
    + +
  • + +
  • + Note: do not forget to escape the semicolon (;) with two semicolons + (;;), else your perl code will be interpreted as an fhem command and you + most certainly get syntax errors. +
  • + +
  • + The current value (the string you see in paranthesis in the output of the + list command) is available in the value hash; to access it + use $value{<devicename>}
    + If you need the old value (and time) of the currently triggered device, + then you can access it with $oldvalue{$dev}{TIME} and + $oldvalue{$dev}{VAL}.
    +
  • + +
  • + To access the numerical value of an FS20 command (e.g. toggle), use the + hash fs20_c2b. E.g. { Log 2, $fs20_c2b{"toggle"} } +
  • + +
  • + If you add the 99_SUNRISE.pm from the contrib directory to your module + directory (NOTE: you have to install the Perl module + DateTime::Event::Sunrise first), then you have access to the follwing + functions:
    +
      + sunset_rel()
      + sunset_abs()
      + sunrise_rel()
      + sunrise_abs()
      + isday()
      +
    + The _rel functions should be used as "at" spec, and the _abs functions as + argument to the on-till argument of the set command.
    + isday returns 1 if the sun is visible, and 0 else. +
  • + +
+ + + diff --git a/fhem/docs/fhem.html b/fhem/docs/fhem.html index bf56135ac..844761148 100644 --- a/fhem/docs/fhem.html +++ b/fhem/docs/fhem.html @@ -1,255 +1,261 @@ - - - - -Home of FHEM - - - - - -

FHEM

-GPL'd server to access devices like FHZ1000/FHZ1300,EM1010PC,WS300,SCIVT. -Formerly known as fhz1000.pl - -

News (as of =DATE=, Version =VERS=)

-
    -
  • doc: linux.html (private udev-rules, not 50-..., ATTRS) -
  • bugfix: setting devices with "-" in their name did not work -
  • doc: fhem.pl and commandref.html (notifyon -> notify, correction - of examples) -
  • feature: modify command added -
  • feature: The "-" in the name is not allowed any more -
  • bugfix: disabled notify causes "uninitialized value" (STefan, 1.5) -
  • bugfix: deleted FS20 items are still logging (zombie) (Gerhard, 16.5) -
  • bugfix: added FS20S8, removed stty_parmrk (Martin, 24.5) -
  • feature: added archivedir/archivecmd to the FileLog -
  • feature: added EM1010PC/EM1000WZ/EM1000EM support -
  • bugfix: undefined messages for unknown HMS devs (Peter, 8.6) -
  • bugfix: em1010 and %oldvalue bugs (Peter, 9.6) -
  • bugfix: SCIVT solar controller (peterp, 1.7) -
  • bugfix: WS300 loglevel change (from 2 to 5 or device specific loglevel) -
  • feature: First steps for a Fritz!Box port. See the fritzbox.html -
- - - -

Description

-
    -This program makes the FHZ1000/FHZ1300/WS300 USB devices sold by ELV, Conrad and -others useable with Linux. In fact, there is nothing Linux special in it, you -should be able to use it on other platforms as long as you can access the -hardware as a serial device.
    -The program runs as a server, you can control it via telnet, command line -program or TCP/IP directly, like the supplied web frontends do.

    - -Currently implemented features:
    -
      -
    • Via the FHZ module (with access to one or more FHZ1000/FHZ1300 device): -
        -
      • reading and sending FS20 events (on/off/dimming, timer commands)
        -
      • support of FS20 address features function group, local and global master -
      • reading and changing FHT80b parameters (temp, actuator, etc).
        - The FHT8b seems to work too. Note: the FHT8 wont work.
      • -
      • reading HMS data (HMS100-T,-TF,-WD,-MG,-TFK and RM100-2)
      • -
      • reading KS300 data
      • -
      -
    • -
    • reading WS300 data, and up to 9 attached devices
    • -
    • reading EM1000WZ/EM1000EM data via an attached EM1010PC
    • -
    • reading an attached SCIVT device
    • -
    • logging events to files (or database), with regexp filters
    • -
    • notifying external programs or internal modules when receiving certain - events
    • -
    • timed commands (e.g. switching a lamp on from sunset till midnight)
    • -
    • modular architecture
    • -
    • a lot of web frontends, choose your favorite
    • -
      -
    -See commandref.html for a detailed command -description and faq.html for the F.A.Q. -
- -

Links:

- -

Related projects:

- - -

Installation

-
    - -

    Linux driver

    - See - http://www.koeniglich.de/fhem/linux.html
    - For kernels older then 2.6.x apply the patch from the doc directory to your - kernel, recompile it and reboot or load/reload the ftdi_sio module. -
- -

Perl modules

-
    - You need perl with the Device::SerialPort ( - http://search.cpan.org/dist/Device-SerialPort/) - module. All other needed modules were present in my installation. - If this module reports Can't call method "opened" on an undefined - value... when starting the server, then you either may ignore - this message, or replace the mentioned line with:
    -    $self->{HANDLE}->close if (defined($self->{HANDLE}) &&
    -    	                       $self->{HANDLE}->opened);
    -
- -

Server installation

-
    -
  • Copy the file fhem.pl into your path (e.g. - /usr/local/bin), and the FHEM directory e.g. to - /usr/local/lib.
  • -
  • Make sure that you can access the serial USB - device (e.g. /dev/tts/USB0).
  • -
  • Create a configuration file (see the examples directory and - docs/commandref.html), and change at least the modpath - (/usr/local/lib) and define FHZ FHZ (/dev/tts/USB0) - parameters.
  • -
  • Delete the savefile if you are upgrading from an older version.
  • -
  • Start the server with fhem.pl <configfile>
  • -
- -

General Notes for Webfrontends:

-
    -
  • You don't have to install all of them, one is probably more than - enough :-)
  • -
  • The web server and the fhem server must be on the same host
  • -
  • Important: Make sure you add some protection (.htaccess, etc) - else everybody will be able to set your devices
  • -
- -

Web frontend 2 (webfrontend/pgm2, the simple one)

-
    - This frontend is CGI/CSS based. It has support for rooms, and FHT/KS300 logs.
    - Screenshots: overview, details - and KS300 temperature logs

    - -
      -
    • Copy the file fhemweb.pl and *.gplot to your cgi-bin directory - (/home/httpd/cgi-bin), the icons (*.gif) to your httpd icons - (/home/httpd/icons), and commandref.html to the html directory - (/home/httpd/html).
      - Note: The program looks for icons in the following order: - <device-name>.<state>, <device-name>, - <device-type>.<state>, <device-type>
      -
    • -
    • Edit fhemweb.pl, and check the "Config" section.
    • -
    • If you want to have access to plotted logs, then make sure that - gnuplot is installed and set the logtype for the FileLog device - (see commandref.html and example/04_log). -
    • -
    • Call <your-site>/cgi-bin/fhemweb.pl -
    - For special features like assigning devices to rooms see the README file. -
- -

Web frontend 3 (webfrontend/pgm3, the professional one)

-
    - This frontend is PHP based and was contributed by Martin Haas. - Look at the webfrontends/pgm3/docs for more documentation or at - this screenshot. A lot more details can be - found on Martins page: - http://www.martin-haas.de/fhz -

    - -
      -
    • Install PHP and enable it by commenting in the "LoadModule - phpX_module ..." directive in httpd.conf (perhaps it is already - done by your distro). Restart/reload httpd.
    • - -
    • Create a directory (e.g.: /home/httpd/html/pgm3) and copy all the - files from the webfrontend/pgm3 to this directory.
      Make sure that this - directory is writeable by the webserver!
    • - -
    • Edit index.php (/home/httpd/html/pgm3/index.php), and check the - required settings section
    • - -
    • If you want to have access to the FHT temperature logs, then: -
        -
      • Make sure gnuplot is installed
      • -
      • check the showgnuplot section in index.php
      • -
      • For each FHT device copy the file docs/gnuplot/gnuplot.wz to - gnuplot.fhtdevicename (to the /home/httpd/html/pgm3 directory) and - replace fht.log in this file with the absolute name of the current - logfile.
      • -
      -
    • Call <your-site>/pgm3/index.php
    • -
    -
- -

Web frontend 4 (webfrontend/pgm4, the template)

-
    - This frontend is PHP based and was contributed by Stefan Mayer. It won't work - for you without modification, it is meant as a template or as an example. See - the screenshot. To install: -
      -
    • Copy the directory webfrontend/pgm4 to your html directory.
    • -
    • Install/enable PHP (see the description for frontend3)
    • -
    • Call the program with http://webserver/pgm4/fs20.php
    • -
    - Now you can go on, and modify it to suit your needs :-) -
- - - -

License:

-
    - Copyright:
    -
      -
    • Rudolf Koenig (r dot koenig at koeniglich dot de)
    • -
    • Raoul Matthiessen (webfrontends/pgm1)
    • -
    • Martin Haas (webfrontends/pgm3)
    • -
    - License: GPL (v2) -
- - - -

Misc:

-
    - Thanks for Tosti for inspiration and numerous other people for help.
    -
- - - - + + + + +Home of FHEM + + + + + +

FHEM

+GPL'd server to access devices like FHZ1000/FHZ1300,EM1010PC,WS300,SCIVT. +Formerly known as fhz1000.pl + +

News (as of =DATE=, Version =VERS=)

+
    +
  • doc: linux.html (private udev-rules, not 50-..., ATTRS) +
  • bugfix: setting devices with "-" in their name did not work +
  • doc: fhem.pl and commandref.html (notifyon -> notify, correction + of examples) +
  • feature: modify command added +
  • feature: The "-" in the name is not allowed any more +
  • bugfix: disabled notify causes "uninitialized value" (STefan, 1.5) +
  • bugfix: deleted FS20 items are still logging (zombie) (Gerhard, 16.5) +
  • bugfix: added FS20S8, removed stty_parmrk (Martin, 24.5) +
  • feature: added archivedir/archivecmd to the FileLog +
  • feature: added EM1010PC/EM1000WZ/EM1000EM support +
  • bugfix: undefined messages for unknown HMS devs (Peter, 8.6) +
  • bugfix: em1010 and %oldvalue bugs (Peter, 9.6) +
  • bugfix: SCIVT solar controller (peterp, 1.7) +
  • bugfix: WS300 loglevel change (from 2 to 5 or device specific loglevel) +
  • feature: First steps for a Fritz!Box port. See the fritzbox.html +
  • feature: FHT lime-protection code discovered by Dirk (7.10) +
  • feature: Softwarebuffer for FHT devices with queuing unsent commands and repeating commands by transmission failure (Dirk 17.10) +
  • feature: FHT low temperatur warning and setting for lowtemp-offset (Dirk 17.10) +
  • change: Change naming for state into warnings (Dirk 17.10) +
+ + + +

Description

+
    +This program makes the FHZ1000/FHZ1300/WS300 USB devices sold by ELV, Conrad and +others useable with Linux. In fact, there is nothing Linux special in it, you +should be able to use it on other platforms as long as you can access the +hardware as a serial device.
    +The program runs as a server, you can control it via telnet, command line +program or TCP/IP directly, like the supplied web frontends do.

    + +Currently implemented features:
    +
      +
    • Via the FHZ module (with access to one or more FHZ1000/FHZ1300 device): +
        +
      • reading and sending FS20 events (on/off/dimming, timer commands)
        +
      • support of FS20 address features function group, local and global master +
      • reading and changing FHT80b parameters (temp, actuator, etc).
        + The FHT8b seems to work too. Note: the FHT8 wont work.
        + For FHT8b devices, FHEM have an internal software buffer for sending commands step by step. This buffer should prevent lost commands. In case of transmission failures FHEM tries to resend commands.
        +
      • +
      • reading HMS data (HMS100-T,-TF,-WD,-MG,-TFK and RM100-2)
      • +
      • reading KS300 data
      • +
      +
    • +
    • reading WS300 data, and up to 9 attached devices
    • +
    • reading EM1000WZ/EM1000EM data via an attached EM1010PC
    • +
    • reading an attached SCIVT device
    • +
    • logging events to files (or database), with regexp filters
    • +
    • notifying external programs or internal modules when receiving certain + events
    • +
    • timed commands (e.g. switching a lamp on from sunset till midnight)
    • +
    • modular architecture
    • +
    • a lot of web frontends, choose your favorite
    • +
      +
    +See commandref.html for a detailed command +description and faq.html for the F.A.Q. +
+ +

Links:

+ +

Related projects:

+ + +

Installation

+
    + +

    Linux driver

    + See + http://www.koeniglich.de/fhem/linux.html
    + For kernels older then 2.6.x apply the patch from the doc directory to your + kernel, recompile it and reboot or load/reload the ftdi_sio module. +
+ +

Perl modules

+
    + You need perl with the Device::SerialPort ( + http://search.cpan.org/dist/Device-SerialPort/) + module. All other needed modules were present in my installation. + If this module reports Can't call method "opened" on an undefined + value... when starting the server, then you either may ignore + this message, or replace the mentioned line with:
    +    $self->{HANDLE}->close if (defined($self->{HANDLE}) &&
    +    	                       $self->{HANDLE}->opened);
    +
+ +

Server installation

+
    +
  • Copy the file fhem.pl into your path (e.g. + /usr/local/bin), and the FHEM directory e.g. to + /usr/local/lib.
  • +
  • Make sure that you can access the serial USB + device (e.g. /dev/tts/USB0).
  • +
  • Create a configuration file (see the examples directory and + docs/commandref.html), and change at least the modpath + (/usr/local/lib) and define FHZ FHZ (/dev/tts/USB0) + parameters.
  • +
  • Delete the savefile if you are upgrading from an older version.
  • +
  • Start the server with fhem.pl <configfile>
  • +
+ +

General Notes for Webfrontends:

+
    +
  • You don't have to install all of them, one is probably more than + enough :-)
  • +
  • The web server and the fhem server must be on the same host
  • +
  • Important: Make sure you add some protection (.htaccess, etc) + else everybody will be able to set your devices
  • +
+ +

Web frontend 2 (webfrontend/pgm2, the simple one)

+
    + This frontend is CGI/CSS based. It has support for rooms, and FHT/KS300 logs.
    + Screenshots: overview, details + and KS300 temperature logs

    + +
      +
    • Copy the file fhemweb.pl and *.gplot to your cgi-bin directory + (/home/httpd/cgi-bin), the icons (*.gif) to your httpd icons + (/home/httpd/icons), and commandref.html to the html directory + (/home/httpd/html).
      + Note: The program looks for icons in the following order: + <device-name>.<state>, <device-name>, + <device-type>.<state>, <device-type>
      +
    • +
    • Edit fhemweb.pl, and check the "Config" section.
    • +
    • If you want to have access to plotted logs, then make sure that + gnuplot is installed and set the logtype for the FileLog device + (see commandref.html and example/04_log). +
    • +
    • Call <your-site>/cgi-bin/fhemweb.pl +
    + For special features like assigning devices to rooms see the README file. +
+ +

Web frontend 3 (webfrontend/pgm3, the professional one)

+
    + This frontend is PHP based and was contributed by Martin Haas. + Look at the webfrontends/pgm3/docs for more documentation or at + this screenshot. A lot more details can be + found on Martins page: + http://www.martin-haas.de/fhz +

    + +
      +
    • Install PHP and enable it by commenting in the "LoadModule + phpX_module ..." directive in httpd.conf (perhaps it is already + done by your distro). Restart/reload httpd.
    • + +
    • Create a directory (e.g.: /home/httpd/html/pgm3) and copy all the + files from the webfrontend/pgm3 to this directory.
      Make sure that this + directory is writeable by the webserver!
    • + +
    • Edit index.php (/home/httpd/html/pgm3/index.php), and check the + required settings section
    • + +
    • If you want to have access to the FHT temperature logs, then: +
        +
      • Make sure gnuplot is installed
      • +
      • check the showgnuplot section in index.php
      • +
      • For each FHT device copy the file docs/gnuplot/gnuplot.wz to + gnuplot.fhtdevicename (to the /home/httpd/html/pgm3 directory) and + replace fht.log in this file with the absolute name of the current + logfile.
      • +
      +
    • Call <your-site>/pgm3/index.php
    • +
    +
+ +

Web frontend 4 (webfrontend/pgm4, the template)

+
    + This frontend is PHP based and was contributed by Stefan Mayer. It won't work + for you without modification, it is meant as a template or as an example. See + the screenshot. To install: +
      +
    • Copy the directory webfrontend/pgm4 to your html directory.
    • +
    • Install/enable PHP (see the description for frontend3)
    • +
    • Call the program with http://webserver/pgm4/fs20.php
    • +
    + Now you can go on, and modify it to suit your needs :-) +
+ + + +

License:

+
    + Copyright:
    +
      +
    • Rudolf Koenig (r dot koenig at koeniglich dot de)
    • +
    • Raoul Matthiessen (webfrontends/pgm1)
    • +
    • Martin Haas (webfrontends/pgm3)
    • +
    + License: GPL (v2) +
+ + + +

Misc:

+
    + Thanks for Tosti for inspiration and numerous other people for help.
    +
+ + + + diff --git a/fhem/fhem.pl b/fhem/fhem.pl index 33586ccd5..8cdbfa453 100755 --- a/fhem/fhem.pl +++ b/fhem/fhem.pl @@ -134,7 +134,7 @@ my %intAt; # Internal at timer hash. my $intAtCnt=0; my $reread_active = 0; my $AttrList = "room comment"; -my $cvsid = '$Id: fhem.pl,v 1.26 2007-09-24 07:09:17 rudolfkoenig Exp $'; +my $cvsid = '$Id: fhem.pl,v 1.27 2007-10-19 09:29:00 dirkh Exp $'; $init_done = 0; @@ -1044,10 +1044,58 @@ CommandList($$) if($r) { $str .= "Readings:\n"; foreach my $c (sort keys %{$r}) { - $str .= sprintf(" %-19s %-15s %s\n",$r->{$c}{TIME},$c,$r->{$c}{VAL}); + my $val = ""; + if (defined($r->{$c}{VAL})) { + $val = $r->{$c}{VAL}; + } + $str .= sprintf(" %-19s %-15s %s\n",$r->{$c}{TIME},$c,$val); } } + $attr{FHZ}{softbuffer} = 1 if (!defined($attr{FHZ}{softbuffer})); + + if ($attr{FHZ}{softbuffer} == 1) { + my %lists = ( + "SENDBUFFER" => "Send buffer", + "NOTSEND" => "Send fail list", + ); + + foreach my $list (keys %lists) { + my $l = $d->{$list}; + if(keys (%{$l}) > 0) { + $str .= $lists{$list} .":\n"; + foreach my $c (sort keys %{$l}) { + my (undef, undef, $vC) = split (/:/, $c); +# $str .= sprintf(" %-19s %-15s %-10s %s\n",$l->{$c}{TIME},$c,$l->{$c}{VAL},$l->{$c}{SENDTIME}); + $str .= sprintf(" %-19s %-15s %s\n",$l->{$c}{TIME},$vC,$l->{$c}{VAL}); + } + } + + if ($defs{$param}->{NAME} eq "FHZ") { + $str .= $lists{$list} .":\n"; + + foreach my $d (sort keys %defs) { + my $p = $defs{$d}; + my $t = $p->{TYPE}; + + if ($t eq "FHT") { + + $l = $p->{$list}; + if(keys (%{$l}) > 0) { + foreach my $c (sort keys %{$l}) { + my (undef, undef, $vC) = split (/:/, $c); + my $val = ""; + if (defined($l->{$c}{VAL})) { + $val = $l->{$c}{VAL}; + } + $str .= sprintf(" %-19s %-15s %-15s %s\n",$l->{$c}{TIME},$p->{NAME},$vC,$val); + } + } + } + } + } + } + } } return $str;