Is there any chance this integration can be done using Delivery Type Push? I have a few cameras and I see an API call every 5 seconds for every camera, it’s overkilling to make that many API calls when most of the time there is no event coming back (very small percentage). And a bigger problem is that events take a long time, let’s say I want to turn on a light when motion is detected, it takes 5 seconds for the light to turn on. If the implementation uses Push the event would be sent right away and it would save a lot of processing and bandwidth.
@JotaDe The pubsub subscriber has 1 outstanding RPC, and the nest integration definitely does not do any sort of polling, I would like to understand more about the API calls you see every 5 seconds for every camera. Can you explain more about what you’re seeing that leads you to this conclusion?
To answer your question, no it only supports pull as (1) pull is actually higher throughput and better for low latency (2) push requires an external endpoint to be exposed on the internet. I don’t think this is actually a solution to the problem you’re seeing, and it should be very low latency. From the cloud pubsub docs In general, asynchronous pull is preferable for latency-sensitive applications.
The Data I see in my cloud console for APIs is 0.02 queries per second for the SDM API and i have 3 cameras and 2 thermostats. I see 0.19 queries per second for cloud console which matches my understanding of what happens with one pubsub pull request rpc every 10 seconds for the long running streaming RPC.
Happy to help understand in more detail what you’re seeing. The nest integration instructions have suggestions for how to view the contents of your pubsub feed if you want to narrow down how long it takes for google to publish the messages. For what its worth, i also see a few seconds delay for person detection before turning a light on in an automation, though I haven’t diagnosed why in detail and attributed it to cloud to local latency.
@allenporter I will send the log later with debug enabled. It may not be 5 seconds per camera but it looked like it’s polling every 5 seconds, perhaps for all devices.
There are only two ways of knowing if an event occurred, either google nest tells me, in which case obviously I need to provide an endpoint; or I ask google nest. It cannot be 0.02 queries per second because that would be about a query per minute which means if let’s say there was a motion detected event I will not know until one minute after.
Or I may be confused and I can actually make an API call every minute or so and let’s say there has not been any event then maybe the API call does not come back right away but instead waits for an event to occur in the next minute or so and then it responds right away, only then I make another call to wait for the next event, or when the previous call times out with no events. If that is the behavior then polling should be fine.
Hi, as I just said there is absolutely no polling for devices every N seconds. Just to confirm are wee talking about Nest - Home Assistant or something else?
There are videos on the cloud pubsub developer site if you want to learn more about how cloud pubsub works. It is not traditional polling: it’s a long running streaming rpc that leaves a connection open and the server streams back new information as soon as it arrives.
Definitely no polling per device, no API calls every 5 seconds, and what you described does not match the code. Again happy to talk through details via log messages of you have them. The integration troubleshooting steps have instructions for turning on debug which can show you rpcs send (via the nest auth library) or pubsub events as they are streamed from the server in a low latency pull, and timestamps for events from the server side.
Already tried and no extra info at all on HA log.
logger:
default: warn
logs:
homeassistant.helpers.config_entry_oauth2_flow: debug
Yes, the oauth consent page is set to production.
Odd, this line of code is what you’re trying to enable:
https://github.com/home-assistant/core/blob/cef34356e2a66c1a51324c8b095183316b612ad4/homeassistant/helpers/config_entry_oauth2_flow.py#L200 which we’ve used in other cases to debug this. May need to restart home assistant of course.
Below are some lines from the log in Debug mode, I think my confusion was that I saw a lot of activity when there were no events with the cameras. It seemed like a lot of calls but looking with more detail I see a heartbeat every 30 seconds and the other entries don’t look like api calls.
2021-10-14 21:14:35 DEBUG (MainThread) [google_nest_sdm.device] Processing update 9a9d8b01-5183-4a4a-9747-562c1fd6aae3 @ 2021-10-15 04:14:17.071000+00:00
2021-10-14 21:14:35 DEBUG (MainThread) [google_nest_sdm.device] Event Update dict_keys(['sdm.devices.events.CameraMotion.Motion'])
2021-10-14 21:14:35 DEBUG (MainThread) [homeassistant.components.nest] Event Update dict_keys(['sdm.devices.events.CameraMotion.Motion'])
2021-10-14 21:14:35 DEBUG (Thread-CallbackRequestDispatcher) [google.cloud.pubsub_v1.subscriber._protocol.dispatcher] Handling 1 batched requests
2021-10-14 21:14:35 DEBUG (Thread-CallbackRequestDispatcher) [google.cloud.pubsub_v1.subscriber._protocol.streaming_pull_manager] Sent request(s) over unary RPC.
2021-10-14 21:14:37 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:14:37 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 6.721073 seconds.
2021-10-14 21:14:44 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:14:44 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 5.467702 seconds.
2021-10-14 21:14:49 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:14:49 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 6.302273 seconds.
2021-10-14 21:14:55 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:14:55 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 4.986255 seconds.
2021-10-14 21:14:56 DEBUG (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Sent heartbeat.
2021-10-14 21:15:00 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:00 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 8.305379 seconds.
2021-10-14 21:15:09 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:09 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 4.455787 seconds.
2021-10-14 21:15:13 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:13 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 0.015209 seconds.
2021-10-14 21:15:13 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:13 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 1.232797 seconds.
2021-10-14 21:15:14 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:14 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 5.628826 seconds.
2021-10-14 21:15:20 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:20 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 7.012166 seconds.
2021-10-14 21:15:26 DEBUG (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Sent heartbeat.
2021-10-14 21:15:27 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:27 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 3.811466 seconds.
2021-10-14 21:15:31 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:31 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 1.290698 seconds.
2021-10-14 21:15:32 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:32 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 5.349482 seconds.
2021-10-14 21:15:38 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:38 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 4.598726 seconds.
2021-10-14 21:15:42 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:42 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 6.623127 seconds.
2021-10-14 21:15:44 DEBUG (MainThread) [homeassistant.components.nest.camera_sdm] Extending stream url
2021-10-14 21:15:44 DEBUG (MainThread) [google_nest_sdm.auth] request[post]=https://smartdevicemanagement.googleapis.com/v1/enterprises/e9d343b5-ad41-4041-8db0-abb8d2eebc22/devices/AVPHwEuLJW2P86e3OIUVdtVAMJhLbSfuBr4ItjpUScqaFAzYYOztWuDYsTqlB4MwnHk2XabRgxgXvkQT-gcAYCImFvBO5A:executeCommand
2021-10-14 21:15:45 DEBUG (MainThread) [homeassistant.components.nest.camera_sdm] New stream url expires at 2021-10-15 04:20:44.640000+00:00
2021-10-14 21:15:49 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:49 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 3.046632 seconds.
2021-10-14 21:15:52 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:52 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 6.695098 seconds.
2021-10-14 21:15:56 DEBUG (Thread-Heartbeater) [google.cloud.pubsub_v1.subscriber._protocol.heartbeater] Sent heartbeat.
2021-10-14 21:15:58 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:58 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 0.935788 seconds.
2021-10-14 21:15:59 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:15:59 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 5.653950 seconds.
2021-10-14 21:16:05 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] The current deadline value is 10 seconds.
2021-10-14 21:16:05 DEBUG (Thread-LeaseMaintainer) [google.cloud.pubsub_v1.subscriber._protocol.leaser] Snoozing lease management for 4.109408 seconds.
Great, glad everything is working.
Are you all using This to connect your nests?
Are any of these steps not necessary if I’ve already connected Google to my HomeAssistant (non nabucasa)?
@allenporter Hi, I reported this several months back and you said that this was a frontend issue, but honestly, it’s just your integration… please see this issue I raised:
See below, on the left is the temp from the Nest 3rd gen Thermostat, on the right temp from Philips Hue multisensor:
It’s obviously silly, right? Nobody in the world uses 5 decimal points to measure temperature in a consumer device… this is not a lab… can you please change the sensor to round to 1 decimal point only please, because that’s what every other temperature integration does on HA so I find it a little extreme to be told that it’s a frontend issue when for months and months only your integration has this weird behavior.
Thank you for what you’ve done for all of us so far by the way.
I am quite sure all the steps are necessary to connect HA to Google-Nest.
Hi, See https://github.com/home-assistant/core/issues/55496 and https://github.com/home-assistant/architecture/discussions/636 and https://github.com/home-assistant/core/pull/56993 (in progress fix).
To be clear: Home assistant nest
integration just returns what the Google Nest SDM API sends back. My stance was that we should fix this systematically in all integrations – or fixed at the source so nest api shouldn’t return this – rather than adding rounding in the integration. There was a proposal to address this for all integrations which I support, but it may not be solved super fast. So, i’m going to cave on my position and let in a fix to the integration as I realize end users just want this fixed and don’t care how it happens. Someone has submitted a pull request with a fix, but has not yet addressed the feedback yet. I just ping’d the PR spelling out more clearly the gaps before it can be merged.
You are SO lovable! Honestly, I support your position, but yep, I think until they fix it, due to the huge popularity of your integration, putting in a fix at your end is going to delight a lot of people. I know it’s a ridiculously simple thing on the grand scheme of things but every time I look at it, I cringe so hard, I know I’m not the only one. This is one of those small things that make a difference to someone’s day. Imagine cringing every time you start your day by looking at the dashboard and seeing that weird temp… Really appreciate how fast you are at responding, too. You are probably the nicest developer I’ve come across online.
I templated the temperature sensor with rounding of my choice.
I chose nearest .5 to match the Nest Thermostat display.
I am as well. But what I want to know is if I have already connected my HA to Google so I can use Google Assistant to control devices, are any of these steps already done?
No shortcuts there. The two integrations are pushing information very different ways and the access to the nest devices is totally separate.
That integration does not make Google devices appear in HA. The Google API access is completely the reverse of the above. The same is true for Amazon Alexa where we have two integrations, one so we can have Alexa control HA devices and another so HA has access to Alexa devices, each with their own separate configuration & authentication schemes.
Hi folks,
A couple quick updates on the nest integration project:
- The next home assistant release will contain very basic support for nest battery cam streams. It only seems to work in Chrome however. Stay tuned.
- Building better ways of showing recent camera events, images and clips (for battery cams). This is a work in progress.
- I am revampong setup steps to reduce complex steps such as redirect urls by using a different authentication. Also looking to automate the pubsub subscriber setup, and working with HA core devs on a plan to get out of configuration.ysml though it’s tricky. This may take some time to finish but just wanted to mention it.
Thanks!
Thank you Allen!!!