FritzBox: ActiveDevices: Unterschied zwischen den Versionen

Aus FHEMWiki
(Die Seite wurde neu angelegt: „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 …“)
 
Keine Bearbeitungszusammenfassung
Zeile 2: Zeile 2:


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.
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 ==
== fhem.cfg ==
<nowiki>define MyAttendance dummy
 
<pre>define MyAttendance dummy
attr MyAttendance icon icoHouse.png
attr MyAttendance icon icoHouse.png
attr MyAttendance room WhoIsAtHome
attr MyAttendance room WhoIsAtHome
define WLAN notify WLAN {FBWLanDevActive('MyWLANDeviceName', "MyAttendance")}  
define WLAN notify WLAN {FBWLanDevActive('MyWLANDeviceName', "MyAttendance")}  
define search_for_MyWLANDeviceName at +*00:05:00 trigger WLAN</nowiki>
define search_for_MyWLANDeviceName at +*00:05:00 trigger WLAN
</pre>
 
== Sub z.B. 99 MyUtils.pm ==
== Sub z.B. 99 MyUtils.pm ==
<nowiki>sub FBWLanDevActive($$) {
<pre>
sub FBWLanDevActive($$) {
  my ($net_device1)=@_[0];
  my ($net_device1)=@_[0];
  my $myLength=length($net_device1);
  my $myLength=length($net_device1);
Zeile 30: Zeile 35:
  if ($status == 1) {$attendance="Anwesend";}else{$attendance="Abwesend";}
  if ($status == 1) {$attendance="Anwesend";}else{$attendance="Abwesend";}
  if(Value("@_[1]") ne $attendance){fhem "set @_[1] $attendance"}
  if(Value("@_[1]") ne $attendance){fhem "set @_[1] $attendance"}
}</nowiki>
}
</pre>
 
== Test ==
== Test ==
Eingabe im fhem Frontend:
Eingabe im fhem Frontend:
<pre>
{ FBWLanDevActive('MyLANDeviceName', "MyAttendance")}
{ FBWLanDevActive('MyLANDeviceName', "MyAttendance")}
</pre>


== Hinweis ==
== Hinweis ==
Zeile 43: Zeile 52:


== Links ==
== Links ==
[[Kategorie:FritzBox]]
[[Kategorie:Code Snippets]]

Version vom 11. Mai 2013, 10:16 Uhr

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