Beschreibung der Berechnung des Rückkanals

Ich lese hier ständig, dass man aus dS keinen Rückkanal hat. Dem ist nicht der Fall. Leider muss man aber etwas dafür tun.

Das Kernstück ist der Angehängte Code am Schluss dieses Posts. Dieser Code scannt die Reaktionen einer Geräte-, Bereichs- oder Raumklemme auf die unterschiedlichsten Raumstimmungen. Es sei erwähnt, dass der Code etwa 4 Minuten durchlaufzeit hat. Der Loop über alle Raumszenen braucht halt sehr lange.

Bereichstaster mit lokaler Priorität sind noch nicht implementiert. Ich verwende keine solchen Klemmen und kann nur mit mühsamer Umprogrammierung zu Hause diese Geräte nachstellen.

Dieses Codes muss in ein php Skript in IP-Symcon kopiert werden. Der Kopfteil muss entsprechend geändert werden.
Wenn die zu analysierende Klemme eine Bereichs- oder eine Raumklemme ist, ist die Implementation relativ einfach. Eine Boolean Variable soll bei einer geschalteten Klemme anzeigen, ob die Lampe brennt. Man muss einzig zu dieser Boolean Variable ein Ereignis hängen, welches auf die Licht-Szenen Veränderungen im Raum reagiert. (siehe Anhang). Den Output dieses Programmes kopiert man in den einzeiligen php-Code (siehe Beilage).
Der Output sieht beispielsweise folgendermassen aus:

SetValue($_IPS[‚TARGET‘], max(0,min(1,GetValue($_IPS[‚TARGET‘])
+ in_array($_IPS[‚VALUE‘], array(5, 7, 8, 9, 17, 18, 20, 21, 23, 24, 26, 27, 29, 30, 33, 35, 37, 39, 65, 76))
-in_array($_IPS[‚VALUE‘], array(2, 3, 4, 67, 68, 69, 72))
-(GetValue(23752)==false)*in_array($_IPS[‚VALUE‘], array(0, 19, 22, 25, 28, 31, 32, 34, 36, 38, 40))
)) );

Ich gehe davon aus, dass man weiss, wie man dann die Veränderungen dieser Variable in dS ausführt.
<?
if ($_IPS[‚SENDER‘] == ‚WebFront‘)
{

    SetValue($_IPS['VARIABLE'], $_IPS['VALUE']); // DAMIT IST DIE INTEGER VARIABLE SCHALTBAR IM WEBFRONT

    switch ($_IPS['VALUE'])
        {

              case 0:
                    DS_CallScene(38218 /*[UG\Abstellkammer\UG - Abstellkammer]*/ ,1); 
              break;

              case 1:
                    DS_CallScene(38218 /*[UG\Abstellkammer\UG - Abstellkammer]*/ ,6);
              break;


        }


}

?>

Wenn die zu analysierende Lampe eine Geräte Klemme ist, ist die Welt etwas komplizierter. In diesem Fall muss im Scene Responder von Digitalstrom ein url Aufruf stattfinden. Dieser url Aufruf setzt einen Drittserver in Bewegung. Dieser Drittserver ändert dann die Variable in IP-Symcon.
Wenn die zu analysierende Lampe eine Geräte Klemme mit lokaler Priorität ist, braut es sogar noch ein zusätzliches Flag, welches angibt, ob die Lampe via dem lokalen Taster eingeschaltet wurde oder via eine Scene. Entsprechend muss im Scene Responder auch die zweite Variable bei lokaler Bedienung geändert werden. (Siehe anhang). Diese lokale Variable muss auf „false“ geändert werden, sobald die Lampe ausgeschaltet wurde. Entsprechend hängt man dieser Variable noch das Ereignis an, wenn die Lampe aus ist mit dem Code SetValue($_IPS[‚TARGET‘], 0);

Anhang: php-Code

<?
/This codes scans the reaction of a yellow device (light). The output is a php-code that should be added into the action of the calculated output variable;/

$Server = „192.168.1.xxx“; // IP Adress of the dss e.g. „192.168.1.33“;
$AppToken = „12345cbbd90401d575a8b61362a54cb9b3f4aeec3cd08d4f4b452873701069ed“; //64 character Applikation Token
$tcpPort = „8080“;
$dsid=„303505d7f800008000030l02“;//Device id from dS;
$localset=23752; //This number is only necesarely in case of local pushbutton with local priority. IP-Symcon reference ;
$debug = false;

/No changes beyond this line/
/***************************************************************************************************************/

$Call0 = „/json/apartment/getDevices?“;
$Call1 = „/json/device/getSceneMode?dsid=“.$dsid."&sceneID=";
$Call2 = „/json/device/getSceneValue?dsid=“.$dsid."&sceneID=";

$arrContextOptions=array(
„ssl“=>array(
„verify_peer“=>false,
„verify_peer_name“=>false,
),
);
$filename = ‚/var/www/html/sessionToken.txt‘;

$sessionToken = fdSLogin();

$ist=fdSGetJson($Call0, $sessionToken);
$ist=json_decode($ist,true);
$ist=$ist[‚result‘];
//echo json_decode(implode(",",$ist));

foreach ($ist as $value)
if ($value[„id“]==$dsid){
//var_dump($value);
$outputMode=$value[„outputMode“];
$buttonID=$value[„buttonID“]; /* Find out if the device is a device/area/room push button*/
$groups=$value[„groups“]; /* Group 1 means light */
$light=in_array(1,$groups);
if (!$light) {echo „The programm only analyses yellow push buttons.“;var_dump($groups);}
else if ($buttonID>13) {echo „The programm cannot analyse app buttons or appartmentbuttonss“;}
else if (!in_array($outputMode, array(16, 22, 35))){echo „The programm only analyse dimmed or shuttered push buttons.“.$outputMode;}

$localpriority=false;
/* In case of a device push button we have to find out, if local priority is set.*/
if ($buttonID==0){
        $temp2=fdSGetJson($Call1.'51', $sessionToken);     
        $a=json_decode($temp2,true);
        $localpriority=$a['result']['specialMode'];
}


/* In case the device output is deaming, we define device on:=(output&gt;0).
If the device is not in deam-mode you can define in the configurator when the device is on.
Unfortunately, we didn't find the value. Standard proposition is &gt;=128. */
if ($outMode=16){$turnOnBorder=128;}
else  {$turnOnBorder=1;}


$OnList="";
$OffList="";   
$OffList2="";  
$nutralList="";
//foreach (array(51) as $x){
foreach (array(0, 1 ,2, 3, 4, 5, 6, 7, 8, 9, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
                30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 65, 67, 68, 69, 70, 71, 72, 73, 74 ,
                76, 80, 81, 82 ,83 ,84 ,85 ,86, 87, 88, 89, 90, 91) as $x){    
                                       
    $temp2=fdSGetJson($Call1.$x, $sessionToken);       
    $a=json_decode($temp2,true);
    $dontCare=$a['result']['dontCare']; /* if dontCare=true this scene will not change the device output.*/
    $specialMode=$a['result']['specialMode']; /* Scenes with specialMode can manipulate the output but cannot switch on/off*/
    $local=$a['result']['localPrio'];
    if ($debug) echo "SceneID=".$x."gives dontCare=".$dontCare."_or_".$temp2."

\r";
if ($dontCare == false /and $specialMode == false and
(($buttonID>=1 and $buttonID<=14) or
($buttonID==0 and $localpriority==false) or
($buttonID==0 and $localpriority==true and $local==true) or
($buttonID==0 and $localpriority==true and $local==false and GetValue($localset)==false) )
/ ){
$temp=fdSGetJson($Call2.$x, $sessionToken);
$b=json_decode($temp,true);

        if  ($b['result']['value']&gt;= $turnOnBorder){
            if ($OnList == ""){$OnList="".$x;}
            else {$OnList=$OnList.", ".$x; }
            if ($debug) echo "SceneID=".$x."on.

\r";
}
else if (($buttonID>=1 and $buttonID<=14) or
($buttonID==0 and $localpriority==false/* and $local==false*/) or
($buttonID==0 and $localpriority==true and $local==true)){ if ($OffList == „“){$OffList="".$x;}
else {$OffList=$OffList.", ".$x;}
if ($debug) echo „SceneID=“.$x."off.

\r";
}
else { if ($OffList2 == „“){$OffList2="".$x;}
else {$OffList2=$OffList2.", ".$x;}
if ($debug) echo „SceneID=“.$x."off2.

\r";
}

        if ($debug) echo "SceneID=".$x.fdSGetJson($Call2.$x, $sessionToken)."

\r";
}
else { if ($nutralList == „“){$nutralList="".$x;}
else {$nutralList=$nutralList.", ".$x;}
if ($debug) echo „SceneID=“.$x."dontCare.

\r";
}
}
if ($debug) echo „On=“.$OnList."_Off=".$OffList."_Nutral=".$nutralList.".
\r";

if (($buttonID&gt;=1 and $buttonID&lt;=14) or
                ($buttonID==0 and $localpriority==false)){
echo 'SetValue($_IPS[\'TARGET\'], max(0,min(1,GetValue($_IPS[\'TARGET\'])
+ in_array($_IPS[\'VALUE\'], array('.$OnList.'))
-in_array($_IPS[\'VALUE\'], array('.$OffList.')) )) );';
}
else {
echo 'SetValue($_IPS[\'TARGET\'], max(0,min(1,GetValue($_IPS[\'TARGET\'])
+ in_array($_IPS[\'VALUE\'], array('.$OnList.'))
-in_array($_IPS[\'VALUE\'], array('.$OffList.'))
-(GetValue('.$localset.')==false)*in_array($_IPS[\'VALUE\'], array('.$OffList2.'))
)) );';
}

}

/************************************************* define the funktions **********************************/

/* digitalSTROM Login Prozedure Function */
function fdSLogin(){
global $Server;
global $tcpPort;
global $AppToken;
global $arrContextOptions;

if($sessionToken = file_get_contents("https://" . $Server . ":" . $tcpPort . "/json/system/loginApplication?loginToken=" . $AppToken, false, stream_context_create($arrContextOptions))){
    $sessionToken = json_decode($sessionToken);
    return $sessionToken-&gt;result-&gt;token;
}
else{
    return "&lt;font color='red'&gt;&lt;b&gt;ERROR:&lt;/b&gt; unable to get loginToken from digitalSTROM Server&lt;/font&gt;&lt;br&gt;";
}

}

/* digitalSTROM get JSON content Function */
function fdSGetJson($call, $sessionToken){
global $Server;
global $tcpPort;
global $arrContextOptions;
$sHelp;
global $debug;

$sHelp = "https://" . $Server . ":" . $tcpPort . $call . "&token=" . $sessionToken;

if($jsonOutput = file_get_contents($sHelp , false, stream_context_create($arrContextOptions))){
    return $jsonOutput; // plain output
}
else{
    return "&lt;font color='red'&gt;&lt;b&gt;ERROR:&lt;/b&gt; unable to get JSON Content from digitalSTROM Server&lt;/font&gt;&lt;br&gt;";
}

}

?>

Raum.JPG

Schön wäre, wenn ein Modulbauer mir hilft. Man könnte eigentlich diesen Output Befehl gleich in das entsprechende php-Skript hineinschreiben.
Noch besser wäre, wenn man einen Loop über alle Räume im Appartment macht und dann über alle Geräte in einem Raum.

Hat es schon jemand ausprobiert? Versteht man die Erklärungen nicht?

Hallo. Sobald ich meine ersten Gehversuche mit Skripten hinter mich gebracht habe und ich anfange zu verstehen, wie das funktioniert, werde ich diesen Beitrag sehr gerne ausprobieren!

Hallo. Also ich wollte jetzt mal Deinen Beitrag umsetzen. Aber das ging nicht. Ich verstehe die Anweisungen nicht zu 100%, vermute ich. Als erstes habe ich den php-Code aus dem Anhang mit der IP Adresse meines dss-Servers versehen. Dann holte ich mir den Token aus dem dss-Konfigurator. Zu guter letzt kopierte ich noch die Geräte dsID für - zum Beispiel - die Badezimmerlampe. Dieses Skript speicherte ich unter der Boolean-Variable „Lampe Bad Oben“.

Jetzt fügte ich ein ausgelöstes Ereignis hinzu. Und weiter komme ich nicht! Was soll ich mit dem Code

<?
if ($_IPS['SENDER'] == 'WebFront')
{

SetValue($_IPS['VARIABLE'], $_IPS['VALUE']); // DAMIT IST DIE INTEGER VARIABLE SCHALTBAR IM WEBFRONT

switch ($_IPS['VALUE'])
{

case 0:
DS_CallScene(38218 /*[UG\Abstellkammer\UG - Abstellkammer]*/ ,1); 
break;

case 1:
DS_CallScene(38218 /*[UG\Abstellkammer\UG - Abstellkammer]*/ ,6);
break;


}


}
?>

machen?

Hier noch die Fehlermeldung, wenn ich das Skript „teste“

Parse error: syntax error, unexpected ‚ist‘ (T_STRING), expecting ‚,‘ or ‚;‘ in /mnt/data/symcon/scripts/33749.ips.php on line 108

@msiegw