diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..739fe19 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +errors.txt +cookies.txt +logininfo.php +!logininfo.php.example +globals.php +!globals.php.example diff --git a/README.md b/README.md new file mode 100644 index 0000000..0f93d60 --- /dev/null +++ b/README.md @@ -0,0 +1,12 @@ +#Stat stat +A set of tools to record and analyze data from a smart thermostat. + +##Thermostat support +Currently, only Honeywell Thermostats controllable through their Total Connect system are supported. + +##Installation +* Add your database info to globals.php.example. Rename to globals.php +* Add your Honeywell Total Connect info to logininfo.php.example. Rename to logininfo.php +* Run dbsetup.php +* Add a cron job to run scrape.php every 5 minutes. +* Wait for useful data to come in \ No newline at end of file diff --git a/current.php b/current.php new file mode 100644 index 0000000..fd860b8 --- /dev/null +++ b/current.php @@ -0,0 +1,53 @@ +query($sql); + if (!$result) { + printf("Errormessage: %s\n", $conn->error); + } + $rows = array(); + while($r = mysqli_fetch_assoc($result)) { + print array_values($r)[0]; + } + + + + $conn->close(); + + } +} + +?> \ No newline at end of file diff --git a/db-get.php b/db-get.php new file mode 100644 index 0000000..63b727c --- /dev/null +++ b/db-get.php @@ -0,0 +1,55 @@ +query($sql); + if (!$result) { + printf("Errormessage: %s\n", $conn->error); + } + $rows = array(); + while($r = mysqli_fetch_assoc($result)) { + $row = array_map('floatval',array_values($r)); + $row[0] = $row[0]*1000; + $rows[] = $row; + } + print json_encode($rows); + + + $conn->close(); + + } +} + +?> \ No newline at end of file diff --git a/dbsetup.php b/dbsetup.php new file mode 100644 index 0000000..f92b7b3 --- /dev/null +++ b/dbsetup.php @@ -0,0 +1,43 @@ +query($sql); +if (!$result) { + printf("Errormessage: %s\n", $conn->error); +} + +?> \ No newline at end of file diff --git a/delay.html b/delay.html new file mode 100644 index 0000000..e52c098 --- /dev/null +++ b/delay.html @@ -0,0 +1,123 @@ + + + +
+");
+// print_r($rows);
+$startTime = -1;
+$startTemp = NULL;
+$startSetPoint = NULL;
+$targetSetPoint = NULL;
+
+$heat_up = NULL;
+$heat_down = NULL;
+$cool_up = NULL;
+$cool_down = NULL;
+$type = NULL;
+
+for($i = 1; $i < count($rows); $i++){
+ $now = $rows[$i];
+ $last= $rows[$i-1];
+// echo $startTime;
+// print_r($now);
+ if($startTime == -1){
+// echo "no start
";
+ if($now['heatSetPoint'] <> $last['heatSetPoint']){
+ //Down!
+// echo "down
";
+ $startTime = $now['date'];
+ $startTemp = $now['dispTemperature'];
+ $startSetPoint = $last['heatSetPoint'];
+ $targetSetPoint = $now['heatSetPoint'];
+ if($now['heatSetPoint'] > $last['heatSetPoint']){
+ $type = "up";
+ } else {
+ $type = "down";
+ }
+ }
+ } else{
+ //looking for end
+// echo "yes start
";
+ if($now['dispTemperature'] == $targetSetPoint || $now['heatSetPoint'] <> $targetSetPoint){
+ $changeTime = ($now['date']-$startTime)/60;
+ $changeTemp = abs($startTemp - $now['dispTemperature']);
+ $outside = $now['weatherTemperature'];
+ $minperdeg = $changeTime/$changeTemp;
+
+ if($type == "up"){
+ $heat_up[] = [$minperdeg,intval($outside)];
+ } else{
+ $heat_down[] = [$minperdeg,intval($outside)];
+ }
+
+ $startTime = -1;
+ }
+ }
+
+}
+
+$return = [$heat_up, $heat_down];
+
+print json_encode($return);
+
+
+$conn->close();
+
+?>
\ No newline at end of file
diff --git a/graph.html b/graph.html
new file mode 100644
index 0000000..b825326
--- /dev/null
+++ b/graph.html
@@ -0,0 +1,104 @@
+
+
+
+ Stat tracker
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.html b/index.html
new file mode 100644
index 0000000..52a4ae8
--- /dev/null
+++ b/index.html
@@ -0,0 +1,50 @@
+
+
+
+
+
+
+
+ Stat stat
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/index.php b/scrape.php
similarity index 80%
rename from index.php
rename to scrape.php
index 9dfa044..ed19261 100644
--- a/index.php
+++ b/scrape.php
@@ -2,7 +2,7 @@
$ch = curl_init();
-require_once('settings.php');
+require_once('settings/logininfo.php');
function get_session(){
$url = "https://mytotalconnectcomfort.com/portal";
@@ -52,6 +52,9 @@ function get_session(){
// print "Sent headers:
";
// var_dump($sentHeaders);
// print "
";
+
+// $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+// echo $code;
}
@@ -117,7 +120,7 @@ function login($usr, $pwd){
}
function getStatus($device){
- print "
Get Status
";
+ // print "
Get Status
";
$time = round(microtime(true) * 1000);
$url = "https://mytotalconnectcomfort.com/portal/Device/Control/".$device;
@@ -190,9 +193,42 @@ function cleanCookies(){
file_put_contents($cookie_file_path,$file_contents);
}
-get_session();
-//login($username, $password);
-//$data = getStatus($device_number);
+function add_data($data){
+ include('globals.php');
+ $conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
+ // Check connection
+ if (!$conn) {
+ die("Connection failed: " . mysqli_connect_error());
+ }
+
+ $good_columns = array("coolLowerSetpLimit","coolNextPeriod","coolSetpoint","coolUpperSetptLimit","deviceID","dispTemperature","displayedUnits","heatLowerSetptLimit","heatNextPeriod","heatSetpoint","heatUpperSetptLimit","isInVacationHoldMode","schedCoolSp","schedHeatSp","scheduleCapable","statusCool","statusHeat","systemSwitchPosition","weatherHumidity","weatherPhrase","weatherTemperature");
+
+ $clean_data = array();
+ foreach($good_columns as $col){
+ $clean_data[$col] = $data[$col];
+ }
+ //$clean_data['weatherPhrase'] = $conn->real_escape_string($clean_data['weatherPhrase']);
+ $columns = implode(", ",array_keys($clean_data));
+ $values = implode(", ", array_values($clean_data));
+
+ $sql = "INSERT INTO `stat`(".$columns.") VALUES (".$values.")";
+ $result = $conn->query($sql);
+ echo $sql;
+ echo "\n";
+ echo $result;
+ if (!$result) {
+ printf("Errormessage: %s\n", $conn->error);
+}
+
+ $conn->close();
+
+}
+//get_session();
+login($username, $password);
+$data = getStatus($device_number);
+
+add_data($data);
+
curl_close($ch);
diff --git a/settings/globals.php.example b/settings/globals.php.example
new file mode 100644
index 0000000..d48e4df
--- /dev/null
+++ b/settings/globals.php.example
@@ -0,0 +1,6 @@
+
\ No newline at end of file
diff --git a/settings/logininfo.php.example b/settings/logininfo.php.example
new file mode 100644
index 0000000..ad772d3
--- /dev/null
+++ b/settings/logininfo.php.example
@@ -0,0 +1,6 @@
+
\ No newline at end of file