diff --git a/fhem/FHEM/73_PRESENCE.pm b/fhem/FHEM/73_PRESENCE.pm index a10bc92ac..0d4f6a686 100755 --- a/fhem/FHEM/73_PRESENCE.pm +++ b/fhem/FHEM/73_PRESENCE.pm @@ -309,24 +309,27 @@ PRESENCE_Attr(@) { if($a[3] eq "0") { - $hash->{helper}{DISABLED} = 0; - readingsSingleUpdate($hash, "state", "defined",0); + + readingsSingleUpdate($hash, "state", "defined",0) if(exists($hash->{helper}{DISABLED}) and $hash->{helper}{DISABLED} == 1); if(defined($hash->{DeviceName})) { if(defined($hash->{FD})) { - PRESENCE_DoInit($hash); + PRESENCE_DoInit($hash) if(exists($hash->{helper}{DISABLED})); + $hash->{helper}{DISABLED} = 0; } else { + $hash->{helper}{DISABLED} = 0; DevIo_OpenDev($hash, 0, "PRESENCE_DoInit"); } } else { + $hash->{helper}{DISABLED} = 0; PRESENCE_StartLocalScan($hash); } - + $hash->{helper}{DISABLED} = 0; } elsif($a[3] eq "1") { @@ -345,21 +348,24 @@ PRESENCE_Attr(@) } elsif($a[0] eq "del" && $a[2] eq "disable") { - $hash->{helper}{DISABLED} = 0; - readingsSingleUpdate($hash, "state", "defined",0); + + readingsSingleUpdate($hash, "state", "defined",0) if(exists($hash->{helper}{DISABLED}) and $hash->{helper}{DISABLED} == 1); if(defined($hash->{DeviceName})) { if(defined($hash->{FD})) { - PRESENCE_DoInit($hash); + PRESENCE_DoInit($hash) if(exists($hash->{helper}{DISABLED})); + $hash->{helper}{DISABLED} = 0; } else { + $hash->{helper}{DISABLED} = 0; DevIo_OpenDev($hash, 0, "PRESENCE_DoInit"); } } else { + $hash->{helper}{DISABLED} = 0; PRESENCE_StartLocalScan($hash); } } @@ -438,14 +444,11 @@ PRESENCE_DoInit($) my ($hash) = @_; - unless($hash->{helper}{DISABLED}) + if( not exists($hash->{helper}{DISABLED}) or exists($hash->{helper}{DISABLED}) and $hash->{helper}{DISABLED} == 1) { + readingsSingleUpdate($hash, "state", "active",0); DevIo_SimpleWrite($hash, $hash->{ADDRESS}."|".$hash->{TIMEOUT_NORMAL}."\n", 0); } - else - { - readingsSingleUpdate($hash, "state", "disabled",1); - } }