Chromoflex Script

Update 24.1.2011: Dieses Script funktioniert nur mit Chromoflex für RS232. NICHT mit Chromoflex RC

Hallo zusammen

Wie vor einigen Tagen angekündigt hab ich mein Chromoflex Script für den allgemeinen Gebrauch umgebaut.
Das möche ich nun an euch weitergeben.
Vorweg gleich mal ein Dank an einige andere Script Schreiber, vieles hab ich mir nur aus im Forum vorhandenen Ideen und Codeschnipseln zusammengesucht.
Will mich keinesfalls mit fremden Federn schmücken.

Meine Variante besteht aus 3 Scripten.
setup“ … das Installationsscript um alle Variablen und Profile anzulegen

update“… dies wird von den Webfrontelementen aufgerufen und steuert seinerseits andere Webfrontelemente

set_Chromoflex“ … dies steuert die Chromoflex Hardware

Vorbereitung der Installation:

  1. Korrekte Funktion des Chromoflex mit der Original Software überprüfen
  2. Chromoflex Sofware wieder beenden. Diese darf nicht mit IPS zusammen aktiv sein.
  3. In IPS eine I/O Instanz fürs entsprechende Serielle Port einrichten,
    Parameter 9600,8,N,1 - Port öffnen

Optional:
Bei mir war auch die Verwendung eines USB/RS232 Wandlers problemlos möglich (muß aber nicht immer so sein)
Ich verwende zzt. zwei XBee Module um das Chromoflex per Funk anzubinden.
Das funktioniert hier ebenfalls einwandfrei.

Installation:
1. eine Kategorie beliebigen Namens anlegen
2. die drei Scripte in diese Kategorie kopieren ( Namen müssen exakt geschrieben sein, und dürfen sich nicht ändern)
3. die beiliegende Datei: color_bar.png nach „…IP-Symcon/Webfront/User“ kopieren
4. das „setup“ Script ausführen
5. im Script „set_Chromoflex“ die instance Id des Seriellen Ports eintragen an dem das Chromoflex angeschlossen ist.

5. Bitte keinesfalls irgendwelche Variablennamen ändern, dann funktioniert nämlich nix mehr.

Funktion:
Ich denke mal es ist soweit selbsterklärend, einfach klicken und sich freuen.

Es ist auch möglich die Variablen durch eigene Scripte zu beschreiben, und so eigene Sequenzen zu erstellen.
Das würde dann zb. so aussehen:


.....
SetValueInteger(58697 /*[Räume\Flur\Weinregal\SettlingTime & Brightness\Helligkeit]*/,100);
SetValueInteger(43676 /*[Räume\Flur\Weinregal\SettlingTime & Brightness\DimTime]*/,20);
IPS_RunScript(12817 /*[Räume\Flur\Weinregal\Scripte\random]*/);
IPS_RunScriptEx(28613 /*[Räume\Flur\Weinregal\Scripte\set_Chromoflex]*/,Array("ChromoflexMode" => 0.0)); //Chromoflex setzen
}
.....

Warnung: Die Scripte wurden nach bestem Wissen und Gewissen erstellt, und bei mir ausgiebig getestet.
Trotzdem kann ich natürlich für Funktion, oder evtl. gar Schäden an anderen Systemen keine Garantie übernehmen.

Tja und wenn mir jemand einen Gefallen tun möchte, so möge er bitte ein paar paar passende Icons für Webfront basteln.
Ich würds dann noch in die Installationsroutine dazubauen.

Das „setup“ Script:


# Variablenprofile anlegen
if (IPS_VariableProfileExists("my_Chromoflex_Prog")==False) {
IPS_CreateVariableProfile('my_Chromoflex_Prog',1);
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 1, "Normal","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 2, "Slow","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 3, "Blob","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 4, "User","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 5, "LSD","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 6, "Fire","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 7, "Flash","");
IPS_SetVariableProfileAssociation("my_Chromoflex_Prog", 8, "Burst","");
}

if (IPS_VariableProfileExists("my_ColorSlider")==False) {
IPS_CreateVariableProfile('my_ColorSlider',1);
IPS_SetVariableProfileValues("my_ColorSlider", 0, 100, 1);
IPS_SetVariableProfileText("my_ColorSlider", "", "%");
}

if (IPS_VariableProfileExists("my_RGBSlider")==False) {
IPS_CreateVariableProfile('my_RGBSlider',1);
IPS_SetVariableProfileValues("my_RGBSlider", 0, 1000, 1);
IPS_SetVariableProfileText("my_RGBSlider", "", "%");
}

if (IPS_VariableProfileExists("my_RGBPresets")==False) {
IPS_CreateVariableProfile('my_RGBPresets',1);
IPS_SetVariableProfileAssociation("my_RGBPresets", 1, "White","");
IPS_SetVariableProfileAssociation("my_RGBPresets", 2, "Random","");
}


$name_RGB = "Color";
$name_T_B = "Time & Brightness";
$ParentID = IPS_GetObject($IPS_SELF);
$ParentID = $ParentID['ParentID'];
IPS_SetHidden($IPS_SELF,true);
# Scripte definieren
$id_update = @IPS_GetScriptIDByName("update", $ParentID);
IPS_SetHidden($id_update,true);

$id_setChromoflex = @IPS_GetScriptIDByName("set_Chromoflex", $ParentID);
IPS_SetHidden($id_setChromoflex,true);

# DummyInstanzen anlegen
$id_RGB = getId($name_RGB);
IPS_SetPosition($id_RGB, 5);
$id_T_B = getId($name_T_B);
IPS_SetPosition($id_T_B, 10);

#Varianblen anlegen
$id = CreateVariableByName($ParentID, "Program_Selection", 1);
IPS_SetVariableCustomProfile($id, "my_Chromoflex_Prog");
IPS_SetPosition($id, 15);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Red", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetPosition($id, 20);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Green", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetPosition($id, 25);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Blue", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetPosition($id, 30);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Presets", 1);
IPS_SetVariableCustomProfile($id, "my_RGBPresets");
IPS_SetPosition($id, 15);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "RGB", 1);
IPS_SetVariableCustomProfile($id, "my_RGBSlider");
IPS_SetPosition($id, 10);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "RGB-Table", 3);
IPS_SetVariableCustomProfile($id, "~HTMLBox");
IPS_SetPosition($id, 5);

SetvalueString($id, '<TABLE width="100%"><TR><TD width="65px"></TD><TD><img src="user/color_bar.png" width="100%" height="35" align="middle" ></TD><TD width="65px"></TD></TR></TABLE>');


$id = CreateVariableByName($id_T_B, "Brightness", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_T_B, "Dim-Time", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetVariableCustomAction($id, $id_update);


echo " Installation finished";


function CreateVariableByName($id, $name, $type)
{
global $IPS_SELF;
   $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");
	}
   return $vid;
}

function getId($name) {
   global $IPS_SELF;
   $ParentID = IPS_GetObject($IPS_SELF);
	$ParentID = $ParentID['ParentID'];

	$ID = @IPS_GetObjectIDByName($name, $ParentID);
	if ($ID == 0) {
  		$dummy=IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");  #Dummy Instance
		IPS_ApplyChanges($dummy);
		IPS_SetName($dummy,$name);
		IPS_SetParent($dummy,$ParentID);
   $ID = @IPS_GetObjectIDByName($name, $ParentID);
	}
return $ID;
}



?>

Das „update“ Script

<?
// This Script is called by Sliders and Button in Webfront
// it updates the separate R-G-B Sliders and forward necessary parameters to
// set_Chromoflex Script

{
// Get categorie ID
$parentID = IPS_GetObject($IPS_SELF);
$parentID = $parentID['ParentID'];
// Get all variable IDs
$id_Color = @IPS_GetInstanceIDByName("Color", $parentID);
$id_Red = @IPS_GetVariableIDByName("Red", $id_Color);
$id_Green = @IPS_GetVariableIDByName("Green", $id_Color);
$id_Blue = @IPS_GetVariableIDByName("Blue", $id_Color);
$id_RGB = @IPS_GetVariableIDByName("RGB", $id_Color);
$id_Presets = @IPS_GetVariableIDByName("Presets", $id_Color);

$id_setChromoflex = @IPS_GetScriptIDByName("set_Chromoflex", $parentID);
$id_Programwahl = @IPS_GetVariableIDByName("Program_Selection", $parentID);



SetValueinteger($IPS_VARIABLE, $IPS_VALUE);
Switch ($IPS_VARIABLE) {
// suppport fixed Color Presets
case $id_Presets: //Presets
if ($IPS_VALUE == 2) {
	setvalueinteger($id_Red /*..Color\Rot]*/,rand(0,100));
	setvalueinteger($id_Green /*..Color\Grün]*/,rand(0,100));
	setvalueinteger($id_Blue /*../Color\Blau]*/,rand(0,100));
	setvalueinteger($id_RGB /*../Color\RGB*/,0);
}
if ($IPS_VALUE == 1) {
	setvalueinteger($id_Red /*..Color\Rot]*/,100);
	setvalueinteger($id_Green /*..Color\Grün]*/,100);
	setvalueinteger($id_Blue /*../Color\Blau]*/,100);
	setvalueinteger($id_RGB /*../Color\RGB*/,0);
}

setvalueinteger($IPS_VARIABLE,0);
break;

case $id_Red:
setvalueinteger($id_RGB /*../Color\RGB*/,0);
break;

case $id_Green:
setvalueinteger($id_RGB /*../Color\RGB*/,0);
break;

case $id_Blue:
setvalueinteger($id_RGB /*../Color\RGB*/,0);
break;

// Combined RGB Slider
case $id_RGB:  //Farbband Slider
$colorVal = $IPS_VALUE;
// RED > ORANGE > YELLOW
if ($colorVal >= 0 && $colorVal <= 170) {
    $redPwr = 255;
    $bluePwr = 0;
    $greenPwr = mape($colorVal, 0, 170, 0, 255);
}

// YELLOW > LIME?? > GREEN
if ($colorVal > 170 && $colorVal <= 341) {
    $greenPwr = 255;
    $bluePwr = 0;
    $redPwr = mape($colorVal, 341, 170, 0, 255);
}

// GREEN > TURQOUISE
if ($colorVal > 341 && $colorVal <= 511) {
    $greenPwr = 255;
    $redPwr = 0;
    $bluePwr = mape($colorVal, 341, 511, 0, 255);
}

// TURQOUISE > BLUE
if ($colorVal > 511 && $colorVal <= 682) {
    $bluePwr = 255;
    $redPwr = 0;
    $greenPwr = mape($colorVal, 682, 511, 0, 255);
}

// BLUE > PURPLE
if ($colorVal > 682 && $colorVal <= 852) {
    $bluePwr = 255;
    $greenPwr = 0;
    $redPwr = mape($colorVal, 682, 852, 0, 255);
}

// PURPLE > RED
if ($colorVal > 852 && $colorVal <= 1023) {
    $redPwr = 255;
    $greenPwr = 0;
    $bluePwr = mape($colorVal, 1023, 852, 0, 255);
}
// update seperate RGB Sliders
setvalueinteger($id_Red /*..Color\Rot]*/,intval($redPwr/2.5));
setvalueinteger($id_Green /*..Color\Grün]*/,intval($greenPwr/2.5));
setvalueinteger($id_Blue /*../Color\Blau]*/,intval($bluePwr/2.5));
IPS_RunScriptEx($id_setChromoflex /*..\/Set_Chromoflex*/,Array("ChromoflexMode" => 0.0)); //Chromoflex setzen
break;
}

}
// call set_Chromoflex Script and call build in Scene
if ($IPS_VARIABLE ==$id_Programwahl /*../Programauswahl]*/){
IPS_RunScriptEx($id_setChromoflex /*..\/Set_Chromoflex*/,Array("ChromoflexMode" => getvalue($id_Programwahl /*../Programauswahl]*/))); //Chromoflex setzen
}
else {
// call set_Chromoflex Script and call static RGB Color
setvalueinteger($id_Programwahl /*../Programauswahl]*/,0);
IPS_RunScriptEx($id_setChromoflex /*..\/Set_Chromoflex*/,Array("ChromoflexMode" => 0.0)); //Chromoflex setzen
}


// support function for combiend RGB Slider
function mape($Value, $min, $max, $new_min, $new_max)
{
    $range = $max - $min;
    $new_range = $new_max - $new_min;
    $scaling = $new_range / $range;
    $new_Value = round(($Value - $min)*$scaling);
    if ($range < 0)
    {
        $new_Value = round(($Value - $max)*$scaling);
        $new_Value = $new_max + $new_Value;
    }
    return $new_Value;
}

?>


Das „set_Chromoflex“ Script

<?
// This Script is called by "update" Script.
// it reads settings from Webfront and forward to Chromoflex Module
// Configuration:
// SET Chromoflex Module Adress, check Chromoflex Dokumentation for further Info
// If only one Module is connected default setting will be fine.
$addr=chr(0).chr(0).chr(0); //Adresse from Chromoflex Moduls   0,0,0 = Broadcast = all connected Modules

//IPS InstanceID of SerialPort where your Chromoflex is connected
define ("ID_CommPort",55219);
// make shure your SerialPort is set to 9600,8,N,1
// Test correct Hardware Function and settings with Original Chromoflex Software
// Note its not posible to have IPS & Chromoflex Software talking to same ComPort at the same time


//______________________________________________________________________________________________

//      NO more User settings below this line
//______________________________________________________________________________________________

// get Kategory ID
$parentID = IPS_GetObject($IPS_SELF);
$parentID = $parentID['ParentID'];
// Get Variable IDs
$id_Color = @IPS_GetInstanceIDByName("Color", $parentID);
$id_Red = @IPS_GetVariableIDByName("Red", $id_Color);
$id_Green = @IPS_GetVariableIDByName("Green", $id_Color);
$id_Blue = @IPS_GetVariableIDByName("Blue", $id_Color);

$id_B_T = @IPS_GetInstanceIDByName("Time & Brightness", $parentID);
$id_Brightness = @IPS_GetVariableIDByName("Brightness", $id_B_T);
$id_Dim_Time = @IPS_GetVariableIDByName("Dim-Time", $id_B_T);

//_________________________________________________________________________________________________
// Check If static RGB Mode or Chromoflex interenal Scenes should be used
IF ($ChromoflexMode > 0) {

// Code for Chromoflex internal Scenes
$cmd=chr(0).chr(0).chr(0xFE); //RESET
send_command($addr.$cmd);
IPS_Sleep(700);

$ProgNr=200+($ChromoflexMode*3)-3;  // $IPS_Value = 1 bis 8 für Chromoflex interen Modes,
$cmd = chr(0).chr(3).chr(0x7D).chr(0x15).chr(0).chr($ProgNr);
send_command($addr.$cmd);
}

// Code for static RGB Mode
else {
//Switch to manual Mode
$cmd=chr(0).chr(3).chr(0x7E).chr(0x11).chr(0x01).chr(0x01);
send_command($addr.$cmd);

$dimtime=GetValue($id_Dim_Time /*.../ DimTime]*/)*2.55;
echo $dimtime;
$cmd=chr(0).chr(5).chr(0x7E).chr(17).chr(1).chr(0x00);
 send_command($addr.$cmd);

//set increments -> 255 = immediate, 1 = 2,55ms for step from 0 to 255
$cmd=chr(0).chr(5).chr(0x7E).chr(8).chr($dimtime).chr($dimtime).chr($dimtime).chr(0x00);
send_command($addr.$cmd);

//Set colors
$bright = getvalue($id_Brightness /*../Brightness*/);
$red=(getvalue($id_Red /*../Color\Red]*/)*2.5 / 100)*$bright;
$green=(getvalue($id_Green /*../Color\Green]*/)*2.5 / 100)*$bright;
$blue=(getvalue($id_Blue /*../Color\Blue]*/)*2.5 / 100)*$bright;

$cmd=chr(0).chr(5).chr(0x7E).chr(4).chr($red).chr($green).chr($blue).chr(0x00);
send_command($addr.$cmd);
}


//_________________________________________________________________________________________________

// Code to send Commands to Chromoflex
//_________________________________________________________________________________________________

function send_command($txt) {
$head=chr(0xCA); //StartByte
$crc=crc16($head.$txt);
$txt=str_replace(chr(0xCB), chr(0xCB).chr(0x01), $txt);
$txt=str_replace(chr(0xCA), chr(0xCB).chr(0x00), $txt);
COMPort_SendText(ID_CommPort/*[Serial Port]*/, $head.$txt.$crc);
}

//_________________________________________________________________________________________________

// Calc Checksumm
//___________________________________________________________________________________________________

function CRC16($s)       // CRC16 reverse
{
 $CRCreg = 0xffff << 1;   // Start
 $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);
}

?>


color_bar.png

Der absolute Hammer!!! Einfacher gehts nicht.

Was soll ich sagen, es funktioniert einfach PERFEKT!!! :loveips:

VIELEN VIELEN DANK!!!

Wow, das sieht toll aus.

Derzeit suche ich noch eine Möglichkeit meine beiden LED-Treiber (absichtlich nicht im Master / Slave Betrieb) separat zu steuern.

Wäre so etwas über Deine Skripte möglich?

Schöne Grüße,
Stephan

@Stephan

Du meinst du hast 2 Chromoflex Module, beide hängen an jeweils eigenen ComPort ?
Ja, du kannst bedenkenlos mehrere Instanzen anlegen.

Du meinst du hast 2 Chromoflex Module, beide hängen an demselben ComPort ?
Vermutlich Ja, müßte durch anpassen der $addr im „set_Chromoflex“ Script funktionieren.
Ich hab bis jetzt aber selbst nur ein Modul, drum auch noch nicht ausprobiert.

gruß
bb

Hallo Bernhard,

für mich gilt die zweite Variante.
Ich habe 2 Module, die ich gerne über einen gemeinsamen Comport steuern würde.
So wie ich Dich verstanden habe könnte es klappen indem ich die Installation 2 Mal durchführe und die Adresse der jeweiligen Module fest hinterlege.

Ich werde das am WE mal ausprobieren.

Vielen Dank für das rasche Feedback,
Stephan

Hallo Bernhard,

sieht echt klase aus - und ist genau die Funktionalität die ich auch suche.
Der Haken: Ich habe keine Chromoflex sonder eine EIB/Dali-Lösung.

Wäre es denkbar dein Script rund um die EIB_Scale Funktion anzupassen ?
Was meinst Du ?

Besten Dank für Dein Feedback,

@djtark

Warum solls nicht möglich sein ?

gruß
bb

sorry, etwas genauer formuliert:

wie groß schätzt du den aufwand ein, kann ich das selbst ?
reicht copy & paste aus ? wie tricky ist die ansprache der chromoflex´s - reicht es diese durch meine eib-befehle zu ersetzen ?

Tja, und ich hab kein Dali.

Du müßtest im set_Chromoflex Script
an dieser Stelle:

//Set colors 
$bright = getvalue($id_Brightness /*../Brightness*/); 
$red=(getvalue($id_Red /*../Color\Red]*/)*2.5 / 100)*$bright; 
$green=(getvalue($id_Green /*../Color\Green]*/)*2.5 / 100)*$bright; 
$blue=(getvalue($id_Blue /*../Color\Blue]*/)*2.5 / 100)*$bright; 

$cmd=chr(0).chr(5).chr(0x7E).chr(4).chr($red).chr($green).chr($blue).chr(0x00); 
send_command($addr.$cmd); 

deine Funktionen um die Dali Dimmer anzusteueren reinhängen.

Der Wertebereich der $red, $green, $blue Variablen geht von 0-255.
ggfl. mußt noch auf den Dali umskalieren.

Die Chromoflex eigenen Scenen kannst natürlich erstmal nicht aufrufen.

gruß
bb

besten dank, da wag ich mich mal ran.

die skalierung ist ebenso 0…255 somit muss ich nichts umrechnen.

klar, die chromoflex implementierten szenen hab ich nicht,
aber die grundfunktionalität wäre schon mal spitze.

ich meld mich sier wieder - und wenns fragen sind gg

vg

Hallo,

geht das Script auch für den IPS-RGBW 868 Controller ?

Denke nämlich gerade darüber nach mir den zu kaufen.

Hi

Wenn ich mir steiners Beispiele für sein IPS-RGBW 868 ansehe sollts eigentlich keine große Zauberei sein.
Paar Zeilen Code umbiegen und geht.

gruß
bb

Hallo,
habe mich mal versucht dies auf die IPS-RGBW868 umzuschreiben.

Das „setup“ Script:


<?
# Variablenprofile anlegen
if (IPS_VariableProfileExists("my_RGBW868_Prog")==False) {
/*
0 – alle RGBW auf Aus
1 – alle RGBW auf den letzten Helligkeits-Wert
2-  Blinken langsam
3-  Blinken schnell
4-  Blitzen (Flash) langsam
5-  Blitzen (Flash) schnell
6-  An- u. Abschwellen (Fade)  langsam
*/
IPS_CreateVariableProfile('my_RGBW868_Prog',1);
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 0, "Aus","");
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 1, "Letzter Wert","");
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 2, "Blinken langsam","");
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 3, "Blinken schnell","");
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 4, "Blitzen langsam","");
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 5, "Blitzen schnell","");
IPS_SetVariableProfileAssociation("my_RGBW868_Prog", 6, "An und Abschwellen","");
}

if (IPS_VariableProfileExists("my_ColorSlider")==False) {
IPS_CreateVariableProfile('my_ColorSlider',1);
IPS_SetVariableProfileValues("my_ColorSlider", 0, 100, 1);
IPS_SetVariableProfileText("my_ColorSlider", "", "%");
}

if (IPS_VariableProfileExists("my_RGBSlider")==False) {
IPS_CreateVariableProfile('my_RGBSlider',1);
IPS_SetVariableProfileValues("my_RGBSlider", 0, 1000, 1);
IPS_SetVariableProfileText("my_RGBSlider", "", "%");
}

if (IPS_VariableProfileExists("my_RGBPresets")==False) {
IPS_CreateVariableProfile('my_RGBPresets',1);
IPS_SetVariableProfileAssociation("my_RGBPresets", 1, "White","");
IPS_SetVariableProfileAssociation("my_RGBPresets", 2, "Random","");
}


$name_RGB = "Color";
$name_T_B = "Time & Brightness";
$ParentID = IPS_GetObject($IPS_SELF);
$ParentID = $ParentID['ParentID'];
IPS_SetHidden($IPS_SELF,true);
# Scripte definieren
$id_update = @IPS_GetScriptIDByName("update", $ParentID);
IPS_SetHidden($id_update,true);

$id_setChromoflex = @IPS_GetScriptIDByName("set_RGBW868", $ParentID);
IPS_SetHidden($id_setChromoflex,true);

# DummyInstanzen anlegen
$id_RGB = getId($name_RGB);
IPS_SetPosition($id_RGB, 5);
$id_T_B = getId($name_T_B);
IPS_SetPosition($id_T_B, 10);

#Varianblen anlegen
$id = CreateVariableByName($ParentID, "Program_Selection", 1);
IPS_SetVariableCustomProfile($id, "my_RGBW868_Prog");
IPS_SetPosition($id, 15);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Red", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetPosition($id, 20);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Green", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetPosition($id, 25);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Blue", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetPosition($id, 30);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "Presets", 1);
IPS_SetVariableCustomProfile($id, "my_RGBPresets");
IPS_SetPosition($id, 15);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "RGB", 1);
IPS_SetVariableCustomProfile($id, "my_RGBSlider");
IPS_SetPosition($id, 10);
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_RGB, "RGB-Table", 3);
IPS_SetVariableCustomProfile($id, "~HTMLBox");
IPS_SetPosition($id, 5);

SetvalueString($id, '<TABLE width="100%"><TR><TD width="65px"></TD><TD><img src="user/color_bar.png" width="100%" height="35" align="middle" ></TD><TD width="65px"></TD></TR></TABLE>');


$id = CreateVariableByName($id_T_B, "Brightness", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetVariableCustomAction($id, $id_update);

$id = CreateVariableByName($id_T_B, "Dim-Time", 1);
IPS_SetVariableCustomProfile($id, "my_ColorSlider");
IPS_SetVariableCustomAction($id, $id_update);


echo " Installation finished";


function CreateVariableByName($id, $name, $type)
{
global $IPS_SELF;
   $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");
    }
   return $vid;
}

function getId($name) {
   global $IPS_SELF;
   $ParentID = IPS_GetObject($IPS_SELF);
    $ParentID = $ParentID['ParentID'];

    $ID = @IPS_GetObjectIDByName($name, $ParentID);
    if ($ID == 0) {
          $dummy=IPS_CreateInstance("{485D0419-BE97-4548-AA9C-C083EB82E61E}");  #Dummy Instance
        IPS_ApplyChanges($dummy);
        IPS_SetName($dummy,$name);
        IPS_SetParent($dummy,$ParentID);
   $ID = @IPS_GetObjectIDByName($name, $ParentID);
    }
return $ID;
}


?>


Das „update“ Script


<?

 // This Script is called by Sliders and Button in Webfront
// it updates the separate R-G-B Sliders and forward necessary parameters to
// set_Chromoflex Script

{
// Get categorie ID
$parentID = IPS_GetObject($IPS_SELF);
$parentID = $parentID['ParentID'];
// Get all variable IDs
$id_Color = @IPS_GetInstanceIDByName("Color", $parentID);
$id_Red = @IPS_GetVariableIDByName("Red", $id_Color);
$id_Green = @IPS_GetVariableIDByName("Green", $id_Color);
$id_Blue = @IPS_GetVariableIDByName("Blue", $id_Color);
$id_RGB = @IPS_GetVariableIDByName("RGB", $id_Color);
$id_Presets = @IPS_GetVariableIDByName("Presets", $id_Color);

$id_setRGBW868 = @IPS_GetScriptIDByName("set_RGBW868", $parentID);
$id_Programwahl = @IPS_GetVariableIDByName("Program_Selection", $parentID);



SetValueinteger($IPS_VARIABLE, $IPS_VALUE);
Switch ($IPS_VARIABLE) {
// suppport fixed Color Presets
case $id_Presets: //Presets
if ($IPS_VALUE == 2) {
    setvalueinteger($id_Red /*..Color\Rot]*/,rand(0,100));
    setvalueinteger($id_Green /*..Color\Grün]*/,rand(0,100));
    setvalueinteger($id_Blue /*../Color\Blau]*/,rand(0,100));
    setvalueinteger($id_RGB /*../Color\RGB*/,0);
}
if ($IPS_VALUE == 1) {
    setvalueinteger($id_Red /*..Color\Rot]*/,100);
    setvalueinteger($id_Green /*..Color\Grün]*/,100);
    setvalueinteger($id_Blue /*../Color\Blau]*/,100);
    setvalueinteger($id_RGB /*../Color\RGB*/,0);
}

setvalueinteger($IPS_VARIABLE,0);
break;

case $id_Red:
setvalueinteger($id_RGB /*../Color\RGB*/,0);
break;

case $id_Green:
setvalueinteger($id_RGB /*../Color\RGB*/,0);
break;

case $id_Blue:
setvalueinteger($id_RGB /*../Color\RGB*/,0);
break;

// Combined RGB Slider
case $id_RGB:  //Farbband Slider
$colorVal = $IPS_VALUE;
// RED > ORANGE > YELLOW
if ($colorVal >= 0 && $colorVal <= 170) {
    $redPwr = 255;
    $bluePwr = 0;
    $greenPwr = mape($colorVal, 0, 170, 0, 255);
}

// YELLOW > LIME?? > GREEN
if ($colorVal > 170 && $colorVal <= 341) {
    $greenPwr = 255;
    $bluePwr = 0;
    $redPwr = mape($colorVal, 341, 170, 0, 255);
}

// GREEN > TURQOUISE
if ($colorVal > 341 && $colorVal <= 511) {
    $greenPwr = 255;
    $redPwr = 0;
    $bluePwr = mape($colorVal, 341, 511, 0, 255);
}

// TURQOUISE > BLUE
if ($colorVal > 511 && $colorVal <= 682) {
    $bluePwr = 255;
    $redPwr = 0;
    $greenPwr = mape($colorVal, 682, 511, 0, 255);
}

// BLUE > PURPLE
if ($colorVal > 682 && $colorVal <= 852) {
    $bluePwr = 255;
    $greenPwr = 0;
    $redPwr = mape($colorVal, 682, 852, 0, 255);
}

// PURPLE > RED
if ($colorVal > 852 && $colorVal <= 1023) {
    $redPwr = 255;
    $greenPwr = 0;
    $bluePwr = mape($colorVal, 1023, 852, 0, 255);
}
// update seperate RGB Sliders
setvalueinteger($id_Red /*..Color\Rot]*/,intval($redPwr/2.5));
setvalueinteger($id_Green /*..Color\Grün]*/,intval($greenPwr/2.5));
setvalueinteger($id_Blue /*../Color\Blau]*/,intval($bluePwr/2.5));
IPS_RunScriptEx($id_setRGBW868 /*..\/Set_Chromoflex*/,Array("RGBW868Mode" => 0.0)); //Chromoflex setzen
break;
}

}
// call set_Chromoflex Script and call build in Scene
if ($IPS_VARIABLE ==$id_Programwahl /*../Programauswahl]*/){
IPS_RunScriptEx($id_setRGBW868 /*..\/Set_Chromoflex*/,Array("RGBW868Mode" => getvalue($id_Programwahl /*../Programauswahl]*/))); //Chromoflex setzen
}
else {
// call set_Chromoflex Script and call static RGB Color
setvalueinteger($id_Programwahl /*../Programauswahl]*/,0);
IPS_RunScriptEx($id_setRGBW868 /*..\/Set_Chromoflex*/,Array("RGBW868Mode" => 0.0)); //Chromoflex setzen
}


// support function for combiend RGB Slider
function mape($Value, $min, $max, $new_min, $new_max)
{
    $range = $max - $min;
    $new_range = $new_max - $new_min;
    $scaling = $new_range / $range;
    $new_Value = round(($Value - $min)*$scaling);
    if ($range < 0)
    {
        $new_Value = round(($Value - $max)*$scaling);
        $new_Value = $new_max + $new_Value;
    }
    return $new_Value;
}

?>

Das „set_RGBW868“ Script


<?
// This Script is called by "update" Script.
// it reads settings from Webfront and forward to Chromoflex Module
// Configuration:
// SET Chromoflex Module Adress, check Chromoflex Dokumentation for further Info
// If only one Module is connected default setting will be fine.


//IPS InstanceID of SerialPort where your Chromoflex is connected
$ID_RGBW868 = 56771 ;
// make shure your SerialPort is set to 9600,8,N,1
// Test correct Hardware Function and settings with Original Chromoflex Software
// Note its not posible to have IPS & Chromoflex Software talking to same ComPort at the same time


//______________________________________________________________________________________________

//      NO more User settings below this line
//______________________________________________________________________________________________

// get Kategory ID
$parentID = IPS_GetObject($IPS_SELF);
$parentID = $parentID['ParentID'];
// Get Variable IDs
$id_Color = @IPS_GetInstanceIDByName("Color", $parentID);
$id_Red = @IPS_GetVariableIDByName("Red", $id_Color);
$id_Green = @IPS_GetVariableIDByName("Green", $id_Color);
$id_Blue = @IPS_GetVariableIDByName("Blue", $id_Color);

$id_B_T = @IPS_GetInstanceIDByName("Time & Brightness", $parentID);
$id_Brightness = @IPS_GetVariableIDByName("Brightness", $id_B_T);
$id_Dim_Time = @IPS_GetVariableIDByName("Dim-Time", $id_B_T);

//_________________________________________________________________________________________________
// Check If static RGB Mode or Chromoflex interenal Scenes should be used

	IPS_LogMessage($IPS_SELF, "RGBW868Mode $RGBW868Mode");

IF ($RGBW868Mode > 0) {
 //RESET ???

print "RGBMode : " + $RGBW868Mode ;
$ProgNr=$RGBW868Mode - 1;  // $IPS_Value = 1 bis 8 für Chromoflex interen Modes,
IPS_LogMessage($IPS_SELF, "Switch ProgrammNr $ProgNr");
PJ_RunProgram($ID_RGBW868, $ProgNr);
}

// Code for static RGB Mode
else {
//Switch to manual Mode
IPS_LogMessage($IPS_SELF, "Switch to Manuell $RGBW868Mode");
PJ_RunProgram($ID_RGBW868, 0);
$dimtime=GetValue($id_Dim_Time /*.../ DimTime]*/)*2.55;
echo $dimtime;
//Set colors
$bright = getvalue($id_Brightness /*../Brightness*/);
$red=(getvalue($id_Red /*../Color\Red]*/)*2.5 / 100)*$bright;
$green=(getvalue($id_Green /*../Color\Green]*/)*2.5 / 100)*$bright;
$blue=(getvalue($id_Blue /*../Color\Blue]*/)*2.5 / 100)*$bright;
$white = 0;

 PJ_DimRGBW($ID_RGBW868,$red,$dimtime,$green,$dimtime,$blue,$dimtime,$white,$dimtime);

}

?>

@belmondo,

danke, dann brauch ich jetzt nur noch auf die neue Küche warten und dann kann’s losgehen :slight_smile:

Kann man die Variablen (z.B. RGB, Red Green usw.
auch mit 'nem Trackbar im Dashbord verbinden, um sowohl als auch im Dashboard und WF die Farben einzustellen?

Wird also das update script dann auch ausgeführt?

Also das Script läuft ja super.
Kann man eigentlich zb. den Normalen modus dimmen?
Weil miene Tochter wollte ein bischen wechselndes licht zum einschlafen, leider sind meine rgb-led´s so hell das die das ganze Zimmer ausleuchten. :rolleyes:
Wollte erst ein eigenes Script schreiben was so ist wie der normale modus, aber das ist ja ma garnicht so einfach.

cu.
uriel2006

Nein, leider nicht per Script.
Die Scenen sind fix in der Chromoflex Hardware abgelegt und werden nur aufgerufen.

Du kannst aber mit der original Chromoflex Software die Scenen selbst nach belieben editieren und dann in der Hardware abspeichern.

gruß
bb

Hallo Belmonde2001,

irgendwie läuft es bei mir nicht. Ich erhalte diese Fehlermeldung im Set_RGBW Script:

[i]Notice: Undefined variable: RGBW868Mode in C:\Programme\IP-Symcon_2_0\scripts\58809.ips.php on line 39

Notice: Undefined variable: RGBW868Mode in C:\Programme\IP-Symcon_2_0\scripts\58809.ips.php on line 41[/i]

und im update Script diese:

Notice: Undefined variable: IPS_VARIABLE in C:\Programme\IP-Symcon_2_0\scripts\36788.ips.php on line 25

Notice: Undefined variable: IPS_VALUE in C:\Programme\IP-Symcon_2_0\scripts\36788.ips.php on line 25

Warning: ‚‘ is not a valid integer value in C:\Programme\IP-Symcon_2_0\scripts\36788.ips.php on line 25

Es sind ein paar mehr zeilen, habe aber jetzt nicht alle kopiert das es immer die selben Fehler sind.

Hallo Horst,

Notice: Undefined variable: RGBW868Mode in C:\Programme\IP-Symcon_2_0\scripts\58809.ips.php on line 39

wird im Script nicht definiert.

Notice: Undefined variable: IPS_VARIABLE in C:\Programme\IP-Symcon_2_0\scripts\36788.ips.php on line 25

Notice: Undefined variable: IPS_VALUE in C:\Programme\IP-Symcon_2_0\scripts\36788.ips.php on line 25

Kommt daher, dass Du das Script von Hand ausführst, das geht nicht, da kein Wert in den Systemvariablen vorhanden ist, erst wenn getriggert wird.

Hallo Rainer,

danke für die Antwort.

Kommt daher, dass Du das Script von Hand ausführst

Hatte ich mir schon gedacht das ich das nicht darf :rolleyes:

Naja, ganz komme ich mit dem Script sowieso nicht klar :o

Die Programme gehen teilweise, Blinken schnell ist Blinken langsam auf und abdimmen geht gar nicht. Dachte eigentlich das ich das wenigstens richtig gemacht habe, aber das kann ich wohl über Assoziation selber richten.

Aber wenn ich z.B. über den Slider die Farbe ändere, dann wechselt auch das Programm :confused:

assoziation.jpg