Danke für das Skript, eine schöne Grundlage für mich. Habe mich am Wochenende mal mit einer Helios KWL im Familienkreis beschäftigt und dabei ist dieses, etwas universellere Skript herausgekommen.
Es erstellt automatisch Dummyinstanzen mit den Parametern unterhalb der angegebenen Kategorie. Die obigen drei Angaben (IP, Passwort, Kategorie-ID) sind die einzig notwendigen Angaben. Einmal ausführen sollte alles anlegen.
Wenn eure Lüftungsanlage andere Parameter unterstützt, bzw. ihr welche wollt oder nicht wollt die (nicht) in der Liste stehen, könnt ihr diese relativ leicht für eure Zwecke anpassen.
<?
// hier die entsprechenden Daten eintragen.
$heliosHost = "0.0.0.0";
$heliosPw = '12345';
$catId = 12345;
// zuordnung, was die Werte bedeuten und wie sie dargestellt werden sollen
// die IDs gibt es entweder unter folgender URL oder per "Untersuchen" im Browser
// auf den entsprechenden Feldern des Webinterface.
//https://www.easycontrols.net/de/service/downloads/send/4-software/16-modbus-dokumentation-f%C3%BCr-kwl-easycontrols-ger%C3%A4te
$paramInfo = array(
"v01306" => array("iname" => "System", "name" => "Status", "type" => 3, "prof" => "(Status)", "write" => false),
"online" => array("iname" => "System", "name" => "Online", "type" => 0, "prof" => "HeliosOnline", "write" => false),
"v01300" => array("iname" => "System", "name" => "Fehlermeldungen", "type" => 1, "prof" => "", "write" => false),
"v01301" => array("iname" => "System", "name" => "Warnungen", "type" => 1, "prof" => "", "write" => false),
"v01302" => array("iname" => "System", "name" => "Info-Meldungen", "type" => 1, "prof" => "", "write" => false),
"v01031" => array("iname" => "Wartung", "name" => "Filter wechseln", "type" => 0, "prof" => "HeliosChangeFilter", "write" => false),
"v01032" => array("iname" => "Wartung", "name" => "Filterwechsel Intervall", "type" => 1, "prof" => "HeliosMonthInterval", "write" => false),
"v01033" => array("iname" => "Wartung", "name" => "Filterwechsel Restzeit", "type" => 1, "prof" => "HeliosLongDuration", "write" => false),
"v00101" => array("iname" => "Betrieb", "name" => "Betriebsart", "type" => 1, "prof" => "HeliosOperationMode", "write" => true),
"v00033" => array("iname" => "Betrieb", "name" => "Feuchte-Steuerung", "type" => 1, "prof" => "HeliosRegulatorMode", "write" => true),
"v00102" => array("iname" => "Betrieb", "name" => "Lüfter-Stufe", "type" => 1, "prof" => "HeliosFanLevel1", "write" => true),
"v00094" => array("iname" => "Party", "name" => "Aktiv", "type" => 0, "prof" => "~Switch", "write" => true),
"v00092" => array("iname" => "Party", "name" => "Lüfter-Stufe", "type" => 1, "prof" => "HeliosFanLevel1", "write" => true),
"v00091" => array("iname" => "Party", "name" => "Dauer", "type" => 1, "prof" => "HeliosSetDuration", "write" => true),
"v00093" => array("iname" => "Party", "name" => "Restzeit", "type" => 1, "prof" => "HeliosRemainDuration", "write" => false),
"v00099" => array("iname" => "Ruhe", "name" => "Aktiv", "type" => 0, "prof" => "~Switch", "write" => true),
"v00097" => array("iname" => "Ruhe", "name" => "Lüfter-Stufe", "type" => 1, "prof" => "HeliosFanLevel", "write" => true),
"v00096" => array("iname" => "Ruhe", "name" => "Dauer", "type" => 1, "prof" => "HeliosSetDuration", "write" => true),
"v00098" => array("iname" => "Ruhe", "name" => "Restzeit", "type" => 1, "prof" => "HeliosRemainDuration", "write" => false),
"v00104" => array("iname" => "Sensoren", "name" => "Temperatur Außenluft", "type" => 2, "prof" => "~Temperature", "write" => false),
"v00105" => array("iname" => "Sensoren", "name" => "Temperatur Zuluft", "type" => 2, "prof" => "~Temperature", "write" => false),
"v00106" => array("iname" => "Sensoren", "name" => "Temperatur Fortluft", "type" => 2, "prof" => "~Temperature", "write" => false),
"v00107" => array("iname" => "Sensoren", "name" => "Temperatur Abluft", "type" => 2, "prof" => "~Temperature", "write" => false),
"v00348" => array("iname" => "Sensoren", "name" => "Drehzahl Zuluft", "type" => 1, "prof" => "HeliosRPM", "write" => false),
"v00349" => array("iname" => "Sensoren", "name" => "Drehzahl Abluft", "type" => 1, "prof" => "HeliosRPM", "write" => false),
"v02136" => array("iname" => "Sensoren", "name" => "Luftfeuchte Abluft", "type" => 1, "prof" => "~Humidity", "write" => false),
"v00601" => array("iname" => "Abwesenheit", "name" => "Aktiv", "type" => 1, "prof" => "HeliosVacationMode", "write" => true),
"v00602" => array("iname" => "Abwesenheit", "name" => "Lüfter-Stufe", "type" => 1, "prof" => "HeliosFanLevel", "write" => true),
//"v00603" => array("iname" => "Abwesenheit", "name" => "Startdatum", "type" => 1, "prof" => "~UnixTimestampDate", "write" => true),
//"v00604" => array("iname" => "Abwesenheit", "name" => "Enddatum", "type" => 1, "prof" => "~UnixTimestampDate", "write" => true),
"v00605" => array("iname" => "Abwesenheit", "name" => "Intervallzeit", "type" => 1, "prof" => "HeliosHourInterval", "write" => true),
"v00606" => array("iname" => "Abwesenheit", "name" => "Einschaltdauer", "type" => 1, "prof" => "HeliosSetDuration300", "write" => true),
"v02119" => array("iname" => "Bypass", "name" => "Status", "type" => 0, "prof" => "~Switch", "write" => false),
"v01035" => array("iname" => "Bypass", "name" => "Raumtemperatur", "type" => 1, "prof" => "HeliosTempIntR", "write" => true),
"v01036" => array("iname" => "Bypass", "name" => "Außentemperatur", "type" => 1, "prof" => "HeliosTempIntO", "write" => true),
"v02120" => array("iname" => "Bypass", "name" => "", "type" => 1, "prof" => "(DayOfMonth)", "write" => true),
"v02121" => array("iname" => "Bypass", "name" => "Aktiv ab (Tag.Monat.)", "type" => 3, "prof" => "(DayMonthInterval)", "write" => false),
"v02128" => array("iname" => "Bypass", "name" => "", "type" => 1, "prof" => "(DayOfMonth)", "write" => true),
"v02129" => array("iname" => "Bypass", "name" => "Aktiv bis (Tag.Monat.)", "type" => 3, "prof" => "(DayMonthInterval)", "write" => false),
);
IPS_SetScriptTimer($_IPS['SELF'], 30);
$updatedIdents = array();
$lastErr = '';
if($_IPS['SENDER'] == 'WebFront' || $_IPS['SENDER'] == 'RunScript') {
$ident = IPS_GetObject($_IPS['VARIABLE'])['ObjectIdent'];
$prof = IPS_GetVariable($_IPS['VARIABLE'])['VariableCustomProfile'];
$value = $_IPS['VALUE'];
if($prof == '~UnixTimestampDate') {
$value = date("d.m.Y", $value);
}
$result = heliosSetValue($ident, $value);
if($result === false) {
$result = heliosLogin();
if($result === false) {
return;
} else {
$result = heliosSetValue($ident, $value);
if($result === false) {
echo "Fehler beim Setzen des Parameters: " . $lastErr;
return;
}
}
} // if
} // if
// "Pages"
// 2 = hauptsächlich Uhrzeit und Datum (Abruf nicht nötig, sollte aber gesetzt werden)
// 3 = Party- und Ruhebetrieb Dauer (nicht Restzeit)
// 4 = Party- und Ruhebetrieb Restzeit, Urlaubs-Enddatum
// 6 = Urlaubsmodus Intervall-Einstellungen, Start- und Enddatum
// 10 = IP-Konfiguration
// 11 = Betr.Stundenz.
// 12 = Zähler Filter
// rufe Werte ab (nötigenfalls einloggen)
$result = heliosGetValues();
if($result === false) {
$result = heliosLogin();
if($result === false) {
return;
} else {
$result = heliosGetValues();
if($result === false) {
updateVariable('onlineStatus', $paramInfo['online'], false);
return;
}
}
} // if
updateVariable('onlineStatus', $paramInfo['online'], true);
parseParamStr($result);
$result = heliosGetValues(3);
parseParamStr($result);
$result = heliosGetValues(4);
parseParamStr($result);
$result = heliosGetValues(6);
parseParamStr($result);
$result = heliosGetValues(12);
parseParamStr($result);
// XML-"Page" parsen und Variablen updaten
function parseParamStr($str) {
static $alreadyUpdated = array();
global $paramInfo;
$xml = simplexml_load_string($str);
$i = 0;
foreach($xml->ID as $id) {
$info = false;
$ident = $id->__toString();
$value = $xml->VA[$i];
if(array_key_exists($ident, $paramInfo)) {
$info = $paramInfo[$ident];
}
if(!in_array($ident, $alreadyUpdated)) {
if($info !== false) {
updateVariable($ident, $info, $value);
} else if($_IPS['SENDER'] == 'Execute') {
echo $ident . ' = "' . $value . "\"\r";
}
$alreadyUpdated[] = $ident;
}
$i++;
}
} // parseParamStr
function updateVariable($ident, $info, $value) {
global $catId;
static $dayOfMonth;
$instId = @IPS_GetObjectIDByName($info['iname'], $catId);
if($instId === false) {
$instId = IPS_CreateInstance('{485D0419-BE97-4548-AA9C-C083EB82E61E}');
IPS_SetName($instId, $info['iname']);
IPS_SetParent($instId, $catId);
}
$varId = @IPS_GetObjectIDByIdent($ident, $instId);
if($info['prof'] == '(DayOfMonth)') {
$dayOfMonth = $value;
return;
} else if($info['prof'] == '(DayMonthInterval)') {
$value = $dayOfMonth . '.' . $value . '.';
}
$update = ($_IPS['SENDER'] == 'Execute');
if($varId === false) {
$varId = IPS_CreateVariable($info['type']);
IPS_SetParent($varId, $instId);
IPS_SetIdent($varId, $ident);
$update = true;
}
if($update) {
echo $ident . ' ' . $info["name"] . ' = "' . $value . "\"\r";
if(substr($info['prof'], 0, 1) != "(") {
updateVariableProfile($info['prof'], $info['type']);
IPS_SetVariableCustomProfile($varId, $info['prof']);
}
if($info['write']) {
IPS_SetVariableCustomAction($varId, $_IPS['SELF']);
} else {
IPS_SetVariableCustomAction($varId, 0);
}
IPS_SetName($varId, $info["name"]);
}
if($info['prof'] == 'HeliosLongDuration') {
$value = calculateRemainingDays($value);
} else if($info['prof'] == '~UnixTimestampDate') {
$value = strtotime($value);
} else if($info['type'] == 0) {
$value = $value > 0;
} else if($info['type'] == 1) {
if($value == '-') return;
$value = intval($value);
} else if($info['type'] == 2) {
if($value == '-') return;
$value = floatval($value);
} else if($info['prof'] == '(Status)') {
$value = decodeStatusStr($value);
} else {
$value = strval($value);
}
SetValue($varId, $value);
} // updateVariable
function updateVariableProfile($prof, $type) {
if($prof == '') return;
if(!IPS_VariableProfileExists($prof)) {
IPS_CreateVariableProfile($prof, $type);
}
switch($prof) {
case "HeliosRegulatorMode":
IPS_SetVariableProfileAssociation($prof, 0, "Aus", "Power", -1);
IPS_SetVariableProfileAssociation($prof, 1, "Stufig", "Shutter", -1);
IPS_SetVariableProfileAssociation($prof, 2, "Stufenlos", "Intensity", -1);
break;
case "HeliosFanLevel":
IPS_SetVariableProfileValues($prof, 0, 4, 1);
IPS_SetVariableProfileIcon($prof, "Ventilation");
break;
case "HeliosFanLevel1":
IPS_SetVariableProfileValues($prof, 1, 4, 1);
IPS_SetVariableProfileIcon($prof, "Ventilation");
break;
case "HeliosOperationMode":
IPS_SetVariableProfileAssociation($prof, 0, "Automatik", "Robot", -1);
IPS_SetVariableProfileAssociation($prof, 1, "Handbetrieb", "Execute", -1);
break;
case "HeliosRPM":
IPS_SetVariableProfileValues($prof, 0, 9999, 1);
IPS_SetVariableProfileIcon($prof, "TurnRight");
IPS_SetVariableProfileText($prof, "", " U./Min.");
break;
case "HeliosVacationMode":
IPS_SetVariableProfileAssociation($prof, 0, "Aus", "Power", -1);
IPS_SetVariableProfileAssociation($prof, 1, "Intervall", "Distance", 0x00FF00);
IPS_SetVariableProfileAssociation($prof, 2, "Konstant", "Script", 0x00FF00);
break;
case "HeliosSetDuration":
IPS_SetVariableProfileValues($prof, 5, 180, 5);
IPS_SetVariableProfileIcon($prof, "Clock");
IPS_SetVariableProfileText($prof, "", " Min.");
break;
case "HeliosSetDuration300":
IPS_SetVariableProfileValues($prof, 5, 300, 5);
IPS_SetVariableProfileIcon($prof, "Clock");
IPS_SetVariableProfileText($prof, "", " Min.");
break;
case "HeliosRemainDuration":
IPS_SetVariableProfileValues($prof, 0, 180, 1);
IPS_SetVariableProfileIcon($prof, "Clock");
IPS_SetVariableProfileText($prof, "", " Min.");
break;
case "HeliosChangeFilter":
IPS_SetVariableProfileAssociation($prof, false, "Nein", "Ok", -1);
IPS_SetVariableProfileAssociation($prof, true, "Ja", "Gear", -1);
break;
case "HeliosMonthInterval":
IPS_SetVariableProfileValues($prof, 0, 12, 1);
IPS_SetVariableProfileIcon($prof, "Calendar");
IPS_SetVariableProfileText($prof, "", " Mon.");
break;
case "HeliosLongDuration":
IPS_SetVariableProfileValues($prof, 0, 356, 1);
IPS_SetVariableProfileIcon($prof, "Calendar");
IPS_SetVariableProfileText($prof, "", " Tg.");
break;
case "HeliosTempIntR":
IPS_SetVariableProfileValues($prof, 10, 40, 1);
IPS_SetVariableProfileIcon($prof, "Temperature");
IPS_SetVariableProfileText($prof, "", " °C");
break;
case "HeliosTempIntO":
IPS_SetVariableProfileValues($prof, 5, 20, 1);
IPS_SetVariableProfileIcon($prof, "Temperature");
IPS_SetVariableProfileText($prof, "", " °C");
break;
case "HeliosHourInterval":
IPS_SetVariableProfileValues($prof, 1, 24, 1);
IPS_SetVariableProfileIcon($prof, "Clock");
IPS_SetVariableProfileText($prof, "", " h");
break;
case "HeliosOnline":
IPS_SetVariableProfileAssociation($prof, false, "Offline", "Warning", 0xFF0000);
IPS_SetVariableProfileAssociation($prof, true, "Online", "Ok", -1);
break;
}
} // updateVariableProfile
function calculateRemainingDays($minutes) {
return intdiv(intval($minutes), 60 * 24);
} // calculateRemainingDays
function decodeStatusStr($str) {
$result = array();
$place = 1;
for($i = strlen($str) - 1; $i >= 0; $i--) {
$flag = substr($str, $i, 1) == '1';
switch($place) {
case 1: if(!$flag) $result[] = "Bootvorgang läuft"; break;
case 2: if($flag) $result[] = "FW-Update läuft"; break;
case 3: if($flag) $result[] = "FW-Update steht bevor"; break;
case 5: if($flag) $result[] = "Partybetrieb"; break;
case 6: if($flag) $result[] = "Ruhebetrieb"; break;
case 7: if($flag) $result[] = "Abwesenheit"; break;
case 27: if($flag) $result[] = "Filterwechsel erforderlich"; break;
case 31: if($flag) $result[] = "Master-PW erforderlich"; break;
}
$place++;
}
if(count($result) > 0) {
return implode(', ', $result);
} else {
return "Normalbetrieb";
}
} // decodeStatusStr
// alle Werte abrufen
function heliosGetValues($page = 8) {
if($_IPS['SENDER'] == 'Execute') {
echo "Requesting page " . $page . "\r";
}
return heliosReq("data/werte" . strval($page) . ".xml", "anzeig.htm", "xml=/data/werte" . strval($page) . ".xml");
}
// Login versuchen
function heliosLogin() {
global $heliosPw;
return heliosReq("info.htm", "info.htm", 'v00402=' . $heliosPw);
}
// Parameter setzen
function heliosSetValue($id, $value) {
return heliosReq("info.htm", "anzeig.htm", $id . '=' . $value);
}
// allgemeinen Request an Lüftungsanlage senden und Ergebnis zurückliefern
function heliosReq($path, $ref, $postFields) {
global $heliosHost, $heliosPw, $lastErr;
$header[] = "Connection: close";
$header[] = "Origin: http://" . $heliosHost;
$header[] = "User-Agent: Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36";
$header[] = "Content-Type: text/plain;charset=UTF-8";
$header[] = "Accept: */*";
$header[] = "Referer: http://" . $heliosHost . "/" . $ref;
$header[] = "Accept-Encoding: gzip, deflate";
$header[] = "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4";
$ch = curl_init('http://' . $heliosHost . '/' . $path);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, 1000);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 1000);
$result = curl_exec($ch);
if($result === false) $lastErr = curl_error($ch);
curl_close($ch);
return $result;
} // heliosReq
?>