Hallo Klaus,
anbei mein Script:
Du muss dazu noch einen UPD Socket anlegen und ein Register Variable die auf das Script zeigt.
Im Script die entsprechend ID eintragen und ebenfalls die Kennung des Lüfters.
Fragen immer gerne
Viel Erfolg
Gruß
Jan Peter
<?php
$id_UDP_Socket = xxxxx;
$id_luefter = '0028111856565108'; // Schlafzimmer
$Instanz_Lüfter = IPS_GetParent($_IPS['SELF']) ;
if ( true )
{
//IPS_LogMessage("Lüfter Sender", $_IPS['SENDER'] );
}
if ( $_IPS['SENDER'] == "WebFront" )
{
set_paramter( $Instanz_Lüfter, $id_luefter, $id_UDP_Socket, $_IPS['VARIABLE'], $_IPS['VALUE']);
return;
}
if ( $_IPS['SENDER'] == "RunScript" )
{
if ( array_key_exists('VARIABLE', $_IPS ))
{
set_paramter( $Instanz_Lüfter, $id_luefter, $id_UDP_Socket, $_IPS['VARIABLE'], $_IPS['VALUE']);
}
else
{
$datablock = "";
if (array_key_exists('Speed', $_IPS))
{
$datablock = $datablock . translate_paramter( 'Speed', $_IPS['Speed'] );
}
if (array_key_exists('State', $_IPS))
{
$datablock = $datablock . translate_paramter( 'State', $_IPS['State'] );
}
if (array_key_exists('PowerControl', $_IPS))
{
$datablock = $datablock . translate_paramter( 'PowerControl', $_IPS['PowerControl'] );
}
if (strlen($datablock) >= 2)
{
send_parameter($Instanz_Lüfter, $id_luefter, $id_UDP_Socket, $datablock );
}
}
return;
}
if ( $_IPS['SENDER'] == "Variable" )
{
set_paramter( $Instanz_Lüfter, $id_luefter, $id_UDP_Socket, $_IPS['VARIABLE'], $_IPS['VALUE']);
return;
}
if ( $_IPS['SENDER'] == "Execute" )
{
$Instanz_Lüfter = IPS_GetParent($_IPS['SELF']) ;
IPS_SetName($_IPS['SELF'], "Lüfter Auswertung");
IPS_SetHidden($_IPS['SELF'], true);
$Name = "Status";
$Ident = "State";
if ( IPS_GetObjectIDByIdent($Ident, $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(0);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 25);
IPS_SetVariableCustomAction($id, $_IPS['SELF']);
IPS_SetVariableCustomProfile($id, "~Switch");
}
if (IPS_GetVariableProfile ($profil_name = "PowerControl") === false)
{
IPS_CreateVariableProfile ($profil_name, 1);
}
IPS_SetVariableProfileAssociation($profil_name, 0x01, "Stufe 1","" , -1);
IPS_SetVariableProfileAssociation($profil_name, 0x02, "Stufe 2","" , -1);
IPS_SetVariableProfileAssociation($profil_name, 0x03, "Stufe 3","" , -1);
IPS_SetVariableProfileAssociation($profil_name, 0xFF, "Manuel","" , -1);
$Name = "Leistungsstufe";
$Ident = "PowerControl";
if ( IPS_GetObjectIDByIdent("PowerControl", $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(1);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 26);
IPS_SetVariableCustomAction($id, $_IPS['SELF']);
IPS_SetVariableCustomProfile($id, "PowerControl");
}
$Name = "Speed";
$Ident = "Speed";
if ( IPS_GetObjectIDByIdent($Ident, $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(1);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 27);
IPS_SetVariableCustomAction($id, $_IPS['SELF']);
IPS_SetVariableCustomProfile($id, "~Intensity.100");
}
if (IPS_GetVariableProfile ($profil_name = "Operating_mode") === false)
{
IPS_CreateVariableProfile ($profil_name, 1);
}
IPS_SetVariableProfileAssociation($profil_name, 0x00, "Lüftung","" , -1);
IPS_SetVariableProfileAssociation($profil_name, 0x01, "Wärmerückgewinnung ","" , -1);
IPS_SetVariableProfileAssociation($profil_name, 0x02, "Zuluft","" , -1);
$Name = "Betriebsart";
$Ident = "Operating_mode";
if ( IPS_GetObjectIDByIdent($Ident, $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(1);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 28);
IPS_SetVariableCustomAction($id, $_IPS['SELF']);
IPS_SetVariableCustomProfile($id, "Operating_mode");
}
$Name = "Feuchte";
$Ident = "RL_Humidity";
if ( IPS_GetObjectIDByIdent($Ident, $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(1);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 30);
IPS_SetVariableCustomProfile($id, "~Humidity");
}
$Name = "Zeit bis Filterwechsel";
$Ident = "Time_to_clean";
if ( IPS_GetObjectIDByIdent($Ident, $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(3);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 40);
}
$Name = "Filterreinigung";
$Ident = "filter_clean";
if ( IPS_GetObjectIDByIdent($Ident, $Instanz_Lüfter) == false)
{
$id = IPS_CreateVariable(0);
IPS_SetParent($id,$Instanz_Lüfter);
IPS_SetName($id, $Name);
IPS_SetIdent($id, $Ident);
IPS_SetPosition($id, 40);
}
}
if ( ($_IPS['SENDER'] == "Execute") or ($_IPS['SENDER'] == "TimerEvent") )
{
$start = hex2bin('FDFD');
$type = hex2bin('02');
$id_luefter_blocksize = chr(strlen($id_luefter));
$id_luefter_blocksize = hex2bin('10');
$password = '1111';
$pw_blocksize = hex2bin('04'); //chr(strlen($password));
$funcnumber = hex2bin('01'); //Datenabfrage
//01 = Status
//02 = Lüfterstufe
//25 = Feuchte
//44 = Lüfter Speed bei Manuel
//64 = Zeit bis Filterwechsel
//88 = Filterwechel Aufforderung
//B7 = Betriebsart des Ventilators
$datablock = hex2bin('010225446488B7');
$checksum = calc_checksumm( $start . $type . $id_luefter_blocksize . $id_luefter . $pw_blocksize . $password . $funcnumber . $datablock );
$content = $start . $type . $id_luefter_blocksize . $id_luefter . $pw_blocksize . $password . $funcnumber . $datablock . $checksum;
if (USCK_SendText($id_UDP_Socket, $content))
{
//echo "gesendet";
};
IPS_SetScriptTimer ($_IPS['SELF'], 60*30);
return;
}
if ($_IPS['SENDER'] == "RegisterVariable")
{
$data = $_IPS['VALUE'];
// Lüfter ID Auswerten
$id_read = substr($data, 4, 16);
if ( strcmp($id_read, $id_luefter) != 0 )
{
return;
}
$func = hexdec( bin2hex($data[$position = 25]) ) ;
//IPS_LogMessage("Lüfter Auslesen ", strlen($data) );
if ($func == 0x06 )
{
$i = 26;
while ( $i <= (strlen($data) - 3) )
{
$i = read_paremter( $Instanz_Lüfter, $data, $i);
if ( $i === false)
{
IPS_LogMessage("Lüfter Auslesen ", "Anzahl Paramter Fehler");
return;
};
}
}
else
{
IPS_LogMessage("Lüfter Auslesen ", "func ungleich 6: $func");
}
}
function read_paremter( $Instanz_Lüfter, $data, $position )
{
$Parameter_Id = hexdec( bin2hex($data[$position]) ) ;
//IPS_LogMessage("Lüfter Auslesen ", "Parameter $Parameter_Id");
switch ($Parameter_Id)
{
case 0x01: // Status
$Status = hexdec( bin2hex($data[$position +1]) ) ;
if ($Status == 0)
{
$Status = false;
}
else
{
$Status = true;
}
$id = IPS_GetObjectIDByIdent("State", $Instanz_Lüfter);
SetValueBoolean($id, $Status);
$position = $position +2;
break;
case 0x02: // Leistungsstufe
$Leistungsstufe = hexdec( bin2hex($data[$position +1]) );
$id = IPS_GetObjectIDByIdent("PowerControl", $Instanz_Lüfter);
SetValueInteger($id, $Leistungsstufe);
$position = $position +2;
break;
case 0x44: // Geschwindigkeit
$Speed = hexdec( bin2hex($data[$position +1]) ) ;
$id = IPS_GetObjectIDByIdent("Speed", $Instanz_Lüfter);
if ($Speed == 0)
{
SetValueInteger ($id, 0);
}
else
{
SetValueInteger ($id, round($Speed * 100 /255));
}
$position = $position +2;
break;
case 0x25: // Feuchte
$Humidity = hexdec( bin2hex($data[$position +1]) ) ;
$id = IPS_GetObjectIDByIdent("RL_Humidity", $Instanz_Lüfter);
SetValueInteger ($id, $Humidity );
$position = $position +2;
break;
case 0x64: // Zeit bis Filterwechsel
$id = IPS_GetObjectIDByIdent("Time_to_clean", $Instanz_Lüfter);
SetValueString($id, hexdec( bin2hex($data[$position +3]) ) . " Tage " . hexdec( bin2hex($data[$position + 2]) ) . " Stunden " . hexdec( bin2hex($data[$position +1]) ) . " Minuten" );
$position = $position + 4;
break;
case 0x72: // Zeit gestuerter Betrieb
$position = $position + 2;
break;
case 0x88: // Filterwechsel Aufforderung
$id = IPS_GetObjectIDByIdent("filter_clean", $Instanz_Lüfter);
if (bin2hex($data[$position +1]) == 0)
{
SetValueBoolean($id, false);
}
else
{
SetValueBoolean($id, true);
}
$position = $position + 2;
break;
case 0xB7: // Operating_mode
$mode = hexdec( bin2hex($data[$position +1]) ) ;
$id = IPS_GetObjectIDByIdent("Operating_mode", $Instanz_Lüfter);
SetValueInteger ($id, $mode );
$position = $position +2;
break;
case 0xFE: // Spezial Befehl (Nächster Befehler hat Überlänge)
$position = $position + 2;
break;
default: // ???
IPS_LogMessage("Lüfter Auslesen ", "Parameter nicht bekannt $Parameter_Id");
return false;
break;
}
// Sichtbarkeit
if ( !GetValueBoolean(IPS_GetObjectIDByIdent("State", $Instanz_Lüfter) ) )
{
IPS_SetHidden(IPS_GetObjectIDByIdent("PowerControl", $Instanz_Lüfter) , true);
IPS_SetHidden(IPS_GetObjectIDByIdent("Speed", $Instanz_Lüfter) , true);
IPS_SetHidden(IPS_GetObjectIDByIdent("Operating_mode", $Instanz_Lüfter), true);
IPS_SetHidden(IPS_GetObjectIDByIdent("RL_Humidity", $Instanz_Lüfter), true);
}
else
{
IPS_SetHidden(IPS_GetObjectIDByIdent("Operating_mode", $Instanz_Lüfter), false);
IPS_SetHidden(IPS_GetObjectIDByIdent("RL_Humidity", $Instanz_Lüfter), false);
$id = IPS_GetObjectIDByIdent("PowerControl", $Instanz_Lüfter);
IPS_SetHidden( $id, false);
$Leistungsstufe = GetValueInteger($id);
if ($Leistungsstufe <= 3)
{
IPS_SetHidden(IPS_GetObjectIDByIdent("Speed", $Instanz_Lüfter), true);
}
else
{
IPS_SetHidden(IPS_GetObjectIDByIdent("Speed", $Instanz_Lüfter), false);
}
}
$id = IPS_GetObjectIDByIdent("filter_clean", $Instanz_Lüfter);
if (GetValueBoolean($id) == true)
{
IPS_SetHidden($id, false);
IPS_SetHidden(IPS_GetObjectIDByIdent("Time_to_clean", $Instanz_Lüfter) , true);
}
else
{
IPS_SetHidden($id, true);
IPS_SetHidden(IPS_GetObjectIDByIdent("Time_to_clean", $Instanz_Lüfter) , false);
}
return $position;
}
function set_paramter($Instanz_Lüfter, $id_luefter, $id_UDP_Socket, $id_variable, $value)
{
$ident = IPS_GetObject($id_variable)["ObjectIdent"];
$datablock = translate_paramter( $ident, $value);
send_parameter($Instanz_Lüfter, $id_luefter, $id_UDP_Socket, $datablock );
}
function translate_paramter( $ident, $value)
{
//IPS_LogMessage("Lüfter Parameter Setzen ", "Name: $ident Wert: $value");
switch ($ident)
{
case "State":
if ($value)
{
$value = hex2bin('01');
}
else
{
$value = hex2bin('00');
}
$para = hex2bin('01');
$datablock = $para . $value;
break;
case "PowerControl":
if ($value == 1)
{
$value = hex2bin('01');
}
else if ($value == 2)
{
$value = hex2bin('02');
}
else if ($value == 3)
{
$value = hex2bin('03');
}
else if ($value == 0xFF)
{
$value = hex2bin('FF');
}
else
{
break;
}
$para = hex2bin('02');
$datablock = $para . $value;
break;
case "Speed":
$value = (integer) round($value * 255 / 100);
if ($value >= 255)
{
$value = 255;
}
$value = dechex($value);
if (strlen($value) <= 1)
{
if ($value == '0') $value = hex2bin('00');
if ($value == '1') $value = hex2bin('01');
if ($value == '2') $value = hex2bin('02');
if ($value == '3') $value = hex2bin('03');
if ($value == '4') $value = hex2bin('04');
if ($value == '5') $value = hex2bin('05');
if ($value == '6') $value = hex2bin('06');
if ($value == '7') $value = hex2bin('07');
if ($value == '8') $value = hex2bin('08');
if ($value == '9') $value = hex2bin('09');
if ($value == 'a') $value = hex2bin('0a');
if ($value == 'b') $value = hex2bin('0b');
if ($value == 'c') $value = hex2bin('0c');
if ($value == 'd') $value = hex2bin('0d');
if ($value == 'e') $value = hex2bin('0e');
if ($value == 'f') $value = hex2bin('0f');
}
else
{
$value = hex2bin($value);
}
$para = hex2bin('44');
$datablock = $para . $value;
break;
case "Operating_mode":
if ($value == 0)
{
$value = hex2bin('00');
}
else if ($value == 1)
{
$value = hex2bin('01');
}
else if ($value == 2)
{
$value = hex2bin('02');
}
else
{
break;
}
$para = hex2bin('B7');
$datablock = $para . $value;
break;
default:
IPS_LogMessage("Lüfter Parameter Setzen ", "Variable nicht veränderbar");
break;
}
return $datablock;
}
function send_parameter( $Instanz_Lüfter, $id_luefter, $id_UPD_Socket, $datablock )
{
$Instanz_Lüfter = IPS_GetParent($_IPS['SELF']) ;
$start = hex2bin('FDFD');
$type = hex2bin('02');
//$id_luefter = '0028001856565108'; // Schlafzimmer
//$id_luefter = '001C002B4741570A'; // Kinderzimmer
$id_luefter_blocksize = chr(strlen($id_luefter));
$id_luefter_blocksize = hex2bin('10');
$password = '1111';
$pw_blocksize = hex2bin('04'); //chr(strlen($password));
$funcnumber = hex2bin('03'); // Parameter Schreiben mit Antwort
$checksum = calc_checksumm( $start . $type . $id_luefter_blocksize . $id_luefter . $pw_blocksize . $password . $funcnumber . $datablock );
$content = $start . $type . $id_luefter_blocksize . $id_luefter . $pw_blocksize . $password . $funcnumber . $datablock . $checksum;
if (USCK_SendText($id_UPD_Socket, $content))
{
//echo "gesendet";
};
}
function calc_checksumm( $data )
{
$i = 0;
$chksum = 0;
$chksum2 = hex2bin('0000');
$chksumHexNeu = hex2bin('0000');
$size = strlen($data);
if( ($data[0] == hex2bin('FD')) and ($data[1] == hex2bin('FD')) ) //and ($data[1] == "\xFD"))
{
for($i = 2; $i <= ($size-1); $i++)
{
$chksum = $chksum + ord($data[$i]);
}
$chksumHex = dechex($chksum);
$size = strlen($chksumHex);
if ($size <= 1)
{
$chksumHexNeu[0] = '0';
$chksumHexNeu[1] = '0';
$chksumHexNeu[2] = '0';
$chksumHexNeu[3] = $chksumHex[0];
}
else if ($size == 2)
{
$chksumHexNeu[0] = '0';
$chksumHexNeu[1] = '0';
$chksumHexNeu[2] = $chksumHex[0];
$chksumHexNeu[3] = $chksumHex[1];
}
else if ($size == 3)
{
$chksumHexNeu[0] = '0';
$chksumHexNeu[1] = $chksumHex[0];
$chksumHexNeu[2] = $chksumHex[1];
$chksumHexNeu[3] = $chksumHex[2];
}
else if ($size == 4)
{
$chksumHexNeu[0] = $chksumHex[0];
$chksumHexNeu[1] = $chksumHex[1];
$chksumHexNeu[2] = $chksumHex[2];
$chksumHexNeu[3] = $chksumHex[3];
}
else
{
return false;
}
$chksum2 = hex2bin($chksumHexNeu);
return $chksum2[1] . $chksum2[0];
}
else
{
return false;
}
}