gboudreau / nest-api

Unofficial Nest Learning Thermostat API
GNU Lesser General Public License v3.0
299 stars 92 forks source link

Nest API No Longer Working #115

Closed zecanard closed 4 years ago

zecanard commented 4 years ago

Starting February 25, the Nest API has stopped working for me. I was waiting to see if someone else would raise the same issue, and/or if it would go away, but it’s still happening. Is it still working for anyone else?

Since I made custom modifications to the PHP class for my personal environment, I downloaded the latest one from GitHub and simply invoked $nest -> getDeviceInfo() (having obtained a Nest object using my login credentials).

The response:

Warning: Invalid argument supplied for foreach() in nest.class.php on line 408
stdClass Object
(
    [current_state] => stdClass Object
        (
            [mode] => off,
            [temperature] => 0
            [backplate_temperature] => 0
            [humidity] => 
            [ac] => 
            [heat] => 
            [alt_heat] => 
            [fan] => 
            [hot_water] => 
            [auto_away] => 
            [manual_away] => 
            [structure_away] => 
            [leaf] => 
            [battery_level] => 
            [active_stages] => stdClass Object
                (
                    [heat] => stdClass Object
                        (
                            [stage1] => 
                            [stage2] => 
                            [stage3] => 
                            [alt] => 
                            [alt_stage2] => 
                            [aux] => 
                            [emergency] => 
                        )

                    [cool] => stdClass Object
                        (
                            [stage1] => 
                            [stage2] => 
                            [stage3] => 
                        )

                )

            [eco_mode] => 
            [eco_temperatures_assist_enabled] => 
            [eco_temperatures] => stdClass Object
                (
                    [low] => 
                    [high] => 
                )

        )

    [target] => stdClass Object
        (
            [mode] => 
            [temperature] => 
            [time_to_target] => 
        )

    [sensors] => stdClass Object
        (
            [all] => Array
                (
                )

            [active] => Array
                (
                )

            [active_temperatures] => Array
                (
                )

        )

    [serial_number] => 
    [scale] => 
    [location] => 
    [network] => stdClass Object
        (
            [online] => 
            [last_connection] => 1970-01-01 00:00:00
            [last_connection_UTC] => 1970-01-01 00:00:00
            [wan_ip] => 
            [local_ip] => 
            [mac_address] => 
        )

    [name] => Not Set
    [auto_cool] => 
    [auto_heat] => 0
    [where] => 
)

Line 408 is foreach ($this->last_status->rcs_settings->{$serial_number}->associated_rcs_sensors as $sensor_serial) { in function getDeviceInfo().

I have not migrated my account to Google, and my login token is valid (using the workaround script). However, the URL to the web interface has changed to https://home.nest.com/thermostat/DEVICE_{some_identifier_not_serial_number}.

vjooris commented 4 years ago

Hello, I do confirm it is stilll working properly for me. Eventually try by renewing your issue_ token & your cookies.

(only needs to be done once, as long as you stay logged into your Google

cagivacode commented 4 years ago

I have not migrated to google and the API is still working, I last renewed my token about 2 weeks ago

vjooris commented 4 years ago

So now, your are "sure" of the origin of the issue : exited token. Because I've migrated my Nest account to Google account.

zecanard commented 4 years ago

This is very strange… I’m still trying to troubleshoot, but my access token seems valid. I renew it every 2 weeks, and on every reboot as well. I tried logging out and back in, then re-executing the login script, with no success either.

vjooris commented 4 years ago

"stupid" question : they are well entered between " ` issue_token = "enter_your_issue_token_here"

cookies = "enter_your_cookies_here" 

`

zecanard commented 4 years ago

@vjooris I haven’t migrated to a Google account, so I only pass in my Nest username and password, correct?

vjooris commented 4 years ago

I do no more have a Nest Account, so I can't test. But this is what it is written in the doc.

// Use a Nest account: $username = 'you@gmail.com'; $pasword = 'Something other than 1234 right?'; $nest = new Nest($username, $pasword);

But why don't you switch to a Google Account ?

vjooris commented 4 years ago

did you tried this ?

Use try...catch to catch exceptions that could occur:

try { $nest = new Nest(NULL, NULL, $issue_token, $cookies); // Execute all Nest-related code here } catch (UnexpectedValueException $ex) { // Happens when the issue_token or cookie is not working, for whatever reason $error_message = $ex->getMessage(); mail(...); } catch (RuntimeException $ex) { // Probably a temporary server-error } catch (Exception $ex) { // Other errors; should not happen if it worked in the past }

// Continue your code here, for example to save the result in a database

zecanard commented 4 years ago

@vjooris Yes, I already had code in place for catching exceptions and emailing me on errors; there is no failure that I can see. I’m still trying to debug this, but if I can’t figure it out, I’ll just migrate to a Google login. There doesn’t appear to be any more downsides since the API was updated to support Google logins?

Thank you very much for your assistance. I really appreciate it.

vjooris commented 4 years ago

sorry (UK is not my mother thong), I do not understand "There doesn’t appear to be any more downsides since the API was updated to support Google logins?". Could your rephrase ?

This is my real pleasure to try to help people, when I can.

zecanard commented 4 years ago

Do you lose anything by migrating to a Google login? Thank you.

vjooris commented 4 years ago

no, I didn't loose anything as functionality. This move is not reversible. On my MAC, I do have several Google accounts, and every time, I want to connect to my Nest, he ask me witch account to use (but no password or double authentication request). On my phone, I do only have one Google account , and their no request ;-)

for the remaining, the migration is transparant.

bauzer714 commented 4 years ago

You can check the FAQ from Google if you'll have negative impacts from transitioning. I've had mine transitioned for some time now without issue.

https://support.google.com/googlenest/answer/9297676?p=migration-account-faq&visit_id=637190258466023369-1289653225&rd=1

vjooris commented 4 years ago

@zecanard , look to this issue, perhaps this can help you ?

zecanard commented 4 years ago

@vjooris I’d been hoping that issue would shed light on what’s happening, but as far as I can tell, all he did was reboot his machine? I’ve already done that a number of times, with no effect.

I took a closer look at what’s going on, and the weird thing is that my thermostat just no longer shows up under [structure] → [structureId] → [devices]. That array is simply empty. All other information in last_status is there, however. I’ll probably migrate to a Google login later today and see if that changes anything.

knappster1 commented 4 years ago

@zecanard that is correct, my issue was resolved with a reboot and my account was already migrated to google about 6 weeks ago, so it is likely unrelated. I think that google/nest are planning to require 2FA soon for Nest accounts which are not migrated to google, so it might become necessary to migrate then anyway. One positive consequence of migrating is that you shouldn't have to redo that workaround every couple weeks. I was somewhat apprehensive to migrate, but a family member was "tricked" into migrating the account to Google from the phone app at which point I no longer had a choice. I assume it is inevitable and Google will force all to be migrated eventually. I wouldn't even need this if they would have a supported method for updating humidity levels automatically...

zecanard commented 4 years ago

@knappster1 Thanks for the followup. I did find it odd that https://home.nest.com/session lists both: "2fa_state":"not_enrolled" and "2fa_enabled":true. I’m not sure if this was the case before my issues started. But yes, given that 2FA will become mandatory very soon, we don’t have a choice but to migrate to a Google login anyway if we want to keep using the API. I simply remembered reading your specific case at the time and decided not to migrate, but didn’t keep up with new issues/resolutions beyond that.

A moment ago I went to my thermostat to reboot it, and noticed a new option under Reset titled Reset WWN (Works With Nest) Connection.I might give this a try first, if for no other reason than sheer curiosity.

zecanard commented 4 years ago

Victory! Reset WWN Connection, followed by removing, then re-adding the thermostat to my home, fixed it. I’m back to accessing my thermostat at https://home.nest.com/thermostat/{serial_number} rather than https://home.nest.com/thermostat/DEVICE_{some_identifier_not_serial_number}, and it’s showing back up under my structure’s devices in last_status.

Re-adding my thermostat to the app was actually pretty annoying, with repeated “Nest Service unreachable” errors requiring multiple reboots of the thermostat. So unless you have a very good reason not to migrate to a Google login yet, it’s probably easiest to do so. But otherwise, this is the workaround to get everything back up and running once again.

(Also note that Google’s documentation does mention resetting WWN connections for Google logins; so it’s possible that Google is rolling out these changes in waves, and that you may need to follow these steps even with a Google login.)

Closing.

knappster1 commented 4 years ago

:+1: