From 5f7e4ea62f29f21d47f5d6b76d2e2aebf8d8e51b Mon Sep 17 00:00:00 2001 From: pahenning <> Date: Sat, 10 Dec 2016 04:35:18 +0000 Subject: [PATCH] 95_Alarm.pm: Bugfix 70_DoorPi.pm: Neue Version git-svn-id: https://svn.fhem.de/fhem/trunk@12733 2b470e98-0d58-463d-a4d8-8e2adae1ed80 --- fhem/FHEM/95_Alarm.pm | 20 ++++---- fhem/contrib/DoorPi/70_DoorPi.pm | 78 +++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 26 deletions(-) diff --git a/fhem/FHEM/95_Alarm.pm b/fhem/FHEM/95_Alarm.pm index ff64471ba..caf108007 100644 --- a/fhem/FHEM/95_Alarm.pm +++ b/fhem/FHEM/95_Alarm.pm @@ -40,7 +40,7 @@ my $alarmname = "Alarms"; # link text my $alarmhiddenroom = "AlarmRoom"; # hidden room my $alarmpublicroom = "Alarm"; # public room my $alarmno = 8; -my $alarmversion = "2.81"; +my $alarmversion = "2.82"; ######################################################################################### # @@ -156,15 +156,15 @@ sub Alarm_CreateEntry($) { } #-- recover state from stored readings for( my $level=0;$level<$alarmno;$level++ ){ - my $val = $hash->{READINGS}{"level".$level}{VAL}; - if( $val eq "disarmed" ){# - CommandAttr (undef,$name.' level'.$level.'xec disarmed'); - }elsif( $val eq "armed" ){ - CommandAttr (undef,$name.' level'.$level.'xec armed'); - }else{ - Log3 $hash,1,"[Alarm $level] has undefined save data, disarming"; - CommandAttr (undef,$name.' level'.$level.'xec disarmed'); - } + my $val = ReadingsVal($name,"level".$level,""); + if( $val eq "disarmed" ){# + CommandAttr (undef,$name.' level'.$level.'xec disarmed'); + }elsif( $val eq "armed" ){ + CommandAttr (undef,$name.' level'.$level.'xec armed'); + }else{ + Log3 $hash,1,"[Alarm $level] has undefined save data $val, disarming"; + CommandAttr (undef,$name.' level'.$level.'xec disarmed'); + } } my $mga = Alarm_getstate($hash)." Keine Störung"; readingsSingleUpdate( $hash, "state", $mga, 1 ); diff --git a/fhem/contrib/DoorPi/70_DoorPi.pm b/fhem/contrib/DoorPi/70_DoorPi.pm index 09d7fb3a3..9ab6c120f 100644 --- a/fhem/contrib/DoorPi/70_DoorPi.pm +++ b/fhem/contrib/DoorPi/70_DoorPi.pm @@ -41,7 +41,7 @@ use vars qw{%attr %defs}; sub Log($$); #-- globals on start -my $version = "1.6"; +my $version = "1.8"; #-- these we may get on request my %gets = ( @@ -74,7 +74,7 @@ sub DoorPi_Initialize ($) { $hash->{AttrList}= "verbose ". "language:de,en ringcmd ". - "doorbutton dooropencmd doorlockcmd doorunlockcmd ". + "doorbutton dooropencmd doorlockcmd doorunlockcmd dooropendly ". "lightbutton lightoncmd lighttimercmd lightoffcmd ". "snapshotbutton streambutton ". "dashlightbutton iconpic iconaudio ". @@ -221,9 +221,15 @@ sub DoorPi_Get ($@) { sub DoorPi_Set ($@) { my ($hash, @a) = @_; - #-- only hash as parameter when acting as timer callback + #-- if only hash as parameter, this is acting as timer callback if( !@a ){ - @a=($hash->{NAME},"light","off"); + Log 1,"[DoorPi_Set] delayed action started with ".$hash->{DELAYED}; + if( $hash->{DELAYED} eq "light"){ + @a=($hash->{NAME},"light","off"); + }elsif( $hash->{DELAYED} eq "door_time"){ + @a=($hash->{NAME},"door","opened"); + } + $hash->{DELAYED} = ""; } my $name = shift @a; @@ -231,7 +237,7 @@ sub DoorPi_Set ($@) { #-- commands my $door = AttrVal($name, "doorbutton", "door"); - my $doorsubs = "open"; + my $doorsubs = "opened"; $doorsubs .= ",locked" if(AttrVal($name, "doorlockcmd",undef)); $doorsubs .= ",unlocked" @@ -339,6 +345,10 @@ sub DoorPi_Set ($@) { #-- from FHEM: door opening, forward to DoorPi if( $value eq "opened" ){ if( $lockstate eq "unlocked" ){ + if( $hash->{DELAYED} eq "door_event"){ + fhem("delete dooropendelay"); + $hash->{DELAYED} = ""; + } $v=DoorPi_Cmd($hash,"dooropen"); Log 1,"[DoorPi_Set] sent dooropen command to DoorPi"; if(AttrVal($name, "dooropencmd",undef)){ @@ -346,35 +356,49 @@ sub DoorPi_Set ($@) { } readingsSingleUpdate($hash,$door,"opened",1); }else{ - Log 1,"[DoorPi_Set] opening of door not possible, is locked"; + Log3 $name, 1,"[DoorPi_Set] opening of door not possible, is locked"; } #-- from DoorPi: door has to be unlocked if necessary }elsif( $value eq "unlockandopen" ){ - #-- need to unlock the door now + + #-- unlocking the door now, delayed opening if( $lockstate eq "locked" ){ if( AttrVal($name, "doorunlockcmd",undef) ){ fhem(AttrVal($name, "doorunlockcmd",undef)); - Log 1,"[DoorPi_Set] received unlockandopen command from DoorPi and executed FHEM doorunlock command"; + Log3 $name,5,"[DoorPi_Set] received unlockandopen command from DoorPi and executed FHEM doorunlock command"; readingsSingleUpdate($hash,"lockstate","unlocked",1); readingsSingleUpdate($hash,$door,"unlocked",1); - $v=DoorPi_Cmd($hash,"doorunlocked"); + $v=DoorPi_Cmd($hash,"doorunlocked"); + my $dly=AttrVal($name, "dooropendly",5); + #-- delay by fixed number of seconds + if( $dly =~ /\d+/ ){ + $hash->{DELAYED} = "door_time"; + InternalTimer(gettimeofday() + $dly, "DoorPi_Set", $hash,1); + #-- delay by event + }else{ + $hash->{DELAYED} = "door_event"; + fhem(" define dooropendelay notify $dly set $name $door opened"); + } }else{ - Log 1,"[DoorPi_Set] received unlockandopen command from DoorPi, but no FHEM doorunlock command"; + Log3 $name,5,"[DoorPi_Set] received unlockandopen command from DoorPi, but no FHEM doorunlock command"; } + + #-- no unlocking necessary, immediate door opening }elsif( $lockstate eq "unlocked" ){ - Log 1,"[DoorPi_Set] received unlockandopen command from DoorPi, but is already unlocked"; + Log3 $name,5,"[DoorPi_Set] received unlockandopen command from DoorPi, but is already unlocked"; + $v=DoorPi_Cmd($hash,"dooropen"); + + #-- error message }else{ - #-- error message - Log 1,"[DoorPi_Set] received unlockandopen command from DoorPi, but uncertain lockstate"; + Log3 $name, 1,"[DoorPi_Set] received unlockandopen command from DoorPi, but uncertain lockstate"; return; } - #-- Now open the door by DoorPi - $v=DoorPi_Cmd($hash,"dooropen"); #-- from DoorPi: door has to be locked if necessary }elsif( $value eq "softlock" ){ - #-- need to lock the door now + + #-- locking the door now if( $lockstate eq "unlocked" ){ if( AttrVal($name, "doorlockcmd",undef) ){ fhem(AttrVal($name, "doorlockcmd",undef)); @@ -458,6 +482,7 @@ sub DoorPi_Set ($@) { } readingsSingleUpdate($hash,$light,"on",1); #-- Intiate turning off light + $hash->{DELAYED} = "light"; InternalTimer(gettimeofday() + 60, "DoorPi_Set", $hash,1); } #-- dashboard lighting @@ -1375,6 +1400,7 @@ sub DoorPi_list($;$){
Returns the version number of the FHEM DoorPi module

Attributes

+
Basic DoorPi actions
+
Basic FHEM actions
+ Door locking and unlocking is executed by FHEM only. After an unlocking action, the following + opening action will be delayed either by a fixed number of seconds or by waiting for an event. +