nest-api icon indicating copy to clipboard operation
nest-api copied to clipboard

Two thermostats

Open dtolone opened this issue 4 years ago • 8 comments

I have two thermostats attached to my account. How can I select which one I want to read from?

Thank you

dtolone avatar Jan 14 '20 18:01 dtolone

You can use the $nest->getDevices() method to get a list of devices. Then, each getter or setting method can take an optional serial number in parameter, to work with a specific device. eg. $next-> getDeviceInfo($serial_number)

gboudreau avatar Jan 27 '20 16:01 gboudreau

I have been running multiple thermostats for 3+ years....and yesterday at 7pm the sort order of returned devices ($nest->getDevices()) changed????

So I had to go back into my code and explicitly set the serial_numbers.....instead of using $devices_serials[0] / $devices_serials[1].

not a big deal.....but a very odd random change

cagivacode avatar Jan 28 '20 17:01 cagivacode

@cagivacode - there is no sorting applied to the getDevices method. Not sure what your code looks like but if you can provide it I could give you some code that might be a bit more versatile. Alternatively, I could probably write a function that sorts it by their "where" location.

 foreach ($this->last_status->user->{$this->userid}->structures as $structure) {
            list(, $structure_id) = explode('.', $structure);
            foreach ($this->last_status->structure->{$structure_id}->devices as $device) {
                list(, $device_serial) = explode('.', $device);
                $devices_serials[] = $device_serial;
            }
        }

bauzer714 avatar Jan 28 '20 18:01 bauzer714

I have it sorted just fine now.....but my original code just used $devices_serials[0] / $devices_serials[1] / $devices_serials[3].

I have 3 zones in one structure.

and they always came back in the same order (for 3+ years).....then last night they came back in a completely different order.

I was just pointing out that not explicitly managing the serials (one way or another) is no longer dependable in a multi thermostat setup.

cagivacode avatar Jan 28 '20 18:01 cagivacode

Hey all, I also have 2 Devices connected with my google account. When I list the devices using: $nest->getDevices() I can only get the values of my first Thermostat. The second is not shown. Online on "https://home.nest.com/" both thermostats are shown.

Any Idea? hmmm

SpaceMag avatar Mar 17 '20 15:03 SpaceMag

Sounds like this is an error in your implementation rather than the library. Assuming they are at the same structure you can use the below to confirm both are being returned.

var_dump($nest->getDevices());

bauzer714 avatar Mar 17 '20 23:03 bauzer714

Okay, with this command I get a list of my two devices. So they exist! Great, thanks! Now I need to find out how the get the values from the second Devices in my request :-)

But thanks already, this helped!

SpaceMag avatar Mar 21 '20 11:03 SpaceMag

When you have more than one device, include the serial number you see in getDevices to the function you're using. Look at the function definition and it will tell you more information.

bauzer714 avatar Mar 21 '20 12:03 bauzer714