Ich habe ein Skript geschrieben, um die beiden Schaltkanäle der Netzwerk-Steckdosenleiste von ELV auszulesen bzw. zu setzen.
Das Gerät gibt es hier als Bausatz.
Die Implementierung ist denkbar einfach:
-Dummy-Instanz anlegen
-darunter ein Skript anlegen
-den Quellcode in das Skript kopieren
-die IP-Adresse der Steckdosenleiste eintragen
-das Skript ausführen
Wenn alles klappt, sollten die drei Statusvariablen für den Gerätestatus und die Schaltstati automatisch erstellt und konfiguriert werden. Mit den Schaltzustand-Variablen kann man die Steckdosen dann auch ein- bzw. ausschalten.
<?
// fill in the IP address of the device here
$deviceAddress = '192.168.178.200';
$scriptId = $_IPS['SELF'];
$instanceId = IPS_GetParent($scriptId);
$obj = IPS_GetObject($instanceId);
if($obj['ObjectType'] != 1)
{
echo 'Error: The script must be placed under a dummy instance.';
return;
}
IPS_SetHidden($scriptId, TRUE);
$switchStateId1 = @IPS_GetObjectIDByIdent('grey_sockets', $instanceId);
if(!$switchStateId1)
{
$switchStateId1 = IPS_CreateVariable(0);
IPS_SetIdent($switchStateId1, 'grey_sockets');
IPS_SetParent($switchStateId1, $instanceId);
IPS_SetName($switchStateId1, 'Grey Sockets');
IPS_SetVariableCustomProfile($switchStateId1, '~Switch');
IPS_SetVariableCustomAction($switchStateId1, $scriptId);
$eventId = IPS_CreateEvent(0);
IPS_SetParent($eventId, $scriptId);
IPS_SetEventTrigger($eventId, 1, $switchStateId1);
IPS_SetEventScript($eventId, $scriptId);
IPS_SetEventActive($eventId, true);
}
$switchStateId2 = @IPS_GetObjectIDByIdent('black_sockets', $instanceId);
if(!$switchStateId2)
{
$switchStateId2 = IPS_CreateVariable(0);
IPS_SetIdent($switchStateId2, 'black_sockets');
IPS_SetParent($switchStateId2, $instanceId);
IPS_SetName($switchStateId2, 'Black Sockets');
IPS_SetVariableCustomProfile($switchStateId2, '~Switch');
IPS_SetVariableCustomAction($switchStateId2, $scriptId);
$eventId = IPS_CreateEvent(0);
IPS_SetParent($eventId, $scriptId);
IPS_SetEventTrigger($eventId, 1, $switchStateId2);
IPS_SetEventScript($eventId, $scriptId);
IPS_SetEventActive($eventId, true);
}
$deviceStatusId = @IPS_GetObjectIDByIdent('device_status', $instanceId);
if(!$deviceStatusId)
{
$deviceStatusId = IPS_CreateVariable(0);
IPS_SetIdent($deviceStatusId, 'device_status');
IPS_SetParent($deviceStatusId, $instanceId);
IPS_SetName($deviceStatusId, 'Device Status');
}
$getStr = '';
if(($_IPS['SENDER'] == 'Variable') || ($_IPS['SENDER'] == 'WebFront'))
{
$variableId = $_IPS['VARIABLE'];
$value = $_IPS['VALUE'];
if($variableId == $switchStateId1)
{
if($value)
$getStr = '?on_gr=on_gr';
else
$getStr = '?off_gr=off_gr';
}
else if($variableId == $switchStateId2)
{
if($value)
$getStr = '?on_sw=on_sw';
else
$getStr = '?off_sw=off_sw';
}
}
$addr = 'http://' . $deviceAddress . '/ipsl32.cgi' . $getStr;
$hdl = @fopen($addr, 'r');
if($hdl)
{
$numSet = 0;
$numNames = 0;
while(!feof($hdl))
{
$thisLine = fgets($hdl);
if(strpos($thisLine, '<button name="on_gr" type="submit" value="on_gr"') !== FALSE)
{
if(strpos($thisLine, 'style="background-color:') !== FALSE)
$switchState = TRUE;
else
$switchState = FALSE;
SetValue($switchStateId1, $switchState);
$numSet++;
}
if(strpos($thisLine, '<button name="on_sw" type="submit" value="on_sw"') !== FALSE)
{
if(strpos($thisLine, 'style="background-color:') !== FALSE)
$switchState = TRUE;
else
$switchState = FALSE;
SetValue($switchStateId2, $switchState);
$numSet++;
}
if(strpos($thisLine, '<textarea name="user_eingabe" cols="15" rows="2" readonly>') !== FALSE)
{
$thisLine = substr($thisLine, strpos($thisLine, '>') + 1);
$thisLine = substr($thisLine, 0, strpos($thisLine, '<'));
if($numNames == 0)
IPS_SetName($switchStateId1, $thisLine);
else
IPS_SetName($switchStateId2, $thisLine);
$numNames++;
}
}
fclose($hdl);
if($numSet == 2)
{
SetValue($deviceStatusId, true);
IPS_SetScriptTimer($scriptId, 5);
}
else
{
echo 'Error: Unable to read status.';
SetValue($deviceStatusId, false);
}
}
else
{
echo 'Error: Device access error.';
SetValue($deviceStatusId, false);
}
?>