user2684 / imou_life

Home Assistant custom component for controlling Imou devices
MIT License
115 stars 18 forks source link

Service "imou_life.ptz_location" doesn't work on Cruiser 2 PTZ camera #92

Open atiburzi opened 7 months ago

atiburzi commented 7 months ago

error_log.txt

Version of the custom_component

HA Imou Life Custom Component version: 1.0.15

Version of the hardware (camera)

Device Info: IPC-GS7E-5M0WE (Imou Cruiser 2 camera)

Describe the bug

"imou_life.ptz_location" service doesn't work while I am successfully able to run the service "imou_life.ptz_move" (running them from developer tools in HA)

Here the service call script that fails (returning message: Unknown error):

service: imou_life.ptz_location
target:
  entity_id: camera.cruiser_2_01_camera
data:
  horizontal: 0
  vertical: 0

The device is NOT shared from an imou account different than the one the device is connected to.

In attachment, the error_log file generated with the diagnostics.

Debug log

Logger: homeassistant.helpers.script.websocket_api_script Source: helpers/script.py:468 First occurred: 09:29:54 (1 occurrences) Last logged: 09:29:54

Logger: homeassistant.components.websocket_api.http.connection Source: custom_components/imou_life/camera.py:117 Integration: Home Assistant WebSocket API (documentation, issues) First occurred: 01:22:15 (1 occurrences) Last logged: 01:22:15

[139818720309184] Error handling message: Unknown error (unknown_error) Andrea from 95.235.80.97 (Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/decorators.py", line 26, in _handle_async_response
    await func(hass, connection, msg)
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 782, in handle_execute_script
    script_result = await script_obj.async_run(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 1587, in async_run
    return await asyncio.shield(run.async_run())
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 426, in async_run
    await self._async_step(log_exceptions=False)
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 479, in _async_step
    self._handle_exception(
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 502, in _handle_exception
    raise exception
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 713, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 675, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 831, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/imou_life/camera.py", line 117, in async_service_ptz_location
    await self.sensor_instance.async_service_ptz_location(
  File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 703, in async_service_ptz_location
    return await self.api_client.async_api_controlLocationPTZ(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 520, in async_api_controlLocationPTZ
    return await self._async_call_api(api, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 227, in _async_call_api
    raise APIError(error_message)
imouapi.exceptions.APIError: 40999: Unknown error.
Logger: homeassistant.helpers.script.websocket_api_script
Source: helpers/script.py:476
First occurred: 01:22:15 (1 occurrences)
Last logged: 01:22:15

websocket_api script: Error executing script. Unexpected error for call_service at pos 1: 40999: Unknown error.
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 476, in _async_step
    await getattr(self, handler)()
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 713, in _async_call_service_step
    response_data = await self._async_run_long_action(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/script.py", line 675, in _async_run_long_action
    return long_task.result()
           ^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2149, in async_call
    response_data = await coro
                    ^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/core.py", line 2186, in _execute_service
    return await target(service_call)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 831, in handle_service
    return await service.entity_service_call(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 882, in entity_service_call
    single_response = await _handle_entity_call(
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 952, in _handle_entity_call
    result = await task
             ^^^^^^^^^^
  File "/config/custom_components/imou_life/camera.py", line 117, in async_service_ptz_location
    await self.sensor_instance.async_service_ptz_location(
  File "/usr/local/lib/python3.11/site-packages/imouapi/device_entity.py", line 703, in async_service_ptz_location
    return await self.api_client.async_api_controlLocationPTZ(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 520, in async_api_controlLocationPTZ
    return await self._async_call_api(api, payload)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/imouapi/api.py", line 227, in _async_call_api
    raise APIError(error_message)
imouapi.exceptions.APIError: 40999: Unknown error.
user2684 commented 7 months ago

Hi, thanks for all the detailed information. Looks like an error coming from the Imou API when called, and of course 40999: Unknown error is not very meaningful :-/ I have no way to reproduce it or to test to call the api with different parameters, hence if any other user has experienced the same, please let me know so we can try to understand with there is in common with what you are facing. Thanks!

atiburzi commented 7 months ago

Hi, fully understand, just to report here another case with a similar Camera: https://community.home-assistant.io/t/imou-life-cloud-integration/462439/191

tobiradi commented 4 months ago

I have absolutly the same Problem !

Cheerpipe commented 1 month ago

Hi.

I get locations working using the HA onvif integration with this service call:

service: onvif.ptz target: entity_id: camera.salon_profile000 data: preset: 2 move_mode: GotoPreset distance: 1 speed: 0.5 continuous_duration: 0.5

Where "2" is the number of a preset created using SmartPPS (it is the preset ID)

user2684 commented 1 month ago

Using the onvif integration as a workaround sounds like a good approach to me