FritzBox: ActiveDevices

Aus FHEMWiki

This is a derivate of the function FBWlanStat published in "FritzBox: WhoIsAtHome". Thanks to the original autor

Stellt fest, ob ein bestimmtes Device in der FB angemeldet ist. For a WLAN device it can take about 10 minutes before the FB knows it left.

fhem.cfg

define MyAttendance dummy
attr MyAttendance icon icoHouse.png
attr MyAttendance room WhoIsAtHome
define WLAN notify WLAN {FBWLanDevActive('MyWLANDeviceName', "MyAttendance")} 
define search_for_MyWLANDeviceName at +*00:05:00 trigger WLAN

Sub z.B. 99 MyUtils.pm

sub FBWLanDevActive($$) {
 my ($net_device1)=@_[0];
 my $myLength=length($net_device1);
 my $number=0;
 my $status=0;
 my $net_device="";
 my $net_device2="";
 my $attendance="";
 while($number <= 25){
  $net_device=
      qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/name);
  $net_device2=substr($net_device, 0, $myLength);
  if($net_device2 eq $net_device1){
  $status=
     qx(/usr/bin/ctlmgr_ctl r landevice settings/landevice$number/active);
   if ($status == 1) {last;}
  }
  $number++;
 }
 if ($status == 1) {$attendance="Anwesend";}else{$attendance="Abwesend";}
 if(Value("@_[1]") ne $attendance){fhem "set @_[1] $attendance"}
}

Test

Eingabe im fhem Frontend:

{ FBWLanDevActive('MyLANDeviceName', "MyAttendance")}

Hinweis

Benutzername (hier'MyLANDeviceName') aus dem FB Frontend ermitteln. It is sufficient to specify the first unique part of the LanDevice. The routine searches all devices if it can find at least 1 device of which the name starts with "MyLanDevicename".

Example: if the devicename is HTC-Harry or HTC-Harry-1, a call with FBWLanDevActive('HTC-Harry', "GSMHarry") or even FBWLanDevActive('HTC', "GSMHarry") is sufficient if this is the only device with a name starting with "HTC"

Links