Giter VIP home page Giter VIP logo

nest-datagraph's Introduction

Nest DataGraph

This project try to fill the biggest Nest Thermostat gap, data history using Python and LAMP stack.

It allow you to browse your Nest thermostat history data with some pretty charts, analyze your consumption and keep a eye on your environment.

Feel free to create a pull request, open an issue or fork it !

Features

  • Polls Nest API to fetch thermostat data
  • Consumptions data are stored in a local database
  • Generates (Google) Charts with your consumptions
  • Select specific date ranges
  • Hover over charts to get the exact timestamp and temperature
  • Verify your Nest Protect devices state
  • And more !

Overview

Installation

Prerequisite

For Docker version:

Docker Setup

If you want to use Nest Datagraph with Docker, please follow these steps:

  • Fill the frontend/conf/settings.ini file with your configuration:

    • timezone - Your timezone (Ex: 'Europe/Paris')
    • units - Choose your temperature units (C or F)
    • api_key - DarkSky API Key
    • lat - Latitude
    • long - Longitude
    • nest_username - Nest login
    • nest_password - Nest password
    • nest_sn - Nest Thermostat serial number
    • nest_protect - Set true if you Nest Protect product
    • mysql_username - MySQL user
    • mysql_password - MySQL password
    • mysql_hostname = IP or FQDN of your MySQL server
    • mysql_database = Database name
  • (Opt) Edit the docker-compose.yml file to specify your ENV variables.

  • Build Docker image:

     docker-compose build
    
  • Run Project

     docker-compose up -d
    
  • Do both build and run in one command:

     docker-compose -f "docker-compose.yml" up -d --build
    

Classic Setup

This example is based on Debian Jessie with NGinx/PHP-FPM web server and MariaDB database engine.

  • Update your package lists and any pending updates before starting:

     sudo apt-get update
    
     sudo apt-get upgrade -y
    
  • Install required packages:

     sudo apt-get install nginx php5-fpm php5-mysql php5-curl mariadb-server mariadb-client git python-pip python-dev build-essential
    
     pip install -r setup/requirements.txt
    
  • Clone the repository:

     cd /opt && git clone [email protected]:gchenuet/nest-datagraph.git
    
  • Setup NGinx Virtual Host:

     sudo cp /opt/nest-datagraph/setup/nginx/nest-datagraph.conf /etc/nginx/sites-available/
    
     sudo ln -s /etc/nginx/sites-available/nest-datagraph.conf /etc/nginx/sites-enabled/nest-datagraph.conf
    
  • Modify the server_name parameter with your FQDN in nest-datagraph.conf :

     vim /etc/nginx/sites-enabled/nest-datagraph.conf
    
  • Reload NGinx

     sudo service nginx reload
    
  • Create a new MySQL user:

     CREATE USER '[username]'@'localhost' IDENTIFIED BY '[password]';
    
     GRANT ALL PRIVILEGES ON * . * TO '[username]'@'localhost';
    
  • Create the database and grant permissions:

     CREATE DATABASE nest_datagraph;
    
     GRANT ALL PRIVILEGES ON nest_datagraph.* TO '[username]'@'localhost';
    
  • Import the DB schema:

     sudo mysql -h <HOST> -u <USER> -p<PASSWORD> nest_datagraph < /opt/nest-datagraph/setup/db/nest-datagraph.sql
    
  • Open the crontab and add the line at the end of the file:

     crontab -e
    
     0   *   *   *   *   /usr/bin/python /opt/nest-datagraph/backend/poller.py
    
  • Fill in variables with your parameters in frontend/conf/settings.ini:

    • timezone - Your timezone (Ex: 'Europe/Paris')
    • units - Choose your temperature units (C or F)
    • owm_id - OpenWeatherMap API Key
    • owm_city_id - Your city ID (without quote, e.g: 2988507)
    • nest_username - Nest login
    • nest_password - Nest password
    • nest_sn - Nest Thermostat serial number
    • nest_protect - Set true if you Nest Protect product
    • mysql_username - MySQL user
    • mysql_password - MySQL password
    • mysql_hostname = IP or FQDN of your MySQL server
    • mysql_database = Database name
  • Enjoy (and wait a hour) !

Features & Known Issues

You can find and post new features or known issues in the Issues tab.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Report a bug

  1. Create an new issue
  2. Explain with details your issue
  3. Add your configuration (OS, Software version, etc)
  4. (Opt) Attach files
  5. Submit !

Acknowledgements

nest-datagraph's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nest-datagraph's Issues

Add more weather info

Hi,

I've updated my own version to store more weather info.
With that data I now also added some weather icons to the graph with an overlay (work in progress) (see below)

schermafbeelding 2017-01-19 om 09 17 17 (note I use curveType: 'function' for a curved line)

I was wondering how to best add these changes to the database, for new installs there is no issue but for upgrades people don't want to lose data.

Regards,

Bas

(i was thinking of making it so that the weather icon is only shown when weather actually changes, but I need to figure out how to handle proper alignment)

Docker version

Do you have any plans/interest in making/distributing a Docker container for this?

Heating time showing wrong data

Heating time chart seems to be showing wrong data or Y label should not be in hours. There is no way I could be heating 80 hours per day. The same issue seems to be with Away chart.

Does not handle database or Nest passwords containing '!'

The application does not work if either the MySQL password or the Nest account password configured in settings.ini contains an exclamation point (!). I was able to work around this by changing both of the passwords so that they did not include an exclamation point.

Interestingly, enclosing the offending password in single quotes enables the poller script to work, but breaks the site. The reverse happens when they are not enclosed in single quotes.

Error from the poller is:

HTTP Error 400: Bad Request"

Error from the nginx error log for the site is:

[error] 2067#0: *1 FastCGI sent in stderr: "PHP message: PHP Warning:  syntax error, unexpected '!' in ../conf/settings.ini on line 23
 in /opt/nest-datagraph/frontend/php/getDayHum.php on line 2
PHP message: PHP Notice:  date_default_timezone_set(): Timezone ID '' is invalid in /opt/nest-datagraph/frontend/php/getDayHum.php on line 3
PHP message: PHP Warning:  mysqli_connect(): (28000/1045): Access denied for user 'www-data'@'localhost' (using password: NO) in /opt/nest-datagraph/frontend/php/getDayHum.php on line 5
PHP message: PHP Warning:  mysqli_error() expects parameter 1 to be mysqli, boolean given in /opt/nest-datagraph/frontend/php/getDayHum.php on line 6" while reading response header from upstream, client: 10.42.42.104, server: nest.domain.local, request: "GET /php/getDayHum.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm.sock:", host: "nest.domain.local", referrer: "http://nest.domain.local/"

Split backend settings in seperate gitignored file

Managing changes and general VC would be a bit easier if all settings/secrets were split-out into independent files that could be ignored by git. This is already done by the php frontend (ini file), but is not done by the python polling script.

login form

Is it possible to create a login form so you need to enter username/password before you see the nest data?

Farenheit?

What is the process for converting the temperatures to Farenheit? It looks like the python scripts and a php script have to be edited?

OpenWeatherMap City

The owm_city variable doesn't seem very accurate. Can the code be modified to accept a city ID instead?

Presence hours

First of all, thanks for the software en guide, great stuff ^^

The away status always seems to show Absence hours / Off, never Presence hours.
Looking at your screenshot to me it seems you have the same issue. (Energy tab, then scroll to the bottom)

Before i start digging, should this already be working? Or is this work in progress?

I also have an issue with it not showing my nest protects, page comes up with just the header, blank body. Seems related to $nest = new (Nest), probably something wrong on my end :P

About my setup, i created a Docker with Debian Jessie image. I used your guide to setup, any errors because of missing components i installed at that point. Running fine ^^

p.s.
There is a typo in the guide, at the cron part: 0 * * * * /usr/bin/python /opt/nest_datagraph/backend/poller.py should be 0 * * * * /usr/bin/python /opt/nest-datagraph/backend/poller.py

No more "Works with Nest"?

I'm assuming that this solution no longer works with the retirement of the WWN program and the migration to Google accounts?

Ask a question about yet-another-cloudwatch-exporter

this is my config

My question is "No NLB health metrics"

apiVersion: v1
data:
config.yml: |
discovery:
exportedTagsOnMetrics:
nlb:

  • Department
  • Tier
  • Environment
  • Project
    jobs:
  • type: "nlb"
    regions:
  • cn-north-1
    nilToZero: true
    metrics:
  • name: UnHealthyHostCount
    statistics: [Maximum]
    period: 60
    delay: 120
  • name: HealthyHostCount
    statistics: [Minimum]
    period: 60
    delay: 120

ConfigParser issue when using poller.py

Hi,

I used to run an old version of Nest Datagraph (thank you very much by the way) without configparser.
I just did a clone of the repository (in a new directory) in order to update my installation.

When I tried to run poller.py, I've got issue bellow :

[root@lab nest-datagraph]# /usr/bin/python /opt/nest-datagraph/backend/poller.py
ConfigParser instance has no attribute '__getitem__'

It seems it could be due to a syntax issue regarding python2 and python3. Indeed, the syntax used in poller.py seems to be intended to run with python3.
Altough, nest.py is developed to use python2.

Maybe something is wrong in my environment.

Please find bellow the details of my environment :

[root@lab nest-datagraph]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core)

[root@lab nest-datagraph]# uname -a
Linux 4.4.6-std-2 #1 SMP Mon Mar 21 13:41:00 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

[root@lab nest-datagraph]# python -V
Python 2.7.5

[root@lab nest-datagraph]# pip -V
pip 18.1 from /usr/lib/python2.7/site-packages/pip (python 2.7)

[root@lab nest-datagraph]# pip install -r setup/requirements.txt
Requirement already satisfied: datetime in /usr/lib64/python2.7/site-packages (from -r setup/requirements.txt (line 1)) (4.3)
Requirement already satisfied: mysql-connector-python in /usr/lib/python2.7/site-packages (from -r setup/requirements.txt (line 2)) (2.1.7)
Requirement already satisfied: pyowm in /usr/lib/python2.7/site-packages (from -r setup/requirements.txt (line 3)) (2.7.1)
Requirement already satisfied: configparser in /usr/lib/python2.7/site-packages (from -r setup/requirements.txt (line 4)) (3.5.0)
Requirement already satisfied: zope.interface in /usr/lib64/python2.7/site-packages (from datetime->-r setup/requirements.txt (line 1)) (4.0.5)
Requirement already satisfied: pytz in /usr/lib/python2.7/site-packages (from datetime->-r setup/requirements.txt (line 1)) (2016.10)
Requirement already satisfied: setuptools in /usr/lib/python2.7/site-packages (from zope.interface->datetime->-r setup/requirements.txt (line 1)) (0.9.8)

[root@lab nest-datagraph]# pip list | grep configparser
configparser                     3.5.0

Thank you for your help/inputs

Nest-datagraph on Synology NAS : SSL error

I am trying to get nest-datagraph running on a synology NAS, the front end works immediately out of the box, but with the backend python script I get an SSL certificate error:

sjirk@boonshare:/volume1/web/nest/backend$ /usr/local/python/bin/python poller.py
<urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:661)>

the python version is:
Python 2.7.14 (default, May 28 2018, 14:46:53)
[GCC 4.6.3] on linux2

is there a solution ?

Cooling Stats

Hi!
Love the graphs. My nest functions only in off or cooling mode, no heating. Have you any plans for adding cooling status on the energy tab? I see right now it's heating oriented.
Thanks!

Add Nest Protect product

Add a new dashboard for Nest Protect product.

Some ideas:

  • General status
  • Smoke status
  • CO2 status
  • WiFi status
  • Electrical/Battery status

nest-datagraph_nestdatagraph_1 continual restarts

I setup the ini, built the images, but when i run the app, it fails to start properly and throws nest-datagraph_nestdatagraph_1 exited with code 2 repeatedly.

I try and docker exec -it into the container and it fails as the container is continually restarting. This is posing an issue in debugging it.

Starting nest-datagraph_mariadb_1 ... done
Recreating nest-datagraph_nestdatagraph_1 ... done
Attaching to nest-datagraph_mariadb_1, nest-datagraph_nestdatagraph_1
mariadb_1        | 2019-05-30 21:33:32 0 [Note] mysqld (mysqld 10.3.15-MariaDB-1:10.3.15+maria~bionic) starting as process 1 ...
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Using Linux native AIO
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Uses event mutexes
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Number of pools: 1
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Using SSE2 crc32 instructions
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Initializing buffer pool, total size = 256M, instances = 1, chunk size = 128M
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Completed initialization of buffer pool
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: 128 out of 128 rollback segments are active.
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Waiting for purge to start
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: 10.3.15 started; log sequence number 1630869; transaction id 21
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mariadb_1        | 2019-05-30 21:33:32 0 [Note] Plugin 'FEEDBACK' is disabled.
mariadb_1        | 2019-05-30 21:33:32 0 [Note] InnoDB: Buffer pool(s) load completed at 190530 21:33:32
mariadb_1        | 2019-05-30 21:33:32 0 [Note] Server socket created on IP: '::'.
mariadb_1        | 2019-05-30 21:33:32 0 [Warning] 'proxies_priv' entry '@% root@d6a171cf6df1' ignored in --skip-name-resolve mode.
mariadb_1        | 2019-05-30 21:33:32 0 [Note] Reading of all Master_info entries succeded
mariadb_1        | 2019-05-30 21:33:32 0 [Note] Added new Master_info '' to hash table
mariadb_1        | 2019-05-30 21:33:32 0 [Note] mysqld: ready for connections.
mariadb_1        | Version: '10.3.15-MariaDB-1:10.3.15+maria~bionic'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  mariadb.org binary distribution
: invalid option namentrypoint.sh: line 2: set: pipefail
nest-datagraph_nestdatagraph_1 exited with code 2
nest-datagraph_nestdatagraph_1 exited with code 2
nest-datagraph_nestdatagraph_1 exited with code 2
Gracefully stopping... (press Ctrl+C again to force)
Stopping nest-datagraph_nestdatagraph_1   ... done
Stopping nest-datagraph_mariadb_1         ... done```

Protect

Installed this app yesterday and today with some help from Guillaume its working (thanks Guillaume!).
Only the Protect link gives me a total blank page... in params.ini I enabled the protect setting.
Any idea?

Thanks!

p.s. please increase the time between polling, once an hour is in my opinion to low. Most of the Google scripts use an interval of 5 minutes. 1 minute is to often and will cause throttling from the nest site. 5 minutes will be ok I think.

Troubleshooting cron job and db.

I'm not sure if this is the right place for this. I am having problems getting my setup working.

I first checked the db and it is empty.
MariaDB [nest_datagraph]> select * from status;
Empty set (0.00 sec)

I found this in the syslog.
Dec 3 16:00:02 raspberrypi CRON[18964]: (pi) CMD (/usr/bin/python /opt/nest-datagraph/backend/poller.py)
Dec 3 16:00:02 raspberrypi CRON[18960]: (CRON) info (No MTA installed, discarding output)

Any ideas? Thanks.

Docker build fails

Hi,
When building the DockerFile it fails eventually with the following error:

Step 8/18 : ADD setup/nginx/nest-datagraph.conf /etc/nginx/sites-available/default.conf ADD failed: stat /var/lib/docker/tmp/docker-builder059889255/setup/nginx/nest-datagraph.conf: no such file or directory

Any idea? I'm using Docker on Mac.
Thanks
Steven

date function used repeatedly which increases load time

In the PHP code to pull the data from the SQL db you use code like

https://github.com/gchenuet/nest-datagraph/blob/master/frontend/php/getTemp.php#L14

$date_array = "Date(".date('Y', $phpdate).",".(date('n', $phpdate)-1).",".date('d', $phpdate).",".date('H', $phpdate).",".date('i', $phpdate).")";

which I just found out almost doubles the page load time when running this script on an old Raspberry Pi.

Changing the code to be

$nMinus = date('n', $phpdate)-1;
$date_array = "Date(".date('Y,'.$nMinus.',d,H,i', $phpdate).")";

helps massively. it brought the total loading of JSON data for the energy.php page down from 11 seconds to 6 seconds.

Cannot login after switching to Google account

A week ago I tried to login to my Nest account and then I was asked to switch my Nest account to Google account, which I did. From that time I am no longer seeing any data updates. I guess it is because the old login method no longer works. Even if I enter my Google account credentials it returns HTTP 400.

Is there any workaround for it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.