#!/usr/bin/php
login();
// --- Schalter -----------------------------------------------------------------------------
$Variable01 = $argv[1];
$Variable02 = $argv[2];
#echo ($Variable01);
#echo ($Variable02);
$sh->SwitchActuator($Variable01, $Variable02); //('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee', 0)
#$sh->switchDimmerState($Variable01, $Variable02); //('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee', 100)
#$sh->RollerShutterActuatorState($Variable01, $Variable02); //('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee', 90)
#$sh->setPointTemperature($Variable01, $Variable02); //('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee', 20.5)
#$sh->setLogicalDeviceState($Variable01, $Variable02); //('aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee', 1)
// --- Class Smarthome --------------------------------------------------------------------------
class Smarthome
{
private $host;
private $username;
private $password;
private $sessionId = false;
private $configurationVersion = false;
function __construct($host, $username, $password)
{
$this->host = $host;
$this->username = $username;
$this->password = $password;
}
function login()
{
$data = '';
$response = $this->doRequest($data);
$a = $response->attributes();
$this->sessionId = $a->SessionId;
$this->configurationVersion = $a->CurrentConfigurationVersion;
}
function doRequest($data)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$this->host.'/cmd');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSLVERSION, 3); //Neu eingefügt
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$xml = new SimpleXMLElement($output);
return $xml;
}
function getInformation()
{
$data = '';
$response = $this->doRequest($data);
return $response->ShcInformation;
}
function getAllLogicalDeviceStates()
{
$data = '';
$response = $this->doRequest($data);
return $response->States;
}
function getConfiguration()
{
$data = '';
$response = $this->doRequest($data);
return $response;
}
function switchActuator($logicalDeviceId, $on)
{
$data = new SimpleXMLElement('
');
$data = $data->asXML();
$response = $this->doRequest($data);
}
function switchDimmerState($logicalDeviceId, $Dimmer)
{
$data = new SimpleXMLElement('
');
$data = $data->asXML();
$response = $this->doRequest($data);
}
function RollerShutterActuatorState($logicalDeviceId, $ShutterLevel)
{
$data = new SimpleXMLElement('
');
$data->ActuatorStates->LogicalDeviceState->addChild('xmlns:ShutterLevel', $ShutterLevel);
$data = $data->asXML();
$response = $this->doRequest($data);
}
function setPointTemperature($logicalDeviceId, $pointTemperature)
{
$data = '
'.$logicalDeviceId.'
'.$pointTemperature.'
';
$response = $this->doRequest($data);
}
function setLogicalDeviceState($logicalDeviceId, $on)
{
$data = new SimpleXMLElement('
');
$data = $data->asXML();
$response = $this->doRequest($data);
}
}
// --- Allgemeine Funktionen --------------------------------------------------------------------------
function sortArray($data, $field)
{
if (!is_array($field))
$field = array($field);
uasort($data,
function($a, $b) use($field)
{
$retval = 0;
foreach($field as $fieldname)
{
if($retval == 0)
$retval = strnatcmp($a[$fieldname],$b[$fieldname]);
}
return $retval;
});
return $data;
}
function xml_attribute($object, $attribute)
{
if(isset($object[$attribute]))
return (string) $object[$attribute];
}
#?>