Hy,
also ich mache es so, siehe Bilder. Von WF aus bedienbar mit Dimmen,
Und hier mal das Skript
<?
/*
*******************************
IP-SYMCON Event Scripting
*******************************
File : Chromoflex.ips.php
Trigger : $IPS_VALUE
Interval :
*/
// Abfragen ob eingeschaltet
//$Status = GetValue(21167 /*[Objekt #21167 existiert nicht]*/);
$dimmer = GetValue(22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/);
if($IPS_SENDER == "WebFront")
{
SetValue($IPS_VARIABLE, $IPS_VALUE);
}
if ($IPS_VARIABLE == 22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/) {
$rot_org = GetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/);
$gruen_org = GetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/);
$blau_org = GetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/);
if (($rot_org/$dimmer*$IPS_VALUE <=255) and ($gruen_org/$dimmer*$IPS_VALUE <=255) and ($blau_org/$dimmer*$IPS_VALUE <=255)) {
$rot_neu = $rot_org / $dimmer * $IPS_VALUE;
if ($rot_neu >= 255) { $rot_neu = 255; }
$gruen_neu = $gruen_org / $dimmer * $IPS_VALUE;
if ($gruen_neu >= 255) { $gruen_neu = 255; }
$blau_neu = $blau_org / $dimmer * $IPS_VALUE;
if ($blau_neu >= 255) { $blau_neu = 255; }
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/, $rot_neu);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, $gruen_neu);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, $blau_neu);
} else {
SetValue(22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/, $dimmer);
}
}
define ("Comport",35107 /*[Serial Port-Chromo]*/ );
$Startbyte = "\xCA"; // StartByte (Muss nicht verändert werden)
$Adresse = "\x00\x00\x00"; // Adresse 0,0,0 = Broadcast
switch ($IPS_VALUE)
{
case "1":
SetValue(26511 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Programm]*/, 269);
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/ , 80);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, 0);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, 0);
break;
case "260":
Reseten(); // Funktion aufrufen
IPS_Sleep(750); // 750ms warten, ansonsten starten die Programme nicht(Timing)
$cmd = chr(0).chr(3).chr(0x7D).chr(0x15).chr(0).chr(0xCB); //Programm. 0xD1 startet Programm 3
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
return;
break;
case "261":
Reseten(); // Funktion aufrufen
IPS_Sleep(750); // 750ms warten, ansonsten starten die Programme nicht(Timing)
$cmd = chr(0).chr(3).chr(0x7D).chr(0x15).chr(0).chr(0xCE); //Programm. 0xD1 startet Programm 3
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
return;
break;
case "262":
Reseten(); // Funktion aufrufen
IPS_Sleep(750); // 750ms warten, ansonsten starten die Programme nicht(Timing)
$cmd = chr(0).chr(3).chr(0x7D).chr(0x15).chr(0).chr(0xDD); //Programm. 0xD1 startet Programm 3
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
return;
break;
/*Programmnummer aufrufen 0-7 und 9. Es erfolgt erst ein Reset,
danach wird das Programm mit einer kleinen Verzögerung aufgerufen, diese muss sein, sonst startet das Programm nicht.
Programm = 200+3*Programmnummer. Hier als Beispiel Nr.3, 200 + 3 * 3 = 209 entspricht 0xD1*/
case "263": // Eigenes Programm(Alarm)
Reseten(); // Funktion aufrufen
IPS_Sleep(750); // 750ms warten, ansonsten starten die Programme nicht(Timing)
$cmd = chr(0).chr(3).chr(0x7D).chr(0x15).chr(0).chr(0xD7); //Programm. 0xD1 startet Programm 3
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
return;
break;
case "265": // Weiß
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/ , 255);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, 255);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, 255);
SetValue(22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/, 255);
break;
case "266": // Gelb
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/ , 255);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, 255);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, 0);
SetValue(22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/, 255);
break;
case "267": // Violett
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/ , 204);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, 51);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, 153);
SetValue(22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/, 255);
break;
case "268": // Chromoflex ausschalten(Standby) alle Werte auf 0
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/ , 0);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, 0);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, 0);
SetValue(22437 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Dimmen]*/, 255);
break;
case "269": // Nach Reset startet das Default Programm
Reseten(); // Funktion aufrufen
break;
default:
SetValue(26511 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Programm]*/, 264);
break;
}
// Werte einlesen
$Rot = GetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/);
$Gruen = GetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/);
$Blau = GetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/);
// Status setzen
$cmd = chr(0).chr(2).chr(0x7E).chr(0x12).chr(0x01);
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
//Farben setzen ==> Set
$cmd = chr(0).chr(4).chr(0x7E).chr(4).chr($Rot).chr($Gruen).chr($Blau);
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
//Level setzen
$cmd = chr(0).chr(4).chr(0x7E).chr(0).chr($Rot).chr($Gruen).chr($Blau);
$txt = $Adresse.$cmd;
$crc = CRC16r($Startbyte.$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport, $Startbyte.$txt.$crc);
// Funktion zur Checksummenberechnung by HJH
function CRC16r($s) // CRC16 reverse
{
$CRCreg = 0xffff << 1; // Startwert
$PLYreg = 0xA001 << 1; // Polynom
$len = strlen($s);
for ($cp=0; $cp<$len; $cp++)
{
$CRCreg ^= ord($s[$cp]) << 1;
for ($bp=0; $bp<8; $bp++)
{
$CRCreg >>= 1;
if ($CRCreg & 0x01) $CRCreg ^= $PLYreg;
}
}
$crc = $CRCreg >> 1;
$crcLo = $crc & 0xff;
$crcHi = $crc >> 8;
return chr($crcHi).chr($crcLo);
}
// Funktion Reseten
function Reseten()
{
SetValue(28086 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Rot]*/ , 0);
SetValue(18850 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Grün]*/, 0);
SetValue(34484 /*[Räume\ EG\Wohnzimmer\Chromoflex WF\Blau]*/, 0);
$cmd = chr(0).chr(0).chr(0xFE);
$txt = "\x00\x00\x00".$cmd;
$crc = CRC16r("\xCA".$txt);
$txt = str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt = str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
Comport_Sendtext(Comport,"\xCA".$txt.$crc);
}
?>