diff --git a/fhem/contrib/DoorPi/70_DoorPi.pm b/fhem/contrib/DoorPi/70_DoorPi.pm index b54cce0c4..ba7ae28f1 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.0beta8"; +my $version = "1.0beta9"; #-- these we may get on request my %gets = ( @@ -123,6 +123,7 @@ sub DoorPi_Define($$) { $init_done = 1; readingsBeginUpdate($hash); readingsBulkUpdate($hash,"state","Initialized"); + readingsBulkUpdate($hash,"lockstate","Unknown"); readingsBulkUpdate($hash,"door","Unknown"); readingsEndUpdate($hash,1); @@ -302,17 +303,83 @@ sub DoorPi_Set ($@) { Log 1,"[DoorPi_Set] Error: attribute target$value does not exist"; return; } - #-- door opening - either from FHEM, or just as message from DoorPi + + #-- Door opening - rather complicated }elsif( ($key eq "$door")||($key eq "door") ){ + my $lockstate = ReadingsVal($name,"lockstate",undef); + + #-- from FHEM: door opening, forward to DoorPi if( $value eq "opened" ){ - $v=DoorPi_Cmd($hash,"dooropen"); - Log 1,"[DoorPi_Set] sent dooropen command to DoorPi"; - if(AttrVal($name, "dooropencmd",undef)){ - fhem(AttrVal($name, "dooropencmd",undef)); + if( $lockstate eq "unlocked" ){ + $v=DoorPi_Cmd($hash,"dooropen"); + Log 1,"[DoorPi_Set] sent dooropen command to DoorPi"; + if(AttrVal($name, "dooropencmd",undef)){ + fhem(AttrVal($name, "dooropencmd",undef)); + } + readingsSingleUpdate($hash,$door,"opened",1); + }else{ + Log 1,"[DoorPi_Set] opening of door not possible, is locked"; } - readingsSingleUpdate($hash,$door,"opened",1); + + #-- from DoorPi: door has to be unlocked if necessary + }elsif( $value eq "unlockandopen" ){ + #-- need to unlock the door now + 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"; + readingsSingleUpdate($hash,"lockstate","unlocked",1); + readingsSingleUpdate($hash,$door,"unlocked",1); + $v=DoorPi_Cmd($hash,"doorunlocked"); + }else{ + Log 1,"[DoorPi_Set] received unlockandopen command from DoorPi, but no FHEM doorunlock command"; + } + }elsif( $lockstate eq "unlocked" ){ + Log 1,"[DoorPi_Set] received unlockandopen command from DoorPi, but is already unlocked"; + }else{ + #-- error message + Log 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 + if( $lockstate eq "unlocked" ){ + if( AttrVal($name, "doorlockcmd",undef) ){ + fhem(AttrVal($name, "doorlockcmd",undef)); + Log 1,"[DoorPi_Set] received softlock command from DoorPi and executed FHEM doorlock command"; + readingsSingleUpdate($hash,"lockstate","locked",1); + readingsSingleUpdate($hash,$door,"locked",1); + $v=DoorPi_Cmd($hash,"doorlocked"); + }else{ + Log 1,"[DoorPi_Set] received softlock command from DoorPi, but no FHEM doorlock command"; + } + }elsif( $lockstate eq "locked" ){ + Log 1,"[DoorPi_Set] received softlock command from DoorPi, but is already locked"; + }else{ + #-- error message + Log 1,"[DoorPi_Set] received softlock command from DoorPi, but uncertain lockstate"; + return; + } + #-- from FHEM: unlocking the door + }elsif( $value eq "unlocked" ){ + #-- careful here - + # a third parameter indicates that the door is already unlocked + # because the command has been issued by the lock itself + if( (AttrVal($name, "doorunlockcmd",undef)) && (!$a[0]) ){ + fhem(AttrVal($name, "doorunlockcmd",undef)); + Log 1,"[DoorPi_Set] sent doorunlocked command to DoorPi and executed FHEM doorunlock command"; + }else{ + Log 1,"[DoorPi_Set] sent doorunlocked command to DoorPi and NOT executed FHEM doorunlock command"; + } + readingsSingleUpdate($hash,"lockstate","unlocked",1); + readingsSingleUpdate($hash,$door,"unlocked",1); + $v=DoorPi_Cmd($hash,"doorunlocked"); + #-- from FHEM: locking the door }elsif( $value eq "locked" ){ - $v=DoorPi_Cmd($hash,"doorlocked"); #-- careful here - # a third parameter indicates that the door is already unlocked if( (AttrVal($name, "doorlockcmd",undef)) && (!$a[0]) ){ @@ -321,19 +388,11 @@ sub DoorPi_Set ($@) { }else{ Log 1,"[DoorPi_Set] sent doorlocked command to DoorPi and NOT executed extra FHEM doorlock command"; } + readingsSingleUpdate($hash,"lockstate","locked",1); readingsSingleUpdate($hash,$door,"locked",1); - }elsif( $value eq "unlocked" ){ - $v=DoorPi_Cmd($hash,"doorunlocked"); - #-- careful here - - # a third parameter indicates that the door is already unlocked - if( (AttrVal($name, "doorunlockcmd",undef)) && (!$a[0]) ){ - fhem(AttrVal($name, "doorunlockcmd",undef)); - Log 1,"[DoorPi_Set] sent doorunlocked command to DoorPi and executed extra FHEM doorunlock command"; - }else{ - Log 1,"[DoorPi_Set] sent doorunlocked command to DoorPi and NOT executed extra FHEM doorunlock command"; - } - readingsSingleUpdate($hash,$door,"unlocked",1); + $v=DoorPi_Cmd($hash,"doorlocked"); } + #-- snapshot }elsif( $key eq "$snapshot" ){ $v=DoorPi_Cmd($hash,"snapshot"); diff --git a/fhem/contrib/DoorPi/FHEMHelper.sh.safe b/fhem/contrib/DoorPi/FHEMHelper.sh.safe index 6157274e4..5f71bb9ca 100644 --- a/fhem/contrib/DoorPi/FHEMHelper.sh.safe +++ b/fhem/contrib/DoorPi/FHEMHelper.sh.safe @@ -11,10 +11,10 @@ checkstream() { } FHEMDP="A.Door.Pi" -FHEMIP="192.168.0.90" +FHEMIP="xxx" FHEM="http://$FHEMIP:8083/fhem?XHR=1&cmd.$FHEMDP" HOME="/home/doorpi" -default_target="XXXX" +default_target="" case $1 in @@ -29,9 +29,9 @@ case $1 in fi ;; - dooropen) + doorunlockandopen) curl "$FHEM=set%20GalaxyTab%20ttsSay%20Ein%20Bewohner%20betritt%20das%20Haus" & - curl "$FHEM=set%20$FHEMDP%20door%20opened" & + curl "$FHEM=set%20$FHEMDP%20door%20unlockandopen" & ;; wrongid) @@ -40,7 +40,7 @@ case $1 in ;; softlock) - curl "$FHEM=set%20$FHEMDP%20door%20locked" & + curl "$FHEM=set%20$FHEMDP%20door%20softlock" & ;; call) diff --git a/fhem/contrib/DoorPi/doorpi.ini.safe b/fhem/contrib/DoorPi/doorpi.ini.safe index a0c04858b..e58160edb 100644 --- a/fhem/contrib/DoorPi/doorpi.ini.safe +++ b/fhem/contrib/DoorPi/doorpi.ini.safe @@ -54,27 +54,6 @@ guests = dashboard [DTMF] "#" = out:door,1,0,3 -####################### Events ####################### -[EVENT_OnStartup] -10 = sleep:1 -20 = os_execute:/home/doorpi/FHEMHelper call init - -[EVENT_BeforeSipPhoneMakeCall] -10 = os_execute:/home/doorpi/FHEMHelper call startup -20 = take_snapshot - -[EVENT_OnCallStateDisconnect] -10 = os_execute:/home/doorpi/FHEMHelper call end - -[EVENT_OnCallStateDismissed] -10 = os_execute:/home/doorpi/FHEMHelper call dismissed - -[EVENT_OnCallStateReject] -10 = os_execute:/home/doorpi/FHEMHelper call rejected - -[EVENT_OnTimeMinuteEvery5] -10=statuswatchdog:/tmp/doorpi.watchdog - ####################### SIP phone ####################### [SIP-Phone] identity = DoorPi @@ -82,9 +61,9 @@ local_port = 5060 firewallpolicy = PolicyNoFirewall # sipphonetyp = linphone -sipserver_password = xxxxxx -sipserver_realm = cccc -sipserver_server = ccccc +sipserver_password = xxxx +sipserver_realm = fritz.box +sipserver_server = xxxx sipserver_username = 620 stun_server = # @@ -108,6 +87,28 @@ video_device = StaticImage: Static picture video_display_enabled = False video_size = vga +####################### Events ####################### +[EVENT_OnStartup] +10 = sleep:1 +20 = os_execute:/home/doorpi/FHEMHelper.sh call init + +[EVENT_BeforeSipPhoneMakeCall] +10 = os_execute:/home/doorpi/FHEMHelper.sh call startup +20 = take_snapshot +#30 = mailto:haus271828@henning-weingarten.de,DoorPi,DoorPi initiating call + +[EVENT_OnCallStateDisconnect] +10 = os_execute:/home/doorpi/FHEMHelper.sh call end + +[EVENT_OnCallStateDismissed] +10 = os_execute:/home/doorpi/FHEMHelper.sh call dismissed + +[EVENT_OnCallStateReject] +10 = os_execute:/home/doorpi/FHEMHelper.sh call rejected + +[EVENT_OnTimeMinuteEvery5] +10=statuswatchdog:/tmp/doorpi.watchdog + ####################### Keyboards ############################## [keyboards] webservice = filesystem @@ -139,7 +140,7 @@ button2 = sleep:0 #-- communicate to FHEM that a snapshot has been taken [EVENT_OnKeyPressed_webservice.snapshot] 10 = take_snapshot -20 = os_execute:/home/doorpi/FHEMHelper call snapshot +20 = os_execute:/home/doorpi/FHEMHelper.sh call snapshot #-- start video stream [EVENT_OnKeyPressed_webservice.streamon] @@ -151,18 +152,18 @@ button2 = sleep:0 #-- obtain the target call number from FHEM [EVENT_OnKeyPressed_webservice.gettarget] -10 = os_execute:/home/doorpi/FHEMHelper gettarget +10 = os_execute:/home/doorpi/FHEMHelper.sh gettarget #-- purge all files older than current PID file [EVENT_OnKeyPressed_webservice.purge] -10 = os_execute:/home/doorpi/FHEMHelper purge +10 = os_execute:/home/doorpi/FHEMHelper.sh purge #-- clear all files [EVENT_OnKeyPressed_webservice.clear] -10 = os_execute:/home/doorpi/FHEMHelper clear +10 = os_execute:/home/doorpi/FHEMHelper.sh clear [EVENT_OnKeyPressed_webservice.button1] -10 = os_execute:/home/doorpi/FHEMHelper sabotage +10 = os_execute:/home/doorpi/FHEMHelper.sh sabotage [EVENT_OnKeyPressed_webservice.button2] 10 = file_call_value:/home/doorpi/calltarget @@ -189,30 +190,29 @@ pull_up_down = PUD_UP #-- DoorOpen pin from Arduino [EVENT_OnKeyPressed_onboardpins.1] 10 = out:dashlight,1 -20 = os_execute:/home/doorpi/FHEMHelper dooropen +20 = os_execute:/home/doorpi/FHEMHelper.sh doorunlockandopen 30 = os_execute:aplay -D plughw:1,0 /home/doorpi/sounds/067_willkommen.wav -40 = out:door,1,0,3 -50 = out:dashlight,0 +40 = out:dashlight,0 #-- WrongID pin from Arduino [EVENT_OnKeyPressed_onboardpins.4] 10 = out:dashlight,1 -20 = os_execute:/home/doorpi/FHEMHelper wrongid +20 = os_execute:/home/doorpi/FHEMHelper.sh wrongid 30 = take_snapshot 40 = out:dashlight,0 #-- LockState pin from Arduino - FHEM will transform softlock into hardlock [EVENT_OnKeyPressed_onboardpins.5] -10 = os_execute:/home/doorpi/FHEMHelper softlock +10 = os_execute:/home/doorpi/FHEMHelper.sh softlock #-- Movement detection [EVENT_OnKeyPressed_onboardpins.6] 10 = out:dashlight,1,0,60 -20 = os_execute:/home/doorpi/FHEMHelper movement +20 = os_execute:/home/doorpi/FHEMHelper.sh movement #-- Sabotage detection [EVENT_OnKeyPressed_onboardpins.7] -10 = os_execute:/home/doorpi/FHEMHelper sabotage +10 = os_execute:/home/doorpi/FHEMHelper.sh sabotage