gboudreau / nest-api

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

Temperature Sensor #102

Closed xetra27 closed 4 years ago

xetra27 commented 4 years ago

Hi, Thank you very much for the php script! It works very well. Would it be possible to add support for the Temperature Sensors? From what I could gather from JS scripts, they are listed under "kryptonite". I was not able to modify the php in order to find them but perhaps someone has an idea? Thank you very much.

bauzer714 commented 4 years ago

@gboudreau any chance you have a sensor?

@xetra27 are you able to provide a raw dump of the obtained data from Nest? Please scrub any personal details.

xetra27 commented 4 years ago

I have three sensors. How do I get a raw dump?

bauzer714 commented 4 years ago

In function "prepareForGet" add this prior to the function closing bracket. Copy and paste this into jsonlint.com and replace any personal information with test data. Save the data in a text file and email it to me (my git username at gmail)

die(json_encode($this->last_status));

xetra27 commented 4 years ago

@bauzer714 Thanks, that worked. Just sent you the email.

bauzer714 commented 4 years ago

PR submitted.

First is to update the location maps - this is not required for Nest Sensor support, but you did happen to use one that wasn't mapped. (https://github.com/gboudreau/nest-api/pull/103)

Second adds basic status support. https://github.com/gboudreau/nest-api/pull/104

Basic implementation

$sensor_status = array();
$device_sensors = $nest->getDevices(DEVICE_TYPE_SENSOR);

foreach ($device_sensors as $sensor)
{
    $sensor_status[] = $nest->getDeviceInfo($sensor);
}

echo json_encode($sensor_status);
bauzer714 commented 4 years ago

@xetra27 this has been merged. Can you confirm basic support is working. Next we should consider you changing the configured temperature sensor as primary so the Nest Thermostat payloads can be modified to indicate its temperature, but that it is deferring to a different device.

xetra27 commented 4 years ago

@bauzer714 Thanks. Basic support is working fine. I am able to find the sensors and get the data from them. How do I set a sensor as primary? I checked Nest settings, but it was not an option.

bauzer714 commented 4 years ago

Looks like you might need to use a schedule?

https://support.google.com/googlenest/answer/9260542?co=GENIE.Platform%3DAndroid&hl=en

xetra27 commented 4 years ago

@bauzer714 If I understand it correctly, it looks like everything is functioning as it should. My two thermostats and three sensors all show different temperatures. Looks like I am able to get the temperatures from the thermostats themselves, regardless of which sensor is actively controlling the thermostat. I am using a schedule for my sensors throughout the day.

Was that the issue, that you can't get the temperature from the thermostat once a sensor is active?

bauzer714 commented 4 years ago

I don't have issues. I'm thinking of a few use cases where you'd want to obtain the in use "current_temperature" of a thermostat (whether that is a sensor or itself). Since we're just now adding sensor functionality I figured this would be the next feature request.

xetra27 commented 4 years ago

Ok, got it. I use homebridge, and when asking Siri for the temperature, I always get the temperature of the active sensor, not the thermostat itself. (I always thought that was annoying in that specific case.) So however the nest homebridge plugin is coded should provide the solution.

I’ll also try to change a sensor and make it primary to go down that path.

bauzer714 commented 4 years ago

I don't necessarily want to override the thermostat, but make it more accessible. Theoretically anyway.

xetra27 commented 4 years ago

active_rcs_sensors seems to point to the active temperature sensor. In the file I sent you, one thermostat has a sensor selected, the other one does not.

bauzer714 commented 4 years ago

Thanks. I'm confused what multiroom means then. What do you think about this?

image

bauzer714 commented 4 years ago

One challenge is how these values affect the current_temperature returned in the thermostat object. This logic could get a bit complicated and I think it's up to the the consumer of the API to look at the thermostat -> current_status to see if it's deferring to an active sensor - if it is, go obtain the temperature of the remote sensor. This logic shouldn't necessarily replace the temperature.

@gboudreau - your thoughts? Right now the code fetches the values for the associated sensors and does the is active / has active logic. I could simply return the serials and let the consumer do any logic, any preference?

bauzer714 commented 4 years ago

https://github.com/bauzer714/nest-api/commit/ca717314c9242b7b39691dfb88dd41055da75655#diff-8ba2bd9f4c8b0b928c13b1aa3ecbce7b

xetra27 commented 4 years ago

I'm not sure about the multiroom. I did a search for it but couldn't find anything. My guess would be, it is for a future implementation of using multiple sensors at the same time.

I'm trying to have the thermostat look at the attached sensors and keep the temperatures in a bracket. Let's say the temps are 66, 70 and 71. I set my thermostat to 71 which makes the bracket e.g. 70-72. Now the heater should run until all values are above 70 or any exceed 72.

As far as the active sensor, perhaps create a variable called $active_temperature based on what sensor is the primary one. That number would match with the temperature that the thermostat is using to control the HVAC.

bauzer714 commented 4 years ago

I'm not sure I understand the bracket example, or how you'd dynamically activate one of the sensors with the Nest so it would start heating/cooling again to get the 66 room back up to 70 and IMO this is out of scope.

Adding the hvac_utilized_temperature could be created and calculated. Give me a few days.

xetra27 commented 4 years ago

The bracketing example was to ensure all rooms get heated without any room getting to hot, i.e. have a temperature bracket or range to be within. But I agree it would be difficult to implement that logic with the current infrastructure. Perhaps make the lowest temperature sensor automatically the active one (in a heating scenario). Or take an average of all sensor readings and make it the 'active' value.

Anyway, these are just thoughts of improving the usefulness of having multiple sensors.

bauzer714 commented 4 years ago

I don't disagree, but until Nest expands on the capabilities of the sensors (i.e. allowing you to switch at any time for any length of time) rather than the current scheduling - this could be a challenge for us to handle.

PR has been submitted. https://github.com/gboudreau/nest-api/pull/106

"temperature" has not been modified and will always reflect the active sensors. To help know what the actual device is I added backplate_temperature to know the true device. image

Here is all of the sensors responding in various ways image

bauzer714 commented 4 years ago

@xetra27 this has been merged for few days now, Can you confirm that we can close this?

xetra27 commented 4 years ago

@bauzer714 Yes, we can close this. Thanks for your help on this issue.