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)))
);
}
?>