Hallo Alexander,
ich hab auch den Pool Controller und im Sommer das Script geändert, versuch das geänderte Script mal
<?
// 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://192.168.0.211";
//In Minuten Abfrageintervall-Aktualisierung festlegen (Default 5 Minuten)
$RescanInterval=60;
//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;
#$debug=true;
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//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 == 0)
{//Uhrzeit
$ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 3, $profile = "~String"); // String
}
if($col < 16)
{//Alle anderen Bezeichnungen vorher
if(($col > 7 and $col < 16) or $col ==5) //Temperatur
{
$ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 2, $profile = "~Temperature"); // Float
}
$ContentRowCol[$countrowfix][$col]=CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[$row][$col], 2, $profile = ""); // Float
}
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], 2, $profile = ""); // Float
}
}
}
//Massbezeichnung, Profile und Assoziationen + Suffix in IPS hieraus generieren
if($row==2)
{
for ($col=1; $col < count($ContentRowCol[$row])-12; $col++) { // start bei 1 da Zeit als String
if(trim($ContentRowCol[$row][$col])!="--" && trim($ContentRowCol[$row][$col])!="n.a.")
{
if(($col > 7 and $col < 16) or $col ==5) //Temperatur
{
}
else
{
@IPS_CreateVariableProfile ("PoolServer_".trim($ContentRowCol[$row][$col]), 2);
@IPS_SetVariableProfileText ("PoolServer_".trim($ContentRowCol[$row][$col]),""," ".trim($ContentRowCol[$row][$col]));
@IPS_SetVariableProfileDigits("PoolServer_".trim($ContentRowCol[$row][$col]), 2);
CreateVariableByName($PoolServerInstanceID, $col."_".$ContentRowCol[1][$col], 2, $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;
if (isset($ContentRowCol[$countrowfix+1][$col])) SetValueString($ContentRowCol[$countrowfix][$col],$ContentRowCol[$countrowfix+1][$col]);
}
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($col>0)
{
if (isset($ContentRowCol[$countrowfix+1][$col])) ;
{
if ($col<16) // unter Pos 16 in float umrechnen
{
$WertString = $ContentRowCol[$countrowfix+1][$col];
$float = tofloat($WertString);
SetValue($ContentRowCol[$countrowfix][$col],$float);
}
}
}
}
}
//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])) SetValue($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
{
}
// Variable einsortieren
$Nummer = $name;
$stringposition = strpos ( $Nummer, '_' );
$Nummer = substr($Nummer,0,$stringposition);
if ($Nummer =="") $Nummer = 99;
IPS_SetPosition($vid, $Nummer);
if(strpos($name, "n.")>0)
IPS_SetHidden($vid, true);
else
IPS_SetHidden($vid, false);
if($type <> 3)
{
if(($profile !== "") and ($profile != 'PoolServer_cm³s') and ($profile != 'PoolServer_m³/h') ) { IPS_SetVariableCustomProfile($vid, $profile); }
}
return $vid;
}
// String in float umrechnen
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);
}
?>