Page 1 of 4

Rebuilding the Nest plugin

Posted: Monday 01 May 2017 23:15
by dotms
Domoticz comes with a hardware plugin to control the Nest thermostat and the accompanying smoke/co detectors.

While this works (for now) there are some issues with this plugin:
  • It uses a non-public API. As far as I can tell an old API for mobile applications is used. Several projects (including Domoticz) use this API but there's no telling how much longer it will work.
  • Documentation for this API is non-existant. By the looks of it some (successful) reverse engineering has been done to access the API.
  • Having 2FA (2 factor authentication) enabled on the account locks Domoticz out because Domoticz cannot supply an additional PIN code.
  • (minor issue): Plain credentials to the Nest account need to be entered and be kept up to date to allow Domoticz to keep working.
Nest has a solution for this. There is a public developer REST API available which is fully supported, is documented. The 2FA issue is circumvented by having OAuth support (so you generate a token specifically for Domoticz that it can use as a 'password' to access the Nest API).

I went ahead and adapted the current Nest plugin to use the new authentication method, calls and properties (for those interested in code see here). Still needs a bit of polishing and cleanup though.

There are some points that still need to be tackled:
  • Getting an access token for Domoticz is a kind of convoluted process: you need to register with Nest as a developer, create an application and permission set, log in as that application, get one-time PIN code, use that PIN code to obtain token. While it is certainly doable, it will need to be well documented on the Wiki. Even then it is much less accessible than just entering a user+pass to make it work.
  • I intend on having it replace the old plugin, but it is not compatible since it uses a different form of authentication.
  • What are the thoughts on the old and new style plugins coexisting in Domoticz?
Happy to hear your thoughts on this.

Re: Rebuilding the Nest plugin

Posted: Wednesday 03 May 2017 22:46
by dotms
Any thoughts?

Re: Rebuilding the Nest plugin

Posted: Thursday 04 May 2017 16:13
by Graph54
Hi Dotms !

This is a very good idea ! If you can improve this part that would be really great. I am not very good at coding but If I can help ... :)

Re: Rebuilding the Nest plugin

Posted: Sunday 18 June 2017 19:58
by Damnet
That would really be a step up!!

Re: Rebuilding the Nest plugin

Posted: Saturday 15 July 2017 8:12
by Dlanor
Your Nest Thermostat will automatically switch to Eco Temperatures after it senses that nobody’s home. You can also manually set your thermostat to Eco Temperatures anytime, even when you’re home.
Is there a fast way to add the Eco mode as a switch in domoticz?

Re: Rebuilding the Nest plugin

Posted: Tuesday 19 September 2017 17:29
by Graph54
Hi ! I've seen the code you've done on Github but I don't really understand where we are now :) Do we have to compile our own Domoticz or is it planned to be part of the official branch ? I do apologize for my "beginner's" questions :)

Re: Rebuilding the Nest plugin

Posted: Sunday 03 December 2017 22:58
by dotms
It's been a while since I last posted, so let's post an update.

Since last post no noteworthy action has been done on my side. Different priorities in life shifted my attention kind of away. Besides this my pc that I use to code/build is a pile of parts now so I'll need to get that up and running again. I expect that to be finished probably within the next week or so, but the time that I can spend on domoticz itself is quite limited unfortunately.

Once I get the build/coding machine working I need to catch up with the current domoticz code base. There probably have been some changes upstream so I need to merge those changes into my downstream repository and hope nothing major breaks :) From there I'll test stuff again, write some documentation and see if I can cobble a pull request together so the code ends up in the main domoticz code tree.

Besides that: I noticed that for me the current Nest device in Domoticz stopped working (at least for me it did: "Error: Nest: Error login!"). Running latest domoticz git version. Anyone else running into this as well resulting in Nest support currently being broken? If so I can try and give the above a little more priority since that hits more people than just me.

edit: managed to resolve the login issue. Was an issue on the side of probably Debian 9. Reverted to Ubuntu 16.04 and all is fine.

Re: Rebuilding the Nest plugin

Posted: Thursday 28 December 2017 19:47
by dotms
Small update on my part.
  • My build machine is up and running again.
  • Merged upstream changes from domoticz/master repo into my version.
  • It still builds. Did some layout fixes and everything works first time.
I did have to change a lot of stuff around to get it to work in Visual Studio 2017 so I did not commit any msbuild related stuff. I'll try and see if I can get it in such a state that it's still compatible with VS2015. If I'm lucky I might be able to squish out a pull request.

Re: Rebuilding the Nest plugin

Posted: Thursday 28 December 2017 23:35
by dotms
Another update: I submitted a pull request: https://github.com/domoticz/domoticz/pull/2026.

If anyone wants to test this new functionality the basic steps come down to:

- Compile a new version of Domoticz from my git repo (while the pull request is not yet accepted).
- Register for an account at Nest Developers
- Create an application so you get a product id and a secret.
- Follow the link displayed so you get a pin code.
- Enter those 3 pieces in domoticz so it will fetch an API key and can communicate with Nest in a secure manner.

Image

Re: Rebuilding the Nest plugin

Posted: Sunday 07 January 2018 9:26
by Mdieli
Thanks dotms!
Just tested it here in my test environment and all is looking good and working like expected thus far!
I hope integration in domoticz will be done quickly. :)

Re: Rebuilding the Nest plugin

Posted: Saturday 20 January 2018 13:12
by Madgeni
Hi - does this still split out NEST functionality into multiple devices? Is there still a separate setpoint and sensor?

Re: Rebuilding the Nest plugin

Posted: Tuesday 23 January 2018 13:10
by MarceldeJongNL
gizmocuz denied the pull request, with the following comment:

Is it possible you could submit the pull request against the development branch ? Patches against the master branch are not allowed (Sorry)

Re: Rebuilding the Nest plugin

Posted: Monday 29 January 2018 22:28
by dotms
I'll put some effort in a new pull request this weekend or sooner :)

Re: Rebuilding the Nest plugin

Posted: Tuesday 06 March 2018 10:40
by poudenes
Version: 3.8975
Build Hash: 63d0d07e
Compile Date: 2018-02-28 08:26:48
dzVents Version: 2.4.1
Platform: Raspbian Jessie (updated today 05-03-2018)
Hardware: Nest Thermostat/Protect OAuth

Nest Thermostat/Protect normal way with username password work without problems.
But i have now 3 Protect devices. And with normal username/pasword way connect i only see smoke sensors.

When i use the OAuth method i see smoke and CO Sensors. But then i get sometimes this error:

Code: Select all

2018-03-05 10:17:34.832 Error: NestOAuthAPI: Error getting structures!
2018-03-05 10:18:06.090 Error: NestOAuthAPI: Error login!
2018-03-05 10:18:37.232 Error: NestOAuthAPI: Error login!
2018-03-05 10:19:08.390 Error: NestOAuthAPI: Error login!
2018-03-05 10:19:39.903 Error: NestOAuthAPI: Error login!
2018-03-05 10:20:11.783 Error: NestOAuthAPI: Error login!
2018-03-05 10:20:43.115 Error: NestOAuthAPI: Error login!
2018-03-05 10:21:47.672 Error: NestOAuthAPI: Error getting structures!
2018-03-05 10:22:18.915 Error: NestOAuthAPI: Error login!
2018-03-05 10:22:49.899 Error: NestOAuthAPI: Error login!
2018-03-05 10:23:24.597 Error: NestOAuthAPI: Error login!
2018-03-05 10:23:55.840 Error: NestOAuthAPI: Error login!
2018-03-05 10:24:27.029 Error: NestOAuthAPI: Error login!
2018-03-05 10:24:58.184 Error: NestOAuthAPI: Error login!
2018-03-05 10:25:29.463 Error: NestOAuthAPI: Error login!
2018-03-05 10:26:00.626 Error: NestOAuthAPI: Error login!
2018-03-05 10:26:31.214 Error: NestOAuthAPI: Error login!
2018-03-05 10:27:01.849 Error: NestOAuthAPI: Error login!
2018-03-05 10:27:33.006 Error: NestOAuthAPI: Error login!
2018-03-05 10:28:04.514 Error: NestOAuthAPI: Error login!
2018-03-05 10:28:35.651 Error: NestOAuthAPI: Error login!
2018-03-05 10:29:06.840 Error: NestOAuthAPI: Error login!
2018-03-05 10:32:23.035 Error: NestOAuthAPI: Error getting devices!

Re: Rebuilding the Nest plugin

Posted: Monday 19 March 2018 14:42
by tcviper
Either Im blind or stupid but i cannot seem to find the OAUTH PIN anywhere when im editting a Nest application on the Nest dev pages.
I do find my id and secret, but there is nowhere i can find the oauth pin.

Re: Rebuilding the Nest plugin

Posted: Monday 19 March 2018 14:48
by dotms
In your Nest developer portal there should be an authentication link on the product page (below the product id and secret). Follow that one, log in with your Nest credentials and you'll get a PIN.

Re: Rebuilding the Nest plugin

Posted: Wednesday 21 March 2018 1:02
by Robbie
Are you planning to also add a switch for the "Manual Eco Mode" like the other nest-plugin?

Re: Rebuilding the Nest plugin

Posted: Wednesday 21 March 2018 11:41
by poudenes
dotms wrote: Monday 19 March 2018 14:48 In your Nest developer portal there should be an authentication link on the product page (below the product id and secret). Follow that one, log in with your Nest credentials and you'll get a PIN.

Any idea why i get lots of errors?

Re: Rebuilding the Nest plugin

Posted: Thursday 22 March 2018 17:15
by leecollings
Robbie wrote: Wednesday 21 March 2018 1:02 Are you planning to also add a switch for the "Manual Eco Mode" like the other nest-plugin?
Isn't that what the current 'ECO' switch is?

Re: Rebuilding the Nest plugin

Posted: Friday 23 March 2018 13:54
by Robbie
leecollings wrote: Thursday 22 March 2018 17:15
Robbie wrote: Wednesday 21 March 2018 1:02 Are you planning to also add a switch for the "Manual Eco Mode" like the other nest-plugin?
Isn't that what the current 'ECO' switch is?
The original Nest Thermostat/Protect adds this 'ECO' switch.
But this new Nest Thermostat/Protect OAuth (the rebuilded plugin which is discussed in this topic) does not have this ECO switch.