STUMPED! Onvif - PTZ service call - Errors!

Hello.
I’ve integrated an onvif camera. Image works well!
After writing this script:

ptz_tilt_up:
  sequence:
    - service: camera.onvif_ptz
      entity_id: 'camera.onvif'
      data:
        tilt: 'UP'
ptz_tilt_down:
  sequence:
    - service: camera.onvif_ptz
      entity_id: 'camera.onvif'
      data:
        tilt: 'DOWN'
ptz_pan_left:
  sequence:
    - service: camera.onvif_ptz
      entity_id: 'camera.onvif'
      data:
        pan: 'LEFT'
ptz_pan_right:
  sequence:
    - service: camera.onvif_ptz
      entity_id: 'camera.onvif'
      data:
        pan: 'RIGHT'
ptz_zoom_in:
  sequence:
    - service: camera.onvif_ptz
      entity_id: 'camera.onvif'
      data:
        zoom: 'ZOOM_IN'
ptz_zoom_out:
  sequence:
    - service: camera.onvif_ptz
      entity_id: 'camera.onvif'
      data:
        zoom: 'ZOOM_OUT'

when calling the script I get this error:

Error executing service <ServiceCall script.ptz_tilt_down (c:f7ce3c0440f14f45a295ecc64937e622)>
Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1150, in _safe_execute
await self._execute_service(handler, service_call)
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1163, in _execute_service
await handler.func(service_call)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 114, in service_handler
context=service.context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 172, in async_turn_on
kwargs.get(ATTR_VARIABLES), context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 131, in async_run
await self._handle_action(action, variables, context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 210, in _handle_action
action, variables, context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 299, in _async_call_service
context=context
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 89, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1141, in async_call
self._execute_service(handler, service_call))
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1163, in execute_service
await handler.func(service_call)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/onvif/camera.py”, line 84, in async_handle_ptz
entity_ids = extract_entity_ids(hass, service)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 99, in extract_entity_ids
async_extract_entity_ids(hass, service_call, expand_group), hass.loop
File "/usr/local/lib/python3.7/site-packages/homeassistant/util/async
.py", line 138, in run_coroutine_threadsafe
raise RuntimeError(‘Cannot be called from within the event loop’)
RuntimeError: Cannot be called from within the event loop

Any ideas?

cheers

It would be great to indicate what camera you’re using.
Have a read

https://www.amazon.co.uk/PTZ-POE-Dome-Camera-Surveillance/dp/B07HQBD2BM/ref=mp_s_a_1_6?keywords=camera+dome+5mp&qid=1558872588&s=gateway&sr=8-6

Will take a look at your link. Thank you!

CGI commands work for my camera so it might help you too.
and if you modify your script according to the second link, it should do the job.
don’t know how the camera.onvif_ptz suppose to work though, but I’m my case it says “PTZ is not supported” in HA log despite the camera being fully controllable via various apps/its web fronted.

Unfortunately. Those CGI commands didnt work for this device.

I’ve uploaded some screenshots of the TideTech Camera web interface. Which basically looks like a generic camera companies buy to logo up and sell!

There are options in the PTZ settings to change the type of PTZ communication. I’m hoping these shots may help someone point me in the right direction to get HASSIO to work it. The camera is set on Palco-D to work with the apps I’m using so far.



100% has nothing to do with that camera. I have a Foscam camera and it has ONVIF. I altered the script to that entity and it does the same.

As stated in the HA manual

If you remove any entity reference then the “camera.onvif_ptz” service will target all.

Targeting entities FOSCAM and The ONVIF CAM or none at all give the original error message.

Failed to call service camera/onvif_ptz. Cannot be called from within the event loop

Traceback (most recent call last):
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/websocket_api/commands.py”, line 121, in handle_call_service
connection.context(msg))
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1141, in async_call
self._execute_service(handler, service_call))
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1163, in _execute_service
await handler.func(service_call)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 114, in service_handler
context=service.context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/components/script/init.py”, line 172, in async_turn_on
kwargs.get(ATTR_VARIABLES), context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 131, in async_run
await self._handle_action(action, variables, context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 210, in _handle_action
action, variables, context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/script.py”, line 299, in _async_call_service
context=context
File “/usr/local/lib/python3.7/site-packages/homeassistant/helpers/service.py”, line 89, in async_call_from_config
domain, service_name, service_data, blocking=blocking, context=context)
File “/usr/local/lib/python3.7/site-packages/homeassistant/core.py”, line 1141, in async_call

Not quite sure how to go forward. Anyone got any ideas?

1 Like

open a new issue on GitHub?

1 Like

Thats an idea mate. But I think I’ll just keep using an app to move the PTZ.

Also looking at flashing another system (on the side) with one of the other open source systems like OpenHab to see whats achievable on them. I’m finding quite a few un-solveable glitches on HASSIO.

yeah, that’s always down to the balance of pros and cons…

I’m having the same problem.
Looks like it has something to do with async calls.

HELLO to all
anyone has made this work?
thanks

Nope! TBH it sounds like they should really un-publish the feature…

i get this error:
Falha ao chamar o serviço camera/onvif_ptz . Cannot be called from within the event loop

1 Like

Same here.
Any news ?

I have FOSCAM FI9928P ONVIF PTZ Camera and get the same results… “Cannot be called from within the event loop”. I am able to PTZ with “ONVIF Device Manager”.

Has anyone made progress on this?

I think full onvif support is one of the key feature that lacks to HA…
Onvifer and onvif manager easily rotate my cameras…

But HA…

My ONVIF camera PTZ does not work. I am not a HA Python coder. Can someone answer why this directory/file does not exist in HA… and should it? It appears wsdl is the method for accessing PTZ service.

/usr/local/lib/python3.7/site-packages/onvif/wsdl/

This is the file being fetched around line 148 in ONVIF/camera.py:

"{}/wsdl/".format(os.path.dirname(onvif.__file__)),

I am using HA 0.92.2. I am trying to understand the code in order to fix it.

1 Like