Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to recieve notification about target temp changes? #128

Open
romanstyler opened this issue Jun 16, 2020 · 7 comments
Open
Labels

Comments

@romanstyler
Copy link

Hi, I want to start some scene in smart home when user changes target temp.
Could you help, does your library allow to detect this moment. Probably some pooling functionality.

As I can see on official web interfate target temperature immediately changes when I spit nest ring.

@gboudreau
Copy link
Owner

Website probably uses some kind of polling, where the web browser initiates a HTTP request, and the server only answers that after the value requested changes, or a timeout occurs, at which point the browser re-initiate the same HTTP request.
The API we use don't support pushing I'd say.

You can simply create a script that checks for the target temp, saves it in a file locally, and schedule that script to run every 5 or 10 minutes. Once the value obtained from the API is different from the one in the file, do whatever you want to trigger, then write the new value in the file.

@romanstyler
Copy link
Author

Thank you for quick support!
I want to integrate Nest thermostat into Fibaro Smart Home system. Idea: on every change of target temperature -> set this temperature to air conditioner.
I quess Google can block me, of I request configuration too often.

This library somehow can react very fast, but this related to only HomeKit users:
https://github.com/chrisjshull/homebridge-nest

Anyway thank you for information, I will continue my investigation.

@bauzer714
Copy link
Contributor

As a data point my scripts run every 5 minutes for several years without being blocked.

It should be noted that you are not guaranteed realtime thermostat data with each script execution. The script can only acquire the latest data nest has. My thermostat provides routine updates ranging 6-13 minutes apart.

@romanstyler
Copy link
Author

Thank you.
Just checked Network log from Chrome. As I can see, there are subscribe requests.
Looks like, this is long pooling.
image

I will try to investigate it.

@romanstyler
Copy link
Author

Probably I found solution.
Thanks to method from your code:
` public function getEnergyLatest($serial_number = NULL) {
$serial_number = $this->getDefaultSerial($serial_number);

    $payload = array(
        'objects' => array(
            array('object_key' => "energy_latest.$serial_number")
        )
    );

    $url = '/v5/subscribe';

    return $this->doPOST($url, json_encode($payload));
}`

This allows to subscribe and load latest energy report. I used this code as example.
But if I subscribe to "shared" topic like this:

$payload = array( 'objects' => array( array('object_key' => "shared.$serial_number", 'object_timestamp' => 1592332412183, 'object_revision' => 19605) ) );

This request will return latest changes of target temperature and also revision and timestamp variables.
Every time I need to pass these variables into request and response will provided only when data is changed. It works almost immediately on target value change.

@kueblc
Copy link

kueblc commented Jun 16, 2020

You may find wiredprairie/unofficial_nodejs_nest useful, as it implements long polling subscription

@romanstyler
Copy link
Author

Thank you very much! But as I can see this library uses nest account. But in my case it's Google Account.
Finally, I implemented new method which allows to poll needed data.
Current version allows to monitor target temperature and on change control air conditioner via IR command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants