Anbindung Controller an IP-Symcon

Anbindung des Controllers an externe Hausautomationssysteme.
wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Der Poolcontroller lässt sich relativ simpel an IP-Symcon anbinden. Das folgende Skript liest die Werte aus dem Controller aus, legt in IP-Symcon die Variablen an und und updated diese dann alle 60 Sekunden. Es muss nur die URL/IP-Adresse des Controllers konfiguriert werden. Diese Skriptversion funktioniert mit allen 1.6er Versionen bis heute des Controllers:


Code: Alles auswählen

<?
// Version 1.0 Poolserver Installationsscript
//Config !! URL MUSS angepasst werden-----------------------------------------------------------------------------------------------------------------------------------------
//Nicht vergessen für die Variablen die Ihr loggen möchtet in den Variablensettings
//dann das Logging aktivieren
//URL-Adresse des Solar/Pool Control zbsp. http://192.168.1.30 oder http://www.deinpoolserver.com und wenn anderer Port als 80 mit http://www.deinpoolserver.com:81
$IPPoolServerAdr="http://IPGOESHERE";

//In Minuten Abfrageintervall-Aktualisierung festlegen (Default 5 Minuten)
$RescanInterval=1;

//Profi/Spezialsettings nicht nötig-------------------------------------------------------------------------------------------------------------------------------------------
set_time_limit(15); //Timeout auf 15 Sekunden für Script erhöhen, kann oder muss in seltenen Fällen erhöht werden
$debug=false;

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Ab hier bitte nichts mehr ändern -------------------------------------------------------------------------------------------------------------------------------------------
// Version 1.0 Poolserver Installationsscript

//Für nächste Version Vorbereitungen
$user="admin";
$pwd="";

//Wert 0 = 8 Relais, Wert 1 = 16 Relais
//Unterstützt wird aktuell erst nur die 8 Relais-Variante
$Rel8or16=0;

//Anzeigen der Taster Digitaleingänge
//Unterstützt wird aktuell die Anzeige der entsprechenden Taster-Digaleingänge noch nicht aufgrund CSV-Strukturfehler
$DigitInShow=true;

//Usernamen: ADC[1..5], Redox, pH, Temperatur[1..8],Relais[1..8], digital Input[1..4], Allenfalls Spezialversionen Relais 9-16 NICHT Implementierte Version
$row=0;

$IPPoolServerAdrPure = $IPPoolServerAdr;
$IPPoolServerAdr.="/GetState.csv";
$RescanInterval=$RescanInterval*60;

if (($handle = fopen($IPPoolServerAdr, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
      	$num = count($data);

	      for ($col=0; $col < $num; $col++) {
	        		$ContentRowCol[$row][$col]= $data[$col];
	      }

		  $row++;
    }
    fclose($handle);
}
else
{
	Echo "FEHLER: Es konnte keine Verbindung hergestellt werden, prüfen Sie bitte die Settings";
	IPS_SetScriptTimer($IPS_SELF,60);
}
																																								if($debug==true)
																																									print_r($ContentRowCol);
if(substr(trim($ContentRowCol[0][1]),0,3)=="1.6")
{
	if(count($ContentRowCol)==6)
	{//Grob Datenstruktur prüfen

		$object = IPS_GetObject($IPS_SELF);
		$parentID = $object['ParentID'];

		//Installer
		if ($IPS_SENDER == "Execute")
		{
			  IPS_SetHidden($IPS_SELF, true);
			  IPS_SetName($IPS_SELF, "ReadSolarPoolControlData");
			  $parentObject = IPS_GetObject($parentID);
			  if ($parentObject['ObjectType'] !== 1)
			  {
			      $instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
			       IPS_SetParent($instanceID, $parentID);
			      $parentID = $instanceID;
			      IPS_SetParent($IPS_SELF, $parentID);
			      IPS_SetName($instanceID, "Solar und Pool Control");

			      IPS_SetScriptTimer($IPS_SELF,10);
			  }
			  else
			  {
				  //Installation ist durch, Scripttimer auf gewünschen Intervall setzen
				  IPS_SetScriptTimer($IPS_SELF,$RescanInterval);
			  }
		}
		else
		{
	      $PoolServerInstanceID = $parentID;

			$poolserverurl = CreateVariableByName($parentID, "PoolServerURL", 3, $profile = "~String");
			SetValueString($poolserverurl, $IPPoolServerAdrPure);

			$username = CreateVariableByName($parentID, "Username", 3, $profile = "~String");
			SetValueString($username, $user);

			$password = CreateVariableByName($parentID, "Password", 3, $profile = "~String");
			SetValueString($password, $pwd);

			$countrowfix = count($ContentRowCol);

			@IPS_CreateVariableProfile("PoolServer_Relais", 1);
			IPS_SetVariableProfileAssociation("PoolServer_Relais", 0, "Aus Automatik", "", -1);
			IPS_SetVariableProfileAssociation("PoolServer_Relais", 1, "Ein Automatik", "", -1);
			IPS_SetVariableProfileAssociation("PoolServer_Relais", 2, "Aus Handbetrieb", "", -1);
			IPS_SetVariableProfileAssociation("PoolServer_Relais", 3, "Ein Handbetrieb", "", -1);

			//Row 0 hat für uns uninteressante Werte - Systeminfo etc.
			for ($row=1; $row < count($ContentRowCol); $row++) {

				//Beschriftung/Ueberschrift aus Row 1 draus generieren wir Variablen zu den Überschriften
				if($row==1)
				{
				      for ($col=0; $col < count($ContentRowCol[$row])-12; $col++) {

			            if($col < 16)
			            {//Alle anderen Bezeichnungen vorher
			         		$ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 3, $profile = "~String");
			         	}
							else
							{//Relais bezeichnung
			         		$ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 1, $profile = "PoolServer_Relais");
			         	}
				      }
				}

				//Massbezeichnung, Profile und Assoziationen + Suffix in IPS hieraus generieren
				if($row==2)
				{
				      for ($col=0; $col < count($ContentRowCol[$row])-12; $col++) {
				         if(trim($ContentRowCol[$row][$col])!="--" && trim($ContentRowCol[$row][$col])!="n.a.")
				         {
				            @IPS_CreateVariableProfile ("PoolServer_".trim($ContentRowCol[$row][$col]), 3);
				            @IPS_SetVariableProfileText ("PoolServer_".trim($ContentRowCol[$row][$col]),""," ".trim($ContentRowCol[$row][$col]));

				         	CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[1][$col], 3, $profile = "PoolServer_".trim($ContentRowCol[$row][$col]));
						 	}
				      }
				}

				//OFFSET aus Row3, GAIN aus Row4 und Value aus Row5 - Verwenden wir für Berechnung und hängen Endwert an Array als neue Row an
				//Achtung Werte ab Position 16 müssen nicht mehr Berechnet werden da es Relais oder ON/OFF Komponenten sind
				if($row==3)
			   {
				      for ($col=0; $col < 16; $col++) {
				         if($col==0) //Spezialfall Zeit-Time
				         {
				            $ContentRowCol[$countrowfix+1][$col]=$ContentRowCol[$row+2][$col];
				         }
				         else
					      {
					      	$ContentRowCol[$countrowfix+1][$col]=($ContentRowCol[$row+2][$col]*$ContentRowCol[$row+1][$col])+$ContentRowCol[$row][$col];
							}
							SetValueString($ContentRowCol[$countrowfix][$col],$ContentRowCol[$countrowfix+1][$col]);
				      }
				}

				//Relais und Schalter entsprechend Automatisch, Aus, Ein, Hand setzen
				if($row==5)
				{
					$ena=0;
					$state=0;
					$i=0;

				      for ($col=16; $col < count($ContentRowCol[$row])-12; $col++) {
				         if($ContentRowCol[$row][$col]==0)
							{//Aus Automatik
				      		$ContentRowCol[$countrowfix+1][$col]=0;
			  				}
				         elseif($ContentRowCol[$row][$col]==1)
				         {//Ein Automatik
				      		$ContentRowCol[$countrowfix+1][$col]=1;
				      	}
				         elseif($ContentRowCol[$row][$col]==2)
				         {//Aus Handbetrieb
				      		$ContentRowCol[$countrowfix+1][$col]=2;
							}
				      	elseif($ContentRowCol[$row][$col]==3)
				      	{//Ein Handbetrieb
				      		$ContentRowCol[$countrowfix+1][$col]=3;
				      	}
				      	SetValueInteger($ContentRowCol[$countrowfix][$col],$ContentRowCol[$countrowfix+1][$col]);
				      	$i++;
				   	}
				 }
			}																																							if($debug==true)
																																											print_r($ContentRowCol);
			IPS_SetScriptTimer($IPS_SELF,$RescanInterval);
		}
	}
	else
	{
		Echo "FEHLER: Die Datenstruktur stimmt nicht, handelt es sich beim Gerät um einen Solar/Pool-Control?";
		IPS_SetScriptTimer($IPS_SELF,60);
	}
}
else
{
	Echo "FEHLER: Die Firmware entspricht nicht dem geforderten Stand mit 1.5.1";
	IPS_SetScriptTimer($IPS_SELF,60);
}

//Funktionsdefinitionen
function CreateVariableByName($id, $name, $type, $profile = "")
 {
     $vid = @IPS_GetVariableIDByName($name, $id);

     if($vid === false)
     {
         $vid = IPS_CreateVariable($type);
         IPS_SetParent($vid, $id);
         IPS_SetName($vid, $name);
         IPS_SetInfo($vid, "this variable was created by script #".$_IPS['SELF']);
     }
     else
     {
     }

	  if(strpos($name, "n.")>0)
	   	IPS_SetHidden($vid, true);
	  else
			IPS_SetHidden($vid, false);

     if($profile !== "") { IPS_SetVariableCustomProfile($vid, $profile); }

     return $vid;
 }
?>


Da einige Werte als Stringvariable ausgelesen werden, und somit nicht ohne weiteres numerisch weiterverarbeitbar sind (Bspw Runden), gibt es noch ein seperates Skript, welches die String Variablen in Floatvariablen umwandelt. Einfach die Floatvariablen anlegen und das Skript, bzw. die Variablen IDs entsprechend anpassen. Ich lasse das Skript jedesmal ausführen, wenn sich eine von mir festgelegte Variable am Controller updated (Sprich, genau nachdem das Controller Skript gelaufen ist).

Code: Alles auswählen

 <?
$string_rueck_solar=getvalue(20998 /*[Pool\Poolcontroller\Solar und Pool Control\10_Rücklauf Solar]*/);
$string_rueck_wp=getvalue(52597 /*[Pool\Poolcontroller\Solar und Pool Control\11_Rücklauf WP]*/);
$string_solar_fuehler=getvalue(48662 /*[Pool\Poolcontroller\Solar und Pool Control\12_Solarfühler]*/);
$string_pumpenschacht=getvalue(34402 /*[Pool\Poolcontroller\Solar und Pool Control\13_Pumpenschacht]*/);
$string_zulauf_solarthermie=getvalue(27017 /*[Pool\Poolcontroller\Solar und Pool Control\14_Zulauf Solarthermie]*/);
$string_rueck_waerme_tauscher=getvalue(36848 /*[Pool\Poolcontroller\Solar und Pool Control\15_Rücklauf Wärmetauscher]*/);
$string_kesseldruck=getvalue(55350 /*[Pool\Poolcontroller\Solar und Pool Control\3_Kesseldruck]*/);
$string_chlor=getvalue(51449 /*[Pool\Poolcontroller\Solar und Pool Control\1_Chlor]*/);
$string_durchfluss=getvalue (56773 /*[Pool\Poolcontroller\Solar und Pool Control\4_Filterdurchfluss]*/);
//echo ($string_chlor);

$float_rueck_solar = tofloat($string_rueck_solar);
$float_rueck_wp = tofloat($string_rueck_wp);
$float_solar_fuehler = tofloat ($string_solar_fuehler);
$float_pumpenschacht = tofloat($string_pumpenschacht);
$float_zulauf_solarthermie= tofloat($string_zulauf_solarthermie);
$float_rueck_waerme_tauscher = tofloat ($string_rueck_waerme_tauscher);
$float_kesseldruck = tofloat($string_kesseldruck);
$float_chlor = tofloat($string_chlor);
$float_durchfluss = tofloat($string_durchfluss);

setvalue (13498 /*[Pool\Poolcontroller\Floatvars\Temp_Rück_Solar]*/,$float_rueck_solar);
setvalue (18881 /*[Pool\Poolcontroller\Floatvars\Temp_Rück_WP]*/, $float_rueck_wp);
setvalue (44957 /*[Pool\Poolcontroller\Floatvars\Temp_Solarfühler]*/, $float_solar_fuehler);
setvalue (13195 /*[Pool\Poolcontroller\Floatvars\Temp_Pumpenschacht]*/, $float_pumpenschacht);
setvalue (19427 /*[Pool\Poolcontroller\Floatvars\Zulauf Solarthermie]*/, $float_zulauf_solarthermie);
setvalue (14248 /*[Pool\Poolcontroller\Floatvars\Rücklauf Wärmetauscher]*/, $float_rueck_waerme_tauscher);
setvalue (11935 /*[Pool\Poolcontroller\Floatvars\Kesseldruck]*/, $float_kesseldruck);
setvalue (36568 /*[Pool\Poolcontroller\Floatvars\Freies Chlor]*/,$float_chlor);
setvalue (14747 /*[Pool\Poolcontroller\Floatvars\Filterdurchfluss]*/,$float_durchfluss);

function tofloat($num) {
    $dotPos = strrpos($num, '.');
    $commaPos = strrpos($num, ',');
    $sep = (($dotPos > $commaPos) && $dotPos) ? $dotPos :
        ((($commaPos > $dotPos) && $commaPos) ? $commaPos : false);

    if (!$sep) {
        return floatval(preg_replace("/[^0-9]/", "", $num));
    }

    return floatval(
        preg_replace("/[^0-9]/", "", substr($num, 0, $sep)) . '.' .
        preg_replace("/[^0-9]/", "", substr($num, $sep+1, strlen($num)))
    );
}


?>

Benutzeravatar
Frankie
Beiträge: 311
Registriert: 22. Dezember 2014, 22:29

Re: Anbindung Controller an IP-Symcon

Beitrag von Frankie »

Hi Ingo
vielen Dank , hoffe der ein oder andere Ip Symcon User kanns gebrauchen
hast vielleicht auch mal einen Screenshot , wie das unter IP Symcon denn so angezeigt werden kann, wie das so aussehen könnte
ich hab selber sowas nicht, also reine Neugierde
gruß
Frank

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Klar. Anbei mal zwei Screenshots. Einer ist ein Ausschnitt meiner Web Oberfläche, diese ist bei IP-Symcon relativ frei konfigurierbar. Der andere Screenshot zeigt die Variablen im Konsolenbaum.

Console IPS.png
Console IPS.png (384.33 KiB) 628 mal betrachtet
webfront pool.png
webfront pool.png (132.53 KiB) 628 mal betrachtet

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Und hier noch ein Screenshot einer in der Datenbank aufgezeichneten Variablen. Mein Beispiel hier ist freies Chlor.
Chlor.png
Chlor.png (426.47 KiB) 628 mal betrachtet

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Habe die Funktion, die die Strings in Floatvars ändert nochmals angepasst, so dass negative Werte berücksichtigt werden (Beispielsweise negativer Druck = Unterdruck)

Code: Alles auswählen

function tofloat($num) {

	 $negative = substr ($num,0,1);
	 print_r ($negative);
	 $dotPos = strrpos($num, '.');
    $commaPos = strrpos($num, ',');
    $sep = (($dotPos > $commaPos) && $dotPos) ? $dotPos :
        ((($commaPos > $dotPos) && $commaPos) ? $commaPos : false);


    if (!$sep) {
        $rueck = floatval(preg_replace("/[^0-9]/", "", $num));
        if ($negative == "-") {
            $rueck = $rueck *-1;
			}
        return $rueck;
    }

    $rueck = (
        preg_replace("/[^0-9]/", "", substr($num, 0, $sep)) . '.' .
        preg_replace("/[^0-9]/", "", substr($num, $sep+1, strlen($num)))
    );
    if ($negative == "-") {
            $rueck = $rueck *-1;
    }
    return ($rueck);
}


Benutzeravatar
Sandhase
Beiträge: 197
Registriert: 6. Januar 2015, 13:48

Re: Anbindung Controller an IP-Symcon

Beitrag von Sandhase »

Hi Ingo,

Muss dann nur im "alte" Skript von oben, der Abschnitt ab "function tofloat($num)" durch den geänderten Abschnitt vom "neuen" ersetzt werden?

Und noch ein paar Fragen, bin blutiger Anfänger bei/mit IP-Symcon. :oops:
Bei mir werden die Werte nicht in dem eingestellten Intervall von 1 Minute aktualisiert.
Nur wenn ich es manuel ausführe und dann bekomme ich folgende Meldungen in der Skript Ausgabe.

Notice: Undefined variable: IPS_SELF in /mnt/data/symcon/scripts/28411.ips.php on line 63

Notice: Undefined variable: IPS_SENDER in /mnt/data/symcon/scripts/28411.ips.php on line 67

Notice: Undefined variable: IPS_SELF in /mnt/data/symcon/scripts/28411.ips.php on line 189

Warning: Skript #0 exisitert nicht in /mnt/data/symcon/scripts/28411.ips.php on line 189


wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Genau, nur die Funktion ersetzen.
ich schätze mal Du bist auf Linux und hast die Kompatibilitäts-Funktion nicht aktiviert.

$IPS_SELF, Sender, etc gibt es eigentlich nicht mehr.

Ersetze das mal so:

Systemvariable Bedeutung
$_IPS['SELF'] SkriptID des aktuellen Skriptes
$_IPS['THREAD'] ThreadID des aktuellen Skriptes
$_IPS['SENDER'] Auslöser des Skriptes. Abhängig vom Wert können sich weitere globale Variablen ergeben. Mögliche Werte sind in der folgenden Tabelle "Zusätzliche Systemvariablen" genauer spezifiziert.

Benutzeravatar
Sandhase
Beiträge: 197
Registriert: 6. Januar 2015, 13:48

Re: Anbindung Controller an IP-Symcon

Beitrag von Sandhase »

wupperi hat geschrieben:Genau, nur die Funktion ersetzen.
ich schätze mal Du bist auf Linux und hast die Kompatibilitäts-Funktion nicht aktiviert.


Danke, ich hätte vieleicht noch erwähnen sollen das ich die SymBox hab.

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Läuft es denn jetzt?

Benutzeravatar
Sandhase
Beiträge: 197
Registriert: 6. Januar 2015, 13:48

Re: Anbindung Controller an IP-Symcon

Beitrag von Sandhase »

Ja jetzt aktualiseirt es die Werte alle 60 sec. :HUG:
Bin jetzt erstmal so ein bissel am rumspielen und ausprobieren.

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Klasse.

hoep
Beiträge: 5
Registriert: 16. Juni 2015, 09:04

Re: Anbindung Controller an IP-Symcon

Beitrag von hoep »

Hi wupperi,

vielen Dank für Dein script, läuft super. Hast Du auch schon in die andere Richtung probiert (Relais schalten, Parameter übergeben z.B. Start/Endzeitpunkt Filter o.ä.) ?
Beste Grüße
hoep

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Hi, nein. Ich arbeite mit 1-Wire digital outs die IPS schaltet und eine Regel auf dem Poolcontroller dann basierend auf dem Eingang der I/O Ports schaltet.
Ist übrigens nicht mein Skript, sondern ein älteres von einem anderen IPS User, welches ich nur (minimal) angepasst habe.

Credits to whom they belong :-)

mrcy73
Beiträge: 5
Registriert: 30. Januar 2015, 09:48

Re: Anbindung Controller an IP-Symcon

Beitrag von mrcy73 »

Hallo wupperi,

hab noch ein Problem, habe gestern einen Durchflussmesser eingebaut. Die Variable an sich wird vom Pool Controller geholt, allerdings legt er die Variable als Integer mit Wert 0 an. Da der ausgegebene Wert des Flowmeters im 0,.. Bereich liegt, ist Integer da wohl eher nicht die beste Wahl ;) Leider weiß ich im Moment nicht, wie ich das "umbiegen" könnte.
Irgend ne Idee?

Danke
Marc

hoep
Beiträge: 5
Registriert: 16. Juni 2015, 09:04

Re: Anbindung Controller an IP-Symcon

Beitrag von hoep »

Hallo mrcry73,

habe diesbezüglich wupperis Skript angepasst:
Gruß
hoep

Code: Alles auswählen

<?
// Version 1.0 Poolserver Installationsscript
//Config !! URL MUSS angepasst werden-----------------------------------------------------------------------------------------------------------------------------------------
//Nicht vergessen für die Variablen die Ihr loggen möchtet in den Variablensettings
//dann das Logging aktivieren
//URL-Adresse des Solar/Pool Control zbsp. http://192.168.1.30 oder http://www.deinpoolserver.com und wenn anderer Port als 80 mit http://www.deinpoolserver.com:81
$IPPoolServerAdr="http://X.X.X.X";

//In Minuten Abfrageintervall-Aktualisierung festlegen (Default 5 Minuten)
$RescanInterval=10;

//Profi/Spezialsettings nicht nötig-------------------------------------------------------------------------------------------------------------------------------------------
set_time_limit(15); //Timeout auf 15 Sekunden für Script erhöhen, kann oder muss in seltenen Fällen erhöht werden
$debug=false;

//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Ab hier bitte nichts mehr ändern -------------------------------------------------------------------------------------------------------------------------------------------
// Version 1.0 Poolserver Installationsscript

//Für nächste Version Vorbereitungen
$user="";
$pwd="";

//Wert 0 = 8 Relais, Wert 1 = 16 Relais
//Unterstützt wird aktuell erst nur die 8 Relais-Variante
$Rel8or16=0;

//Anzeigen der Taster Digitaleingänge
//Unterstützt wird aktuell die Anzeige der entsprechenden Taster-Digaleingänge noch nicht aufgrund CSV-Strukturfehler
$DigitInShow=true;

//Usernamen: ADC[1..5], Redox, pH, Temperatur[1..8],Relais[1..8], digital Input[1..4], Allenfalls Spezialversionen Relais 9-16 NICHT Implementierte Version
$row=0;

$IPPoolServerAdrPure = $IPPoolServerAdr;
$IPPoolServerAdr.="/GetState.csv";
//$RescanInterval=$RescanInterval*60;

if (($handle = @fopen($IPPoolServerAdr, "r")) !== FALSE) {
    while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
         $num = count($data);

         for ($col=0; $col < $num; $col++) {
                 $ContentRowCol[$row][$col]= $data[$col];
         }

        $row++;
    }
    fclose($handle);
}
else
{
   Echo "FEHLER: Es konnte keine Verbindung hergestellt werden, prüfen Sie bitte die Settings";
   IPS_SetScriptTimer($IPS_SELF,60);
}
if($debug==true)
  print_r($ContentRowCol);

//print_r($ContentRowCol);
if (!isset($ContentRowCol[0][1])) goto Abbruch;
if(substr(trim($ContentRowCol[0][1]),0,3)=="1.6")
{
   if(count($ContentRowCol)==6)
   {//Grob Datenstruktur prüfen

      $object = IPS_GetObject($IPS_SELF);
      $parentID = $object['ParentID'];

      //Installer
      if ($IPS_SENDER == "Execute")
      {
           IPS_SetHidden($IPS_SELF, true);
           IPS_SetName($IPS_SELF, "ReadSolarPoolControlData");
           $parentObject = IPS_GetObject($parentID);
           if ($parentObject['ObjectType'] !== 1)
           {
               $instanceID = IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");
                IPS_SetParent($instanceID, $parentID);
               $parentID = $instanceID;
               IPS_SetParent($IPS_SELF, $parentID);
               IPS_SetName($instanceID, "Pool Controller");

               IPS_SetScriptTimer($IPS_SELF,10);
           }
           else
           {
              //Installation ist durch, Scripttimer auf gewünschen Intervall setzen
              IPS_SetScriptTimer($IPS_SELF,$RescanInterval);
           }
      }
      else
      {
         $PoolServerInstanceID = $parentID;

         $poolserverurl = CreateVariableByName($parentID, "PoolServerURL", 3, $profile = "~String");
         SetValueString($poolserverurl, $IPPoolServerAdrPure);

         $username = CreateVariableByName($parentID, "Username", 3, $profile = "~String");
         SetValueString($username, $user);

         $password = CreateVariableByName($parentID, "Password", 3, $profile = "~String");
         SetValueString($password, $pwd);

         $countrowfix = count($ContentRowCol);

         @IPS_CreateVariableProfile("PoolServer_Relais", 1);
         IPS_SetVariableProfileAssociation("PoolServer_Relais", 0, "Aus (Auto)", "", -1);
         IPS_SetVariableProfileAssociation("PoolServer_Relais", 1, "Ein (Auto)", "", -1);
         IPS_SetVariableProfileAssociation("PoolServer_Relais", 2, "Aus (Manu)", "", -1);
         IPS_SetVariableProfileAssociation("PoolServer_Relais", 3, "Ein (Manu)", "", -1);

         //Row 0 hat für uns uninteressante Werte - Systeminfo etc.
         for ($row=1; $row < count($ContentRowCol); $row++) {

            //Beschriftung/Ueberschrift aus Row 1 draus generieren wir Variablen zu den Überschriften
            if($row==1)
            {
						$clrestvar = CreateVariableByName($PoolServerInstanceID, "36"."_"."Cl Rest", 2, $profile = "");
						$phminusrestvar = CreateVariableByName($PoolServerInstanceID, "37"."_"."pH- Rest", 2, $profile = "");
						$phplusrestvar = CreateVariableByName($PoolServerInstanceID, "38"."_"."pH+ Rest", 2, $profile = "");
						$clconsvar = CreateVariableByName($PoolServerInstanceID, "39"."_"."Cl Verbrauch", 2, $profile = "");
						$phminusconsvar = CreateVariableByName($PoolServerInstanceID, "40"."_"."pH- Verbrauch", 2, $profile = "");
						$phplusconsvar = CreateVariableByName($PoolServerInstanceID, "41"."_"."pH+ Verbrauch", 2, $profile = "");
                  for ($col=0; $col < count($ContentRowCol[$row])-12; $col++) {

                     if($col < 16)
                     {//Alle anderen Bezeichnungen vorher
                        $ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 3, $profile = "~String");
                     }
                     else
                     {//Relais bezeichnung
							  if ($col <> 24)
                        $ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 1, $profile = "PoolServer_Relais");
                        else  $ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 3, $profile = "~String");
                     }
                  }
            }

            //Massbezeichnung, Profile und Assoziationen + Suffix in IPS hieraus generieren
            if($row==2)
            {
                  for ($col=0; $col < count($ContentRowCol[$row])-12; $col++) {
                     if(trim($ContentRowCol[$row][$col])!="--" && trim($ContentRowCol[$row][$col])!="n.a.")
                     {
                        @IPS_CreateVariableProfile ("PoolServer_".trim($ContentRowCol[$row][$col]), 3);
                        @IPS_SetVariableProfileText ("PoolServer_".trim($ContentRowCol[$row][$col]),""," ".trim($ContentRowCol[$row][$col]));

                        CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[1][$col], 3, $profile = "PoolServer_".trim($ContentRowCol[$row][$col]));
                      }
                  }
            }

            //OFFSET aus Row3, GAIN aus Row4 und Value aus Row5 - Verwenden wir für Berechnung und hängen Endwert an Array als neue Row an
            //Achtung Werte ab Position 16 müssen nicht mehr Berechnet werden da es Relais oder ON/OFF Komponenten sind
            if($row==3)
            {
                  for ($col=0; $col < 25; $col++) {
                     if($col==0) //Spezialfall Zeit-Time
                     {
								$h = $ContentRowCol[$row+2][$col];
								$stunde = floor($h/256);
								$minute = (int) $h - $stunde*256;
								$h = sprintf("%'.02d",$stunde).":".sprintf("%'.02d",$minute);
                        $ContentRowCol[$countrowfix+1][$col]=$h;
                     }
                     else if ($col<16)
                     {
                        $ContentRowCol[$countrowfix+1][$col]=($ContentRowCol[$row+2][$col]*$ContentRowCol[$row+1][$col])+$ContentRowCol[$row][$col];
                     }
                      else if ($col==24)
                     {
                        $ContentRowCol[$countrowfix+1][$col]=($ContentRowCol[$row+2][$col]*$ContentRowCol[$row+1][$col])+$ContentRowCol[$row][$col];
                     }
                     if (isset($ContentRowCol[$countrowfix+1][$col])) SetValueString($ContentRowCol[$countrowfix][$col],$ContentRowCol[$countrowfix+1][$col]);
                  }
            }

            //Relais und Schalter entsprechend Automatisch, Aus, Ein, Hand setzen
            if($row==5)
            {
               $ena=0;
               $state=0;
               $i=0;
                  SetValueFloat($clrestvar,floatval($ContentRowCol[$row][36]/10.0));
                  SetValueFloat($phminusrestvar,floatval($ContentRowCol[$row][37]/10.0));
                  SetValueFloat($phplusrestvar,floatval($ContentRowCol[$row][38]/10.0));
                  SetValueFloat($clconsvar,floatval($ContentRowCol[$row][39]));
                  SetValueFloat($phminusconsvar,floatval($ContentRowCol[$row][40]));
                  SetValueFloat($phplusconsvar,floatval($ContentRowCol[$row][41]));
					
                  for ($col=16; $col < count($ContentRowCol[$row])-12; $col++) {
                     if($ContentRowCol[$row][$col]==0)
                     {//Aus Automatik
                        $ContentRowCol[$countrowfix+1][$col]=0;
                       }
                     elseif($ContentRowCol[$row][$col]==1)
                     {//Ein Automatik
                        $ContentRowCol[$countrowfix+1][$col]=1;
                     }
                     elseif($ContentRowCol[$row][$col]==2)
                     {//Aus Handbetrieb
                        $ContentRowCol[$countrowfix+1][$col]=2;
                     }
                     elseif($ContentRowCol[$row][$col]==3)
                     {//Ein Handbetrieb
                        $ContentRowCol[$countrowfix+1][$col]=3;
                     }
                     if ($col <> 24)
                     SetValueInteger($ContentRowCol[$countrowfix][$col],$ContentRowCol[$countrowfix+1][$col]);
                      else if (isset($ContentRowCol[$countrowfix+1][$col])) SetValueString($ContentRowCol[$countrowfix][$col],$ContentRowCol[$countrowfix+1][$col]." cm/s");
                     $i++;
                     
                  }
             }
         }                                                                                                                     if($debug==true)
                                                                                                                                 print_r($ContentRowCol);
         IPS_SetScriptTimer($IPS_SELF,$RescanInterval);
      }
   }
   else
   {
      Echo "FEHLER: Die Datenstruktur stimmt nicht, handelt es sich beim Gerät um einen Solar/Pool-Control?";
      IPS_SetScriptTimer($IPS_SELF,60);
   }
}
else
{
   Echo "FEHLER: Die Firmware entspricht nicht dem geforderten Stand mit 1.5.1";
   IPS_SetScriptTimer($IPS_SELF,60);
}
Abbruch:
//Funktionsdefinitionen
function CreateVariableByName($id, $name, $type, $profile = "")
 {
     $vid = @IPS_GetVariableIDByName($name, $id);

     if($vid === false)
     {
         $vid = IPS_CreateVariable($type);
         IPS_SetParent($vid, $id);
         IPS_SetName($vid, $name);
         IPS_SetInfo($vid, "this variable was created by script #".$_IPS['SELF']);
     }
     else
     {
     }

     if(strpos($name, "n.")>0)
         IPS_SetHidden($vid, true);
     else
         IPS_SetHidden($vid, false);

     if(($profile !== "") and ($profile != 'PoolServer_cm/s')  and ($profile != 'PoolServer_m³/h')) { IPS_SetVariableCustomProfile($vid, $profile); }

     return $vid;
 }
?>
Edit: Script angepasst und Abbruch Sprungmarke eingefügt (Nachdem ich noch ein paar andere Routinen drinnen hatte, die ich rausgelöscht habe, war mir dieser durchgerutscht).
Eigentlich sollte es reichen das Script einmal händisch auszuführen, dann sollten die Variablen angelegt werden (die kritische Variable - 24_XX glaube ich vorher löschen).
Zuletzt geändert von hoep am 5. Juni 2016, 17:06, insgesamt 1-mal geändert.

mrcy73
Beiträge: 5
Registriert: 30. Januar 2015, 09:48

Re: Anbindung Controller an IP-Symcon

Beitrag von mrcy73 »

Hallo Hoep,

Danke für die Unterstützung. Kann ich den Scriptcode einfach ersetzen, ohne dass sich die bereits vorhandenen Variablen ändern (Variablennummern)?

Gruß
Marc

wupperi
Beiträge: 17
Registriert: 30. Januar 2015, 08:19

Re: Anbindung Controller an IP-Symcon

Beitrag von wupperi »

Zumindest bei mir läuft die Version von hoep nicht, da das Label 'abbruch' icht definiert ist.

hoep
Beiträge: 5
Registriert: 16. Juni 2015, 09:04

Re: Anbindung Controller an IP-Symcon

Beitrag von hoep »

Danke für den Hinweis, Script oben upgedatet und Abbruch Sprungmarke eingefügt).
Gruß
hoep

mrcy73
Beiträge: 5
Registriert: 30. Januar 2015, 09:48

Re: Anbindung Controller an IP-Symcon

Beitrag von mrcy73 »

Hallo Hoep,

funktioniert wunderbar!
Besten Dank.

Gruß
Marc

sklpoolcontroller
Beiträge: 12
Registriert: 18. August 2016, 10:35

Re: Anbindung Controller an IP-Symcon

Beitrag von sklpoolcontroller »

Hallo zusammen,

Bin grad am überlegen ob ich meine Poolsteuerung nativ über meinen LCN Bus und IPS mache oder dem Poolcontroller nehme.

Ich hab das Script zum auslesen der Variablen gesehen - das sieht ja relativ straight forward aus - wie ist es mit dem aktiven Schalten und Steuern aus IPS heraus? Habt ihr da schon was?

Danke und Gruß

Stephan