gboudreau / nest-api

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

Two thermostats #111

Open dtolone opened 4 years ago

dtolone commented 4 years ago

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

Thank you

gboudreau commented 4 years ago

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)

cagivacode commented 4 years ago

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

bauzer714 commented 4 years ago

@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;
            }
        }
cagivacode commented 4 years ago

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.

SpaceMag commented 4 years ago

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

bauzer714 commented 4 years ago

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());

SpaceMag commented 4 years ago

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!

bauzer714 commented 4 years ago

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.