ThatCasualMatt / Nest-Extended

Obtaining data from and interacting with Nest Thermostats.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Mysql Timezone

jpoynton opened this issue · comments

The nest-get-json script converts the logged timestamp into a Unix timestamp. MySQL Unix Timestamp conversion factors in timezone difference between the server timezone and UTC. This causes a display time offset problem when the timezone of the Nest device and the timezone of the MySQL server are not the same.

Fix is to tell MySQL the timezone of the Nest device when the data is pulled.

Once the databased connection is up applied the following.

$sql = "set time_zone='Europe/London';";
$query = $con->query($sql) or trigger_error('SQL: ' . $sql . ' Error: ' . $con->error, E_USER_ERROR);

I think we can ignore the server's time_zone if we have it store the data in UTC. This requires changing the type of log_datetime from DATETIME to TIMESTAMP. TIMESTAMP is internally stored in UTC, as described in mysql docs. I was able to change the structure of my existing nest table using phpMyAdmin and I didn't lose anything but you may want to do some research for how to properly convert existing data.

Merged change from @costerwi