-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathexample.php
91 lines (71 loc) · 2.82 KB
/
example.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<?php
/**
* Created with IntelliJ IDEA.
* Project: SmartHome PHP
* User: Bubelbub <[email protected]>
* Date: 07.12.13
* Time: 15:44
*/
use Bubelbub\SmartHomePHP\SmartHome;
use Bubelbub\SmartHomePHP\Entity\LogicalDevice;
require_once 'vendor/autoload.php';
$newLine = php_sapi_name() == 'cli' ? PHP_EOL : '<br />';
$config = new SimpleXMLElement('<SmartHomeConfiguration />');
$configFile = __FILE__ . '.config';
if(file_exists($configFile))
{
try{$config = new SimpleXMLElement($configFile, 0, true);}catch(Exception $ex){}
}
$sh = new SmartHome('Hostname or IP address', 'Username', 'Password');
if(!file_exists($configFile))
{
$config->addChild('SessionId', $sh->getSessionId());
$config->addChild('ClientId', $sh->getClientId());
$config->addChild('Version', $sh->getVersion());
$config->addChild('ConfigurationVersion', $sh->getConfigVersion());
$config->saveXML($configFile);
}
$sh->setSessionId((string) $config->SessionId);
$sh->setClientId((string) $config->ClientId);
$sh->setVersion((string) $config->Version);
$sh->setConfigVersion((string) $config->ConfigurationVersion);
// get your current session id
echo 'Your session id is ' . $sh->getSessionId() . $newLine;
// get your current session id
echo 'Your current client id is ' . $sh->getClientId() . $newLine;
// get your current version
echo 'Your current version is ' . $sh->getVersion() . $newLine;
// get your current configuration version
echo 'Your current configuration version is ' . $sh->getConfigVersion() . $newLine;
// Load all entities (full configuration: LogicalDevices, Locations etc.)
echo 'Loading full configuration...' . $newLine;
$sh->getEntities();
// Load only locations
// $sh->getEntities('Locations');
// Get all logical devices states
echo 'Loading logical device states' . $newLine;
$sh->getAllLogicalDeviceStates();
// Now get a list of all LogicalDevices and print their names and room
foreach ($sh->getLogicalDevices() as $ld) {
printf("Device '%s' is a '%s' in room '%s'.", $ld->getName(), $ld->getType(), $ld->getLocation()->getName());
if($ld->getType() == LogicalDevice::DEVICE_TYPE_SWITCH_ACTUATOR) {
printf(" Switch state is '%s'.", $ld->getState());
}
if($ld->getType() == LogicalDevice::DEVICE_TYPE_WINDOW_DOOR_SENSOR) {
printf(" %s is %s.", $ld->getInstallationType(), $ld->getState());
}
echo $newLine;
}
// Get updates
//print_r($sh->getUpdates());
// Get all messages
//print_r($sh->getMessageList());
// Set room temperature of heater to 18°C
/*
$setActuatorStatesRequest = new SetActuatorStatesRequest($sh);
$setActuatorStatesRequest->addRoomTemperatureActuatorState('id of heater (LID)', 12, 'auto');
$setActuatorStatesRequest->send();
*/
// Switch on your adapter for computer
//$sh->setSwitchActuatorState('id of computer adapter (LID)', 'on'); // 'on' could be true, too
// Now you could wake your computer up! (@since 30.03.2014)