Es gibt diese 4-fach IP-Steckdosenleiste unter vielfachen Namen bei verschiedenen Händlern. Hier ein simples Skript, das ich benutze, um bei mir eine solche Steckdosenleiste anzusteuern:
<?
// hier die IP eintragen
$deviceAddress = '';
$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);
$switchStatusId = Array(0, 0, 0, 0);
for($i = 0; $i < 4; $i++)
{
$switchStateId[$i] = @IPS_GetObjectIDByIdent('socket' . $i, $instanceId);
if(!$switchStateId[$i])
{
$switchStateId[$i] = IPS_CreateVariable(0);
IPS_SetIdent($switchStateId[$i], 'socket' . $i);
IPS_SetParent($switchStateId[$i], $instanceId);
IPS_SetName($switchStateId[$i], 'Socket ' . ($i + 1));
IPS_SetVariableCustomProfile($switchStateId[$i], '~Switch');
IPS_SetVariableCustomAction($switchStateId[$i], $scriptId);
$eventId = IPS_CreateEvent(0);
IPS_SetParent($eventId, $scriptId);
IPS_SetEventTrigger($eventId, 1, $switchStateId[$i]);
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');
}
$postVar = '';
if($_IPS['SENDER'] == 'WebFront')
{
SetValue($_IPS['VARIABLE'], $_IPS['VALUE']);
return;
}
else if($_IPS['SENDER'] == 'Variable')
{
$variableId = $_IPS['VARIABLE'];
$value = $_IPS['VALUE'];
for($i = 0; $i < 4; $i++)
{
if($variableId == $switchStateId[$i])
{
if($value)
$postVar .= '&cte'.($i + 1).'=1';
else
$postVar .= '&cte'.($i + 1).'=0';
}
}
}
else
{
for($i = 0; $i < 4; $i++)
{
$postVar .= '&cte'.($i + 1).'=';
if(GetValue($switchStateId[$i]))
$postVar .= '1';
else
$postVar .= '0';
}
}
IPS_SetScriptTimer($scriptId, 15);
$addr = 'http://' . $deviceAddress . '/login.html';
$ch = curl_init($addr);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'pw=');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
$addr = 'http://' . $deviceAddress . '/';
$ch = curl_init($addr);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postVar);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if($result)
{
SetValue($deviceStatusId, true);
}
else
{
SetValue($deviceStatusId, false);
}
?>
Die Steckdosenleiste dient bei mir als reiner Aktor, ohne Rückmeldung der Zustände. Die Geräte-App verwende ich nicht, ich steuere nur über IPS.
Die Verfügbarkeit des Geräts wird über die Variable DeviceStatus angezeigt.
Das Skript muss unter eine Dummy-Instanz gelegt und einmal manuell ausgeführt werden.