-
Notifications
You must be signed in to change notification settings - Fork 4
/
thermostat.php
executable file
·154 lines (128 loc) · 3.83 KB
/
thermostat.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/usr/bin/php
<?php
use GuzzleHttp\Client;
require 'vendor/autoload.php';
class HoneywellWifiAPI
{
const USER_AGENT = 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36';
const USERNAME = '***';
const PASSWORD = '***';
const DEVICE_ID = 000;
const PROTOCOL = 'https';
const URL = 'mytotalconnectcomfort.com';
public function __construct()
{
date_default_timezone_set('America/Chicago');
}
public function parseClientCookies($cookies, $container)
{
$ignore = array('path', 'Path', 'HttpOnly');
$return = [];
foreach( $cookies as $cookie )
{
$data = explode(';', $cookie);
foreach ($data as $inside)
{
$split = explode('=', trim($inside));
if (!in_array($split[0], $ignore))
{
if ($split[0] == 'expires')
{
$return['expires'] = explode(',', $split[1])[0];
}
else
{
$return[$split[0]] = $split[1];
}
}
}
}
return $return;
}
public function fillCookieJar($cookieJar)
{
$string = '';
foreach ($cookieJar as $cookieKey => $cookieVal)
{
$string .= $cookieKey . '=' . $cookieVal . ';';
}
return $string;
}
public function getLogin()
{
$client = new Client();
$query = [
'timeOffset' => '360',
'UserName' => self::USERNAME,
'Password' => self::PASSWORD,
'RememberMe' => 'false',
];
$headers2 = [
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept' => 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Encoding' => 'sdch',
'Host' => self::URL,
'DNT' => '1',
'Origin' => self::PROTOCOL . '://' . self::URL . '/portal/',
'User-Agent' => self::USER_AGENT,
];
$response2 = $client->post(self::PROTOCOL . '://' . self::URL . '/portal/', [
'headers' => $headers2,
'body' => $query,
'cookies' => true,
]);
$headers3 = [
'Accept' => '*/*',
'DNT' => '1',
'Accept-Encoding' => 'plain',
'Cache-Control' => 'max-age=0',
'Accept-Language' => 'en-US,en,q=0.8',
'Connection' => 'keep-alive',
'Host' => self::URL,
'Referer' => self::PROTOCOL . '://' . self::URL . '/portal/',
'X-Requested-With' => 'XMLHttpRequest',
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36',
];
$response3 = $client->get(self::PROTOCOL . '://' . self::URL . '/portal/Device/CheckDataSession/' . self::DEVICE_ID . '?_=' . time(), [
'headers' => $headers3,
'cookies' => true,
]);
$data = $response3->json();
$headers4 = [
'Accept' => 'application/json, text/javascript, */*; q=0.01',
'DNT' => '1',
'Accept-Encoding' => 'gzip,deflate',
'Content-Type' => 'application/json; charset=UTF-8',
'Cache-Control' => 'max-age=0',
'Accept-Language' => 'en-US,en;q=0.8',
'Connection' => 'keep-alive',
'Origin' => self::PROTOCOL . '//' . self::URL,
'Host' => self::URL,
'Referer' => self::PROTOCOL . '://' . self::URL . '/portal/Device/Control/' . self::DEVICE_ID,
'X-Requested-With' => 'XMLHttpRequest',
'User-Agent' => 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36',
];
$body = [
'CoolNextPeriod' => null,
'CoolSetpoint' => null,
'DeviceID' => self::DEVICE_ID,
'FanMode' => null,
'HeatNextPeriod' => null,
'HeatSetpoint' => 72,
'StatusCool' => null, // 1 for hold, 0 for regular
'StatusHeat' => null, // 1 for hold, 0 for regular
'SystemSwitch' => null, // 2 is off, 1 is heat, 3 for AC
];
$response4 = $client->post(self::PROTOCOL . '://' . self::URL . '/portal/Device/SubmitControlScreenChanges', [
'headers' => $headers4,
'cookies' => true,
'json' => $body,
'debug' => true,
]);
echo $response3->getBody();
die();
}
}
$honeywell = new HoneywellWifiApi();
$honeywell->getLogin();
?>