python-ring-doorbell icon indicating copy to clipboard operation
python-ring-doorbell copied to clipboard

Implement Live Snapshot and trigger Recording in HA integration

Open JoeDaddy7105 opened this issue 5 years ago • 4 comments

This is more for the HA integration. My python skills and HA knowledge are limited, I come from the .NET/C# realm. Willing to help put this together but not entirely certain where to begin.

Current snapshot service in HA appears to only grab the snapshot from the last recording. This function appears to trigger the doorbell/camera to take a live snapshot then download it which would be better. I want to trigger this to take a snapshot in an automation in HA when a door switch is opened. Should the existing snapshot service use this or should this be a new service/action? https://github.com/tchellomello/python-ring-doorbell/blob/b579e5e8ab3df05f5eeaa49712012850e3f7f405/ring_doorbell/doorbot.py#L376-L391

Also would be helpful to add this function in order to trigger recording with an automation. I am less interested in actually live streaming to something and more interested in just starting a new cloud recording. https://github.com/tchellomello/python-ring-doorbell/blob/b579e5e8ab3df05f5eeaa49712012850e3f7f405/ring_doorbell/doorbot.py#L274-L285

Should these be implemented as new Services (https://developers.home-assistant.io/docs/en/dev_101_services.html) in HA or should they be Actions (https://developers.home-assistant.io/docs/en/device_automation_action.html) since they may be better used in Automations?

JoeDaddy7105 avatar Jan 11 '20 20:01 JoeDaddy7105

I also want to be able to trigger a recording on demand. For example, I want a 60sec recording at noon every day, etc...

4Dolio avatar Jan 12 '20 02:01 4Dolio

Agreed on the snapshot, I noticed this and commented on it in another thread. Would happily contribute myself if I had ANY idea what the API call would need to look like. I've been playing around trying to find something that works, but with no success.

On the recording trigger. I have managed to create something that triggers a live stream, which records records for 30 seconds, the code waits for the video to be uploaded to Ring and then downloads it locally. When I have a bit more time I'll contribute my code. From what I can see there's a problem with the current code, the request to the LIVE STREAM ENDPOINT returns a 200 status code, the current code is looking for a 204, meaning it always returns false.

tzbailey avatar Jan 12 '20 21:01 tzbailey

Update on this. I've managed to get it to work by disabling the snapshot feature in the app (Code below). A word of warning though, if you're planning to couple this with Movement Detection, be prepared to wait, it seems like the snapshot will wait until the default 30 second recording of video on movement detection finishes before taking the snapshot, which doesn't really work for what I'm trying to do

def get_snapshot_custom(self, retries=10, delay=5): url = API_URI + SNAPSHOT_TIMESTAMP_ENDPOINT payload = {"doorbot_ids": [self._attrs.get("id")]} print(payload) request_time = time.time() self._ring.query(url, method="POST", json=payload).json() for _ in range(retries): time.sleep(delay) response = self._ring.query(url, method="POST", json=payload).json() print(request_time) print(response) if request_time - (response["timestamps"][0]["timestamp"] / 1000) < 10: print("SNAPSHOT TAKEN!") return self._ring.query(API_URI + SNAPSHOT_ENDPOINT.format(self._attrs.get("id")) ).content elif request_time - (response["timestamps"][0]["timestamp"] / 1000) < 604.8: print("Snapshot less than 10mins Old, exiting") return False return False

tzbailey avatar Jan 15 '20 15:01 tzbailey

I am actually wanting to use this to cut back my motion detection on the Ring camera so I can trigger recordings using other sensors. I also want to bake this into the Home Assistant integration or use a python script in HA to trigger the recordings and get a live snapshot since this appears to be already functioning in this library. I am having trouble figuring out how best to add this to the HA Ring integration though.

@balloob or @steve-gombos , you two seem to have had some involvement in this library as well as the Ring integration in HA. What is the best way to use get_snapshot and live_streaming_json from this library in HA in order to add these functions to HA automations?

Thanks!

JoeDaddy7105 avatar Mar 22 '20 16:03 JoeDaddy7105

There hasn't been any activity on this issue recently. This issue has been automatically marked as stale because of that. It will be closed if no further activity occurs. Please make sure to update to the latest ring_doorbell version and check if that solves the issue. Thank you for your contributions.

github-actions[bot] avatar Apr 18 '24 18:04 github-actions[bot]