Disable/Enable Nest Camera Recording

New HA user. I’ve got the basic nest camera image on my states dashboard, but id like to be able to create triggers which enable or disable recording. Is this possible, and how can I do this?

1 Like

I’m also pretty new to HA, but from browsing the code a bit, it looks like the basic camera component does not provide a service to disable/enable recording and/or streaming (i.e., to change the state.) It returns the state as idle, streaming or recording, but has no provisions to change it. It would really be nice to have this feature.

FWIW, the basic Nest python integration already has the functionality to disable/enable recording (i.e., via the is_streaming.setter.) And the nice part of this is, when disabling/enabling recording via this method, the cache of the current settings (from the Nest Cloud API) will be cleared so the next poll will see the change of state. (Otherwise it could be up to 5 minutes before HA will be aware that the camera state has changed!)

What appears to be necessary is for components/camera/nest.py to add a method to the NestCamera class to set the recording state via a statement like self.device.is_streaming = true/false. It’s the layers above that that I’m a little foggy about.

FWIW, I was able to add a shell_command to change the is_streaming state directly to the Nest Cloud API (using a curl command), but as I alluded to above, HA doesn’t see that change for up to 5 minutes (because the base Nest class in components/nest.py maintains a cache of the last query from the Nest Cloud API by default for 270 seconds, or 4.5 minutes, and then the default polling in HA can add up to another 30 seconds to that.)

Anyway, since it’s been 9 months since you posted this, I was wondering what you did or if you know of some change to this situation that has happened in the meantime. I tried to search Feature Requests, but didn’t see anyone asking for the ability to change the state of Camera devices via a service call and for the Nest integration to implement it.

So I went ahead and added this feature in my local copies. I changed the following files:

homeassistant/components/camera/__init__.py
homeassistant/components/camera/nest.py
homeassistant/components/camera/services.yaml
nest/nest.py

I modeled it after the set_operation_mode service in climate. So now there is a camera.set_operation_mode service that accepts an operation_mode parameter with the value of idle, streaming or recording. For Nest, idle sets is_streaming to False, and streaming or recording sets is_streaming to True.

I also changed nest/nest.py since although it does “bust the cache” when something is changed so that the next poll will grab fresh data from the Nest Cloud API, it turns out that happens too quickly. I.e., when the HA service is called, and is_streaming is changed, HA will pretty much immediately cause the camera state to update which causes an immediate poll which causes an immediate pull of new data from the Nest Cloud API. Unfortunately, the data in the Nest Cloud API doesn’t change that quickly. So I effectively added a 5 second delay before the cached data is “busted.” This causes the immediate poll to still use the cached data, and the NEXT poll to retrieve new data from the Nest Cloud API. Seems to work, although obviously not sure what the delay needs to be in all cases. But this may not be needed if someone does eventually update the basic Nest python integration to use REST Streaming, which seems like it might happen soon-ish. :slight_smile:

In any case, if anyone is interested in the details of my changes, just let me know. I’m not (yet) set up to put changes into github, etc., so I can simply provide copies of my modified files if anyone wants to give this a try, or better yet, try to make it “official”. :slight_smile:

1 Like

See also: