roleoroleo / yi-hack_ha_integration

Home Assistant custom integration for Yi cameras: yi-hack-MStar, yi-hack-Allwinner, yi-hack-Allwinner-v2, yi-hack-v5 and sonoff-hack
GNU General Public License v3.0
205 stars 32 forks source link

Yi Dome U Pro privacy mode/turning off the camera #67

Closed pannal closed 2 months ago

pannal commented 2 years ago

Hey,

Thank you for the hack and the integration. I'm using the Yi Dome U Pro.

I'd like to turn on the privacy mode ("face-down" and off) using HA - how does that work?

I've tried camera.turn_off, which seems to kill the stream itself resulting in the image not to show anymore and these log entries:

2021-12-28 18:37:45 ERROR (SyncWorker_9) [custom_components.yi_hack.camera] Fetch snapshot image failed from yi_hack_a2_a82d67_cam, falling back to FFmpeg; HTTPConnectionPool(host='yicam_1', port=8080): Max retries exceeded with url: /cgi-bin/snapshot.sh?res=high&watermark=yes (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f5415077940>: Failed to establish a new connection: [Errno 113] Host is unreachable'))
2021-12-28 18:37:48 ERROR (SyncWorker_9) [custom_components.yi_hack.camera] Error getting stream link from yi_hack_a2_a82d67_cam: HTTPConnectionPool(host='yicam_1', port=8080): Max retries exceeded with url: /cgi-bin/links.sh (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f541507cc70>: Failed to establish a new connection: [Errno 113] Host is unreachable'))

Using camera.turn_on doesn't work afterwards, with this error:

2021-12-28 18:39:32 ERROR (MainThread) [homeassistant.helpers.script.websocket_api_script] websocket_api script: Error executing script. Unexpected error for call_service at pos 1: set_power_off_in_progress() missing 1 required positional argument: 'device_name'
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 555, in async_turn_on
await self.hass.async_add_executor_job(self.turn_on)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/yi_hack/camera.py", line 159, in turn_on
set_power_off_in_progress(self.hass)
TypeError: set_power_off_in_progress() missing 1 required positional argument: 'device_name'
2021-12-28 18:39:32 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [139999106636672] Error handling message: Unknown error
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 27, in _handle_async_response
await func(hass, connection, msg)
File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 527, in handle_execute_script
await script_obj.async_run(msg.get("variables"), context=context)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1260, in async_run
await asyncio.shield(run.async_run())
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 363, in async_run
await self._async_step(log_exceptions=False)
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 381, in _async_step
await getattr(self, handler)()
File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 584, in _async_call_service_step
await service_task
File "/usr/src/homeassistant/homeassistant/core.py", line 1495, in async_call
task.result()
File "/usr/src/homeassistant/homeassistant/core.py", line 1530, in _execute_service
await handler.job.target(service_call)
File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 209, in handle_service
await self.hass.helpers.service.entity_service_call(
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 663, in entity_service_call
future.result() # pop exception if have
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 896, in async_request_call
await coro
File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 700, in _handle_entity_call
await result
File "/usr/src/homeassistant/homeassistant/components/camera/__init__.py", line 555, in async_turn_on
await self.hass.async_add_executor_job(self.turn_on)
File "/usr/local/lib/python3.9/concurrent/futures/thread.py", line 52, in run
result = self.fn(*self.args, **self.kwargs)
File "/config/custom_components/yi_hack/camera.py", line 159, in turn_on
set_power_off_in_progress(self.hass)
TypeError: set_power_off_in_progress() missing 1 required positional argument: 'device_name'

Should I use a saved PTZ position and switch.yi_cam_1_privacy to achieve this?

Thank you!

pannal commented 2 years ago

When using "turn camera on/off" in the Yi app, the camera automatically moves its "head" down into the "lens isn't visible anymore"-position. I'd like to be able to do that using HA.

roleoroleo commented 2 years ago

The 1st error is normal. I don't know how to tell to ha that the cam is disable. I could try to catch the error. The 2nd error should be fixed here: https://github.com/roleoroleo/yi-hack_ha_integration/commit/6d45b9a2e38c3434da9b83aff372c9ca7a431756

About the "turn camera on/off" in the Yi app, I'm not able to implement it. But the privacy is ok: rtsp and snapshots are switched off.

Yes, you could try to use ptz service to move the head into a preset position.

roleoroleo commented 2 years ago

The 1st error is normal. I don't know how to tell to ha that the cam is disable. I could try to catch the error.

I checked this error. Is not normal but it doesn't depend on the component. It's a "simple" connection error, probably a temporary wifi issue. Because it's related to a http request to which the cam must always respond.

pannal commented 2 years ago

Thank you. Is there a way to move to a predefined PTZ preset using the HA integration? The webinterface of the Yi Hack camera has this functionality.

Edit: The webinterface uses /cgi-bin/preset.sh?num=X for this

roleoroleo commented 2 years ago

Check ptz service.

pannal commented 2 years ago

Yes but PTZ service only allows me to PTZ, not to activate presets, as far as I can see. Am I missing something?

roleoroleo commented 2 years ago

You are right. At the moment you can't use presets with ha.

man-ebc commented 1 year ago

Hi @pannal!

I am at the same boat. Could you be able to face down the U pro? And able to move 360º from HA?

Best!

ianfromnyc commented 1 year ago

When I turn the camera off from the camera settings page in the Web UI, the head tilts face down and the camera stops streaming, but when I switch on privacy mode from HA nothing happens. Can the HA privacy switch toggle the "camera on/off" setting from the Camera Settings page in the Web UI?

github-actions[bot] commented 3 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.