Page 5 of 14

Re: NEST Account migration

Posted: Saturday 25 January 2020 14:36
by rolandbreedveld
as requested by @Marcello1970 :

a new version 1.03, with a bugfix and support for both Away and ECO mode,
- nest_auth.php is renamed to nest_auth.php-example, so it won't overwrite your file.
- idx and devices are moved from the get_nest.sh script to a config file: nest_devices.cfg
- delivered as nest_devices.cfg-example, so it won't overwrite your file.

so if you want it, create a extra virtual device for the away-mode (see README.md)
important: before installing,write down the idx numbers from your current get_nest.sh
rename nest_devices.cfg-example to nest_devices.cfg, and change the IDX numbers to yours.
suc6!

Re: NEST Account migration

Posted: Sunday 26 January 2020 16:26
by Marcello1970
Ho Roland,

I have tested the new version, there are some strange thinks.

The set / unset ECO mode command works, but I get a error message:

Code: Select all

PHP Warning:  file_put_contents(/tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2): failed to open stream: Permission denied in /home/pi/nest-api/nest.class.php on line 1191
bool(true)
The set / unset Away mode works strange and I get the same error message as above.
When I excute the command set Away mode, the ECO get set instead.
When I excute the command unset Away mode, the ECO gets unset, but the Away mode get set or stays set.

Re: NEST Account migration

Posted: Sunday 26 January 2020 16:32
by rolandbreedveld
Marcello1970 wrote: Sunday 26 January 2020 16:26 Ho Roland,

I have tested the new version, there are some strange thinks.

The set / unset ECO mode command works, but I get a error message:

Code: Select all

PHP Warning:  file_put_contents(/tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2): failed to open stream: Permission denied in /home/pi/nest-api/nest.class.php on line 1191
bool(true)
The set / unset Away mode works strange and I get the same error message as above.
When I excute the command set Away mode, the ECO get set instead.
When I excute the command unset Away mode, the ECO gets unset, but the Away mode get set or stays set.
looks like the file /tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2 is not allowed, is it possible you run it 1st as root and after that with another user?
remove it rm -rf /tmp/nest_php*, and try it again ?

Re: NEST Account migration

Posted: Sunday 26 January 2020 17:04
by Marcello1970
rolandbreedveld wrote: Sunday 26 January 2020 16:32 looks like the file /tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2 is not allowed, is it possible you run it 1st as root and after that with another user?
remove it rm -rf /tmp/nest_php*, and try it again ?
With user root it's works all fine.
After that with the normal user (pi) I get a double error message and strange behavior.

Code: Select all

PHP Warning:  file_put_contents(/tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2): failed to open stream: Permission denied in /home/pi/nest-api/nest.class.php on line 1191
Setting away mode...
PHP Warning:  file_put_contents(/tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2): failed to open stream: Permission denied in /home/pi/nest-api/nest.class.php on line 1191
bool(true)
When I remove the two nest.php files, I get only one error message.

Code: Select all

PHP Warning:  file_put_contents(/tmp/nest_php_cache_9585540375c319a527bcca3b68e07fe2): failed to open stream: Permission denied in /home/pi/nest-api/nest.class.php on line 1191
extra:
I have manually extend the user user rights of the two files in the temp map and now the normal user also works also good.

Re: NEST Account migration

Posted: Sunday 26 January 2020 18:07
by Quiphainyr
@rolandbreedveld
Man, you're a hero! I got my Nest Thermostat working in Domoticz again after migrating to a Google account :)
One question though... Do you have to update the cookie and issuetoken often in order to keep it running?

Many thanks for all your effort! Cheers!

Re: NEST Account migration

Posted: Monday 27 January 2020 11:21
by rolandbreedveld
Quiphainyr wrote: Sunday 26 January 2020 18:07 @rolandbreedveld
Man, you're a hero! I got my Nest Thermostat working in Domoticz again after migrating to a Google account :)
One question though... Do you have to update the cookie and issuetoken often in order to keep it running?

Many thanks for all your effort! Cheers!
I never had to change it, I think when it runs frequently, it won't be an issue.

Re: NEST Account migration

Posted: Monday 27 January 2020 18:33
by Quiphainyr
rolandbreedveld wrote: Monday 27 January 2020 11:21 I never had to change it, I think when it runs frequently, it won't be an issue.
Awesome! So far everything works again. Really happy! Thanks again!

Re: NEST Account migration

Posted: Monday 27 January 2020 22:53
by romain1206
hello

it's possible to have the same device for the Temp + Humidity (WTGR800)

many thanks

Re: NEST Account migration

Posted: Tuesday 28 January 2020 11:55
by rolandbreedveld
romain1206 wrote: Monday 27 January 2020 22:53 hello

it's possible to have the same device for the Temp + Humidity (WTGR800)

many thanks
I don't know which one is the WTGR800, but if you create a virtual device "Tem+Hum", it will create a "THGN122/123/132, THGR122/228/238/268"

actually I think you'r request is more elegant than my 2 different sensors, so thanxz for the idea romain1206

I added it to the script, both solutions are possible,
add the virtual "Temp+Hum" device,
add "TEMPHUM 511" (with your IDX) to nest_devices.cfg
you can use them both, or if you don't, remove or place a # for the lines you don't use.

good luck

Re: NEST Account migration

Posted: Thursday 30 January 2020 10:00
by joost81
Awesome! Took some time, but I got it to work perferctly! Thanks

Please not that you'll need to install php 7.3 on Raspbian Buster

Re: NEST Account migration

Posted: Friday 31 January 2020 16:59
by blackie
Thank you guys for this solution,
I have finally decided to migrate my account, but have a mixed result.
UPDATED:
Configuration went OK, SetPoint and Temp/Humi devices are working - status updates via cron job, but HEAT switch doesn't work.
My nest-api directory path is a bit different from default, but was updated in all files according to README.

Domoticz Nest devices are:
105 Dummy Nest_TempHumi Temp + Humidity THGN122/123/132, THGR122/228/238/268
106 Dummy Nest_SetPoint Thermostat SetPoint
107 Dummy Nest_ECO Light/Switch Switch Off - -
108 Dummy Nest_Away Light/Switch Switch Closed - -
109 Dummy Nest_Heating Light/Switch Switch Off - -
110 Dummy Nest_Protect Light/Switch Switch Off - -

file nest_devices.cfg was updated with correct device_idx codes:
Device idx
============
SETPOINT 106
AWAYMODE 108
ECOMODE 107
HEAT 109
TEMPHUM 105
PROTECT 110

OS is Raspbian Stretch from OpenMediaVault 4.1 with php 7.0.33 that resists to upgrade to 7.3.
Any suggestions where the HEAT switch problem reason could be?
What about Nest Protect sensor, is it supported in nest_devices.cfg via some code (PROTECT, or else)?

Thanks in advance
P.S. Away and ECO switches started to work after I changed Away switch type from "Door contact" to "On/Off" (used "Door contact" before because of icon). But HEATING switch still refuses to update it's status from Nest or control heating (switch type is "On/Off" and nest_devices.cfg line is "HEAT 109")...

Re: NEST Account migration

Posted: Sunday 02 February 2020 10:02
by Joncho
Thanks Roland, took the leap and managed to get it to work.

It took some time, because I hadn't added 127.0.0.* to the whitelist in the Domoticz settings, just my local network 192.168.1.*. Before adding the local IP, I could only set temperature, Away and Eco Mode and couldn't get the status of the Nest hardware.

Re: NEST Account migration

Posted: Thursday 06 February 2020 3:52
by Cloudwraith
So, after a bit of work, I too have this working with my Nest Gen2.

One issue I ran into was that, here in the USA, my temperatures are in F. Domoticz is set to show my units in F. I'm not sure if the issue is with Domoticz or the updating script (get_nest.sh) but my nest returns a F number and the script passes this on to Domoticz which then assumes this is a C number and converts it to F leaving me with something like 160F for a room temperature.

I solved this temporarily by converting the F number received from the Nest to C in the get_nest.sh script before it updates Domoticz.

You should install bc (sudo apt-get install bc) if you don't have it installed as bc will help with fractional numbers.

Clearly I'm not the best bash script writer in the world and this is admittedly a complete hack but it got the job done for me and may help others.

Line 88 of get_nest.sh

Code: Select all

  if [ ! -z "${IDX}" ]
  then
    if [ "${TYPE}" == "TEMP" ]
    then
      VALC=$(echo "scale=2;(5/9)*($VALUE-32)"|bc)
      curl -X GET "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=${IDX}&nvalue=0&svalue=${VALC}" >/dev/null 2>&1
      echo "Update ${TYPE} to $VALC"
    fi
This only changes the value for Temperature, not the setpoint or temp+humid. I did notice that get_nest.php returns a "Scale" parameter. Perhaps the original author could check this value and, if F, convert all numbers to C before updating Domoticz. If the value is C then just send the numbers as is.

Re: NEST Account migration

Posted: Friday 07 February 2020 15:07
by rolandbreedveld
blackie wrote: Friday 31 January 2020 16:59 Any suggestions where the HEAT switch problem reason could be?
What about Nest Protect sensor, is it supported in nest_devices.cfg via some code (PROTECT, or else)?
Heat wasn't updated, a bug, enclosed the fix

PROTECT can be added, if it gives no output from my account
please do:
php nest-api.php
if it's correct it should give more info than on my account:

Devices list (Nest Protect):
[]

Re: NEST Account migration

Posted: Friday 07 February 2020 15:21
by rolandbreedveld
Cloudwraith wrote: Thursday 06 February 2020 3:52 One issue I ran into was that, here in the USA, my temperatures are in F. Domoticz is set to show my units in F. I'm not sure if the issue is with Domoticz or the updating script (get_nest.sh) but my nest returns a F number and the script passes this on to Domoticz which then assumes this is a C number and converts it to F leaving me with something like 160F for a room temperature.
Never understand why you US-people use Fahrenheit and inches .... ;)
so if you use temp+hum, and not separate devices it works without modifications?

Re: NEST Account migration

Posted: Friday 07 February 2020 15:38
by rolandbreedveld
cause of changes, bugfixes, and user requests, my nest-api scripts are on github now:

https://github.com/rolandbreedveld/nest-api

Re: NEST Account migration

Posted: Friday 07 February 2020 17:14
by Cloudwraith
rolandbreedveld wrote: Friday 07 February 2020 15:21 so if you use temp+hum, and not separate devices it works without modifications?
No, I just didn't modify the temp+humid part of the script. I use Temp and Humidity separately so for me, just modifying the temp was enough for a quick fix. I guess the best thing to do would be to check the scale returned from the nest and modify all temps to C (if the scale is F) before sending on to domoticz.

Re: NEST Account migration

Posted: Friday 07 February 2020 17:31
by rolandbreedveld
Cloudwraith wrote: Friday 07 February 2020 17:14
rolandbreedveld wrote: Friday 07 February 2020 15:21 so if you use temp+hum, and not separate devices it works without modifications?
No, I just didn't modify the temp+humid part of the script. I use Temp and Humidity separately so for me, just modifying the temp was enough for a quick fix. I guess the best thing to do would be to check the scale returned from the nest and modify all temps to C (if the scale is F) before sending on to domoticz.
I can change it in the code, wit a setting parameter, if you like

Re: NEST Account migration

Posted: Friday 07 February 2020 21:34
by blackie
rolandbreedveld wrote: Friday 07 February 2020 15:07
blackie wrote: Friday 31 January 2020 16:59 Any suggestions where the HEAT switch problem reason could be?
What about Nest Protect sensor, is it supported in nest_devices.cfg via some code (PROTECT, or else)?
Heat wasn't updated, a bug, enclosed the fix

PROTECT can be added, if it gives no output from my account
please do:
php nest-api.php
if it's correct it should give more info than on my account:

Devices list (Nest Protect):
[]
Thank you Roland for the fix, Heating switch is working fine in the latest version.
If I run "php get_nest.php" I can see device ID for my Nest Protect device in the output:
Devices list (Nest Protect):
[
"06?????????????"
]
But there is no section "Device information" for Protect device like there is for Thermostat device...
I can't test the protect sensor switch in Domoticz right now but I plan to do it later.
Thanks a lot for your good work

Re: NEST Account migration

Posted: Saturday 08 February 2020 19:44
by jeroenkl
Hmmm need help,
This is what I get:

pi@raspberrypi:~/nest-api $ ./get_nest.sh
PHP Fatal error: Uncaught Error: Call to undefined function curl_init() in /home/pi/nest-api/nest.class.php:1256
Stack trace:
#0 /home/pi/nest-api/nest.class.php(1224): Nest->doRequest('GET', 'https://account...', NULL, true, Array)
#1 /home/pi/nest-api/nest.class.php(1089): Nest->doGET('https://account...', Array)
#2 /home/pi/nest-api/nest.class.php(124): Nest->login()
#3 /home/pi/nest-api/get_nest.php(19): Nest->__construct(NULL, NULL, 'https://account...', 'OCAK=xxxxxxxx..')
#4 {main}
thrown in /home/pi/nest-api/nest.class.php on line 1256

thanks in advance.

Jeroen