AVM Smarthome Devices wie Fritz!Powerline 546e Auslesen und Schalten

Du hast leider ein wenig zuviel auskommentiert.
Bitte wie von mir beschrieben auch nur das auskommentieren

/* 
//check varable is right 
$name='fritz_aha_reader'; 
if ($name != "Switch Status") { 
  IPS_LogMessage("FritzAHA Switch","Error: Action from wrong variable ".$_IPS['VARIABLE']); 
  return; 
}
*/ 

Das dann überflüssige schliessende Kommentarzeichen am Ende vor der Funktion nicht vergessen wieder zu entfernen.
So hast Du auch alle Funktionen auskommentiert. Im Logfile wird sich das Script auf jeden Fall verewigen, wenn es angesprochen wird.

Das auszukommentieren war mein erster Versuch,

dann kommt allerdings als Meldung im Log das hier:

<?php
/*
switch a Fritz AHA Device (Fritz Powerline 546E, Fritz Dect200) from IPSymcon
http://www.tdressler.net/ipsymcon
V2.2 16.01.2016
see also
http://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf
http://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AHA-HTTP-Interface.pdf
*/
if (!function_exists('mb_convert_encoding')) {
   IPS_LogMessage ("FritzAHA Switch","Error:Need mbstring_extension!
");
   return;
}
if (!function_exists('simplexml_load_string')) {
   IPS_LogMessage("FritzAHA Switch","Error:Need SimpleXML functions(simplexml_load_string)!
");
   return;
}

/* config section, pls adopt this for your device
credential array array('<1.host/ip>' =>array('user'=>'<login name1>','password'=>'<secret>')
                      ,'<2.host/ip>' =>array('user'=>'<login name2>','password'=>'<secret2>')
                      ,..
                     );
if no login name is needed/applicable, set the name to an empty string ('')!
*/
$logins=array('172.16.1.2'=>array('user'=>'','password'=>'start') //sample entry for fritzbox
/*           ,'192.168.170.211'=>array('user'=>'','password'=>'xyz123') //sample entry for another host,maybe fritz546 */
        );

$id=31887 /*[FRITZ Smarthome\ TV Beleuchtung\Status]*/; //test variable for execute
/* end config section */

//check caller
$sender=$_IPS['SENDER'];
switch ($sender) {
case "WebFront":
  $me=$_IPS['VARIABLE'];
  $val=$_IPS['VALUE'];
   SetValue($me, $val); //doing will be done by variable change
   return;
  break; //not reached
case "Variable":
  $me=$_IPS['VARIABLE'];
  $val=$_IPS['VALUE'];
  break;
case "Execute":
  $me=$id;
  $val=@GetValue($me);
  break;
default:
  IPS_LogMessage("FritzAHA Switch", "Error: unknown Sender '$sender'");
  return;
}

$state=$val;
IPS_LogMessage("FritzAHA Switch","Switch ID ".$me." to ".($state?'ON':'OFF'));

/*
//check varable is right
$name='fritz_aha_reader';
if ($name != "Switch Status") {
  IPS_LogMessage("FritzAHA Switch","Error: Action from wrong variable ".$_IPS['VARIABLE']);
  return;
}
*/
//get parameter from IPS
$parent=IPS_GetParent($me);
$host=getVarValue('Device Host',$parent);
$ain=getVarValue('Device AIN',$parent);

//checks
if (!$host || !$ain) {
  IPS_LogMessage("FritzAHA Switch","Error: Parameter host($host) or AIN($ain) missed");
  return;
}

//get password using ID host
$username=$logins[$host]['user'];
$password=$logins[$host]['password'];
if (!$password) {
  IPS_LogMessage("FritzAHA Switch","Error: password for '$host' not defined");
  return;
}

//build urls and login
$loginurl="http://".$host."/login_sid.lua";//login_sid.lua for fritzos 5.50+
$ahaurl="http://".$host."/webservices/homeautoswitch.lua";//api url
$sid=get_sid($loginurl,$username,$password);
if (!isset($sid)) {
  IPS_LogMessage("FritzAHA Switch", "Error: Login invalid or failed");
  return;
}

//query actual state
$url=$ahaurl.'?ain='.rawurlencode($ain).'&sid='.$sid.'&switchcmd=getswitchstate';
$answer=chop(@file_get_contents($url));
$response=$http_response_header[0];
if (!preg_match("/200\s+OK$/",$response)){
  IPS_LogMessage("FritzAHA Switch", "Error: Query ($url) failed, Response: $response ");
  return;
}
IPS_LogMessage("FritzAHA Switch", "Actor $ain actual state:".($answer?"ON":"OFF"));
if ((($answer=="1")!=$state) || ($sender == "Execute")) {
//execute query
  $cmd=($state==true)?'setswitchon':'setswitchoff';
  IPS_LogMessage("FritzAHA Switch", "Actor $ain execute cmd:".$cmd);
  $url=$ahaurl.'?ain='.rawurlencode($ain).'&sid='.$sid.'&switchcmd='.$cmd;
  $answer=@file_get_contents($url);
  $response=$http_response_header[0];
  if (!preg_match("/200\s+OK$/",$response)) {
     IPS_LogMessage("FritzAHA Switch", "Error: Update Actor $ain failed, Response: $response");
     return;
  }
  IPS_LogMessage("FritzAHA Switch", "New Status for Actor $ain:".($answer?"ON":"OFF"));
}else{
   IPS_LogMessage("FritzAHA Switch", "No need to switch Actor $ain");
}

//-------------------------------------------------------------------------------
/**
  * login into fritz and get sid
  * @param string loginurl url for accessing device
  * @param string username Username to login, if needed or empty
  * @param string password password for login
  * @return string sid
  */
function get_sid ($loginurl,$username,$password) {

 if (is_null($username)) $username='';
 $sid='';
 // get challenge string
 $http_response = file_get_contents($loginurl);
 $response=$http_response_header[0];
 if (preg_match("/200\s+OK$/",$response)) {
  $xml = simplexml_load_string($http_response);
  $challenge=(string)$xml->Challenge;
  $sid=(string)$xml->SID;
 }else{
   IPS_LogMessage("FritzAHA Switch", "Error: GetSid with $loginurl failed, Response: $response");
 }
 if ((strlen($sid)>0) && (preg_match("/^[0]+$/",$sid)) && $challenge) {
     //sid is null, got challenge
    $sid="";
    //build password response
    $pass=$challenge."-".$password;
    //UTF-16LE encoding as required
    $pass=mb_convert_encoding($pass, "UTF-16LE");
    //md5hash on top
    $md5 = md5($pass);
    //final answer string
    $challenge_response = $challenge."-".$md5;
    //send to box
    $url=$loginurl."?username=".$username."&response=".$challenge_response;
   $http_response = file_get_contents($url);
   //check answer
   $xml = simplexml_load_string($http_response);
   $sid=(string)$xml->SID;
   if ((strlen($sid)>0) && !preg_match("/^[0]+$/",$sid)) {
            //is not null, bingo!
            return $sid;
   }

 }else {
  //use existing sid if $sid matches an hex string
  if ((strlen($sid)>0) && (preg_match("/^[0-9a-f]+$/",$sid))) return $sid;
 }
 return null;
}//function

//-------------------------------------------------------------------------------
/**
* get varable value by name referencing parent
* @param string $name Name of variable
* @param integer $par ID of parent (category)
* @return variant value of selected variable or null
*/
function getVarValue($name,$par) {
  $value=null;
  $vid = @IPS_GetVariableIDByName($name, $par);
  if ($vid)
    $value=GetValue($vid);
  return $value;
}
?>

Gut. Damit kann ich wieder was anfangen
Bitte die Zeilen

$host=getVarValue('Device Host',$parent);
$ain=getVarValue('Device AIN',$parent);

austauschen gegen

$host=getVarValue('Host',$parent);
$ain=getVarValue('AIN',$parent);

Ist eben immer blöd zwei eigentlich zusammenhängende Scripte aus verschiedenen Generationen zu verwenden.

Kann ich mir vorstellen,

So hab die beiden Zeilen wie du gesagt hast ersetzt:

<?php
/*
switch a Fritz AHA Device (Fritz Powerline 546E, Fritz Dect200) from IPSymcon
http://www.tdressler.net/ipsymcon
V2.2 16.01.2016
see also
http://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AVM_Technical_Note_-_Session_ID.pdf
http://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/AHA-HTTP-Interface.pdf
*/
if (!function_exists('mb_convert_encoding')) {
   IPS_LogMessage ("FritzAHA Switch","Error:Need mbstring_extension!
");
   return;
}
if (!function_exists('simplexml_load_string')) {
   IPS_LogMessage("FritzAHA Switch","Error:Need SimpleXML functions(simplexml_load_string)!
");
   return;
}

/* config section, pls adopt this for your device
credential array array('<1.host/ip>' =>array('user'=>'<login name1>','password'=>'<secret>')
                      ,'<2.host/ip>' =>array('user'=>'<login name2>','password'=>'<secret2>')
                      ,..
                     );
if no login name is needed/applicable, set the name to an empty string ('')!
*/
$logins=array('172.16.1.2'=>array('user'=>'','password'=>'start') //sample entry for fritzbox
/*           ,'192.168.170.211'=>array('user'=>'','password'=>'xyz123') //sample entry for another host,maybe fritz546 */
        );

$id=31887 /*[FRITZ Smarthome\ TV Beleuchtung\Status]*/; //test variable for execute
/* end config section */

//check caller
$sender=$_IPS['SENDER'];
switch ($sender) {
case "WebFront":
  $me=$_IPS['VARIABLE'];
  $val=$_IPS['VALUE'];
   SetValue($me, $val); //doing will be done by variable change
   return;
  break; //not reached
case "Variable":
  $me=$_IPS['VARIABLE'];
  $val=$_IPS['VALUE'];
  break;
case "Execute":
  $me=$id;
  $val=@GetValue($me);
  break;
default:
  IPS_LogMessage("FritzAHA Switch", "Error: unknown Sender '$sender'");
  return;
}

$state=$val;
IPS_LogMessage("FritzAHA Switch","Switch ID ".$me." to ".($state?'ON':'OFF'));

/*
//check varable is right
$name='fritz_aha_reader';
if ($name != "Switch Status") {
  IPS_LogMessage("FritzAHA Switch","Error: Action from wrong variable ".$_IPS['VARIABLE']);
  return;
}
*/
//get parameter from IPS
$parent=IPS_GetParent($me);
$host=getVarValue('Host',$parent);
$ain=getVarValue('AIN',$parent);

//checks
if (!$host || !$ain) {
  IPS_LogMessage("FritzAHA Switch","Error: Parameter host($host) or AIN($ain) missed");
  return;
}

//get password using ID host
$username=$logins[$host]['user'];
$password=$logins[$host]['password'];
if (!$password) {
  IPS_LogMessage("FritzAHA Switch","Error: password for '$host' not defined");
  return;
}

//build urls and login
$loginurl="http://".$host."/login_sid.lua";//login_sid.lua for fritzos 5.50+
$ahaurl="http://".$host."/webservices/homeautoswitch.lua";//api url
$sid=get_sid($loginurl,$username,$password);
if (!isset($sid)) {
  IPS_LogMessage("FritzAHA Switch", "Error: Login invalid or failed");
  return;
}

//query actual state
$url=$ahaurl.'?ain='.rawurlencode($ain).'&sid='.$sid.'&switchcmd=getswitchstate';
$answer=chop(@file_get_contents($url));
$response=$http_response_header[0];
if (!preg_match("/200\s+OK$/",$response)){
  IPS_LogMessage("FritzAHA Switch", "Error: Query ($url) failed, Response: $response ");
  return;
}
IPS_LogMessage("FritzAHA Switch", "Actor $ain actual state:".($answer?"ON":"OFF"));
if ((($answer=="1")!=$state) || ($sender == "Execute")) {
//execute query
  $cmd=($state==true)?'setswitchon':'setswitchoff';
  IPS_LogMessage("FritzAHA Switch", "Actor $ain execute cmd:".$cmd);
  $url=$ahaurl.'?ain='.rawurlencode($ain).'&sid='.$sid.'&switchcmd='.$cmd;
  $answer=@file_get_contents($url);
  $response=$http_response_header[0];
  if (!preg_match("/200\s+OK$/",$response)) {
     IPS_LogMessage("FritzAHA Switch", "Error: Update Actor $ain failed, Response: $response");
     return;
  }
  IPS_LogMessage("FritzAHA Switch", "New Status for Actor $ain:".($answer?"ON":"OFF"));
}else{
   IPS_LogMessage("FritzAHA Switch", "No need to switch Actor $ain");
}

//-------------------------------------------------------------------------------
/**
  * login into fritz and get sid
  * @param string loginurl url for accessing device
  * @param string username Username to login, if needed or empty
  * @param string password password for login
  * @return string sid
  */
function get_sid ($loginurl,$username,$password) {

 if (is_null($username)) $username='';
 $sid='';
 // get challenge string
 $http_response = file_get_contents($loginurl);
 $response=$http_response_header[0];
 if (preg_match("/200\s+OK$/",$response)) {
  $xml = simplexml_load_string($http_response);
  $challenge=(string)$xml->Challenge;
  $sid=(string)$xml->SID;
 }else{
   IPS_LogMessage("FritzAHA Switch", "Error: GetSid with $loginurl failed, Response: $response");
 }
 if ((strlen($sid)>0) && (preg_match("/^[0]+$/",$sid)) && $challenge) {
     //sid is null, got challenge
    $sid="";
    //build password response
    $pass=$challenge."-".$password;
    //UTF-16LE encoding as required
    $pass=mb_convert_encoding($pass, "UTF-16LE");
    //md5hash on top
    $md5 = md5($pass);
    //final answer string
    $challenge_response = $challenge."-".$md5;
    //send to box
    $url=$loginurl."?username=".$username."&response=".$challenge_response;
   $http_response = file_get_contents($url);
   //check answer
   $xml = simplexml_load_string($http_response);
   $sid=(string)$xml->SID;
   if ((strlen($sid)>0) && !preg_match("/^[0]+$/",$sid)) {
            //is not null, bingo!
            return $sid;
   }

 }else {
  //use existing sid if $sid matches an hex string
  if ((strlen($sid)>0) && (preg_match("/^[0-9a-f]+$/",$sid))) return $sid;
 }
 return null;
}//function

//-------------------------------------------------------------------------------
/**
* get varable value by name referencing parent
* @param string $name Name of variable
* @param integer $par ID of parent (category)
* @return variant value of selected variable or null
*/
function getVarValue($name,$par) {
  $value=null;
  $vid = @IPS_GetVariableIDByName($name, $par);
  if ($vid)
    $value=GetValue($vid);
  return $value;
}
?>

Die Meldung im Log ist nun:

Eine Reaktion ist trotzdem noch nicht zu erkennen.

Irgendwas gemacht hat er aber, zumindest sagt er von Off nach On geschaltet zu haben. Gehört die nicht mehr lesbare gelbe Meldung nicht auch noch zum Script?
Sorry, so langsam fällt mir nichts mehr ein.

Huhu,

ne die gelbe Meldung ist ne Statusabfrage zu nem Skript von mir.

Finde es auch merkwürdig er scheint ja alles richtig zu holen nur kommt kein Schaltbefehl.

„Smarthome Devices freigeben“ ist in der Fritzbox aktiviert?

Leider ja :rolleyes:

Hallo zusammen,

ich bin ein Neuling bei IP-Symcon. Ich möchte in ein paar Monaten das System im neuen Haus in meiner KNX Installation einsetzen und jetzt schon mal mit den DECT200-Steckdosen ein wenig „spielen“.

Ich habe die Skripte von tommi installiert. Ich bring auch die „Schalter“ im Webfront und kann die schalten.

Aber wie lege ich einen Wochenzeitplan mit den Schaltzuständen „an“ und „aus“ an, um die Zeitschaltungen aus der Fritzbox ins Symcon zu verlagern?

Ich habe verschiedene Sachen probiert, z. B. die Variable „Switch Status“ mittels „SetValue($_IPS[‚TARGET‘], False); oder True“ ändern zu lassen, aber der Schaltzustand hält genau eine Sekunde.

Wie lege ich das an?

Danke und viele Grüße
Flo

Verwendest Du die uralten Scripte oder das AVMAHA Modul?
Tommi

Hallo,

danke für deine Antwort. Ich habe die Scripts von deiner Seite (tdressler.net) geladen und nach Anleitung eingespielt.

Grüße Flo

Die Scripte waren für IPS<4 und sollten jetzt nicht mehr genommen werden, Ich muss die Seite wahrscheinlich ganz löschen, offenbar zeigt der Rote Text darüber nicht so viel Wirkung :frowning:

Dafür gibt es nun das AVMAHA Modul und das Switch Modul. Zum Schalten sollte der Befehl SwitchMode genommen werden. Siehe Doku im Readme.

Tommi

Also dann ist das hier veraltet?
http://www.tdressler.net/ipsymcon/fritz_aha.html

Ich habe da keinen roten Text gesehen :slight_smile:

Wo finde ich die aktuellen Module?

Grüße Flo

Nachtrag: Ich glaube ich habe jetzt die richtigen Module gefunden. Habe den GitHub-Link von Tommy hinzugefügt und das Modul installiert.

Vielen Dank, ich werde jetzt mal weiterspielen und versuchen ob ich das jetzt hinbekomme.

Grüße Flo

Also dann ist das hier veraltet?
http://www.tdressler.net/ipsymcon/fritz_aha.html

Genau. Ich bin jetzt auch etwas verblüfft, das dort die alte Seite stand. Jetzt ist sie ganz weg…

Tommi

Hi,

hat jemand das Modul mit FritzOS 7.x laufen und kann bestätigen, dass es funktioniert?

Überlege, meine 7490 zu updaten.

Freu mich auf Rückmeldung. Vielen Dank.

VG: Lars.

Gesendet von meinem SM-G955F mit Tapatalk

Hi,

Läuft bei mir mit Dect200!

Gruß

Vielen Dank für die schnelle Rückmeldung :smiley:

Gesendet von meinem SM-G955F mit Tapatalk

Schaut mal hier

https://github.com/Tommi2Day/ipsymcon-phpmodule-by-Tommi

Hallo
Ich habe mir einen Comet Dect Heizungsthermostat gekauft.

Im AVMAHA Modul wird das Heizungsthermostat als Temperatur erkannt. (WSDEF)

Im Sourcecode auf Git habe ich die Stelle für die HRK gefunden.

     * Forward HKR data to HeatingDev instances
     * Create one if needed
     * ToDo: must be implemented
     * @param $caps string
     * @param $data array
     */
    private function SendHKRData($caps, $data)
    {
        IPS_LogMessage(__CLASS__, __FUNCTION__ . '::Not implemented yet');
    }

was muss ich hier einfügen das die Daten von Soll Ist Temp Batterie Fenster usw als Variabel angeleght werden ?

Super wäre naturlich auch die Solltemperatur zu ändern.

MfG Ziege-One