ONVIF camera

I have exactly the same issue as donnib.
Hass tries to install http://github.com/tgaugry/suds-passworddigest-py3/archive/86fc50e39b4d2b8997481967d6a7fe1c57118999.zip#suds-passworddigest-py3==0.1.2a
but not in time for the onvif platform setup.

Thanks for narrowing the issue I’ll take a look and check the dependancies.
Does it install it at all?

I cleaned out all locations containing python packages but it still won’t install properly. Or at least it tries to install suds-passworddigest-py3 at every reboot.

2017-07-18 17:51:47 INFO (Thread-8) [homeassistant.util.package] Attempting install of onvif-py3==0.1.3
2017-07-18 17:51:50 INFO (Thread-7) [homeassistant.util.package] Attempting install of http://github.com/tgaugry/suds-passworddigest-py3/archive/86fc50e39b4d2b8997481967d6a7fe1c57118999.zip#suds-passworddigest-py3==0.1.2a
2017-07-18 17:51:56 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform onvif
Traceback (most recent call last):
  File "/home/tatsch/.homeassistant/deps/lib/python3.5/site-packages/onvif/client.py", line 34, in wrapped
    return func(*args, **kwargs)
  File "/home/tatsch/.homeassistant/deps/lib/python3.5/site-packages/onvif/client.py", line 98, in __init__
    raise ONVIFError('%s doesn`t exist!' % url)
onvif.exceptions.ONVIFError: Unknown error: /home/tatsch/.homeassistant/deps/onvif/wsdl/media.wsdl doesn`t exist!

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/tatsch/home-assistant/homeassistant/helpers/entity_component.py", line 164, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 400, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 293, in result
    raise self._exception
  File "/usr/lib/python3.5/asyncio/tasks.py", line 239, in _step
    result = coro.send(None)
  File "/usr/lib/python3.5/asyncio/coroutines.py", line 210, in coro
    res = func(*args, **kw)
  File "/home/tatsch/home-assistant/homeassistant/components/camera/onvif.py", line 48, in async_setup_platform
    async_add_devices([ONVIFCamera(hass, config)])
  File "/home/tatsch/home-assistant/homeassistant/components/camera/onvif.py", line 66, in __init__
    '{}/deps/onvif/wsdl/media.wsdl'.format(hass.config.config_dir)
  File "/home/tatsch/.homeassistant/deps/lib/python3.5/site-packages/onvif/client.py", line 36, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: Unknown error: /home/tatsch/.homeassistant/deps/onvif/wsdl/media.wsdl doesn`t exist

The file really doesnt exist at that location but at /home/tatsch/.homeassistant/deps/lib/python3.5/site-packages/onvif/wsdl/media.wsdl

Are you running in a venv? How was home assistant installed?

I’ll rebuild my Dev box and see if I see similar issues.
Does it work if you manually install suds-passworddigest-py3?
pip3 install http://github.com/tgaugry/suds-passworddigest-py3/archive/86fc50e39b4d2b8997481967d6a7fe1c57118999.zip#suds-passworddigest-py3==0.1.2a

I have the same issue using the docker image

I’ve made a quick change, it appears that if onvif not installed in a venv then the component cannot find the wsdl path.
I’ve tested it in docker, hassbian and vagrant.

I’ve made a quick file to test.
Please create a custom_components folder in the home-assistant config folder and then a camera folder under the custom_components folder.
Then add the following file in to the camera folder as onvif.py
github gist onvif.py

Then restart Home-assistant

I’ve submitted a pull request to get it fixed in the next release
https://github.com/home-assistant/home-assistant/pull/8592

Hi,
this is my log file…
I have a Sricam with ONVIF enabled, all works with other platform but nut with HA (running on a PI).

Uffff…

Traceback (most recent call last):
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py", line 164, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
  File "/usr/lib/python3.4/asyncio/tasks.py", line 372, in wait_for
    return fut.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/asyncio/tasks.py", line 237, in _step
    result = next(coro)
  File "/usr/lib/python3.4/asyncio/coroutines.py", line 141, in coro
    res = func(*args, **kw)
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/camera/onvif.py", line 48, in async_setup_platform
    async_add_devices([ONVIFCamera(hass, config)])
  File "/srv/homeassistant/homeassistant_venv/lib/python3.4/site-packages/homeassistant/components/camera/onvif.py", line 68, in __init__
    self._input = media.GetStreamUri().Uri
  File "/home/homeassistant/.homeassistant/deps/onvif/client.py", line 36, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: <urlopen error [Errno -2] Name or service not known>
2017-07-22 11:32:42 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2017-07-22 11:32:42 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2017-07-22 11:32:43 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.
2017-07-22 11:32:43 WARNING (MainThread) [homeassistant.components.media_player] Setup of platform cast is taking over 10 seconds.

I’ve got 2 sricams, how have you configured them in homeassistant.
On mine I found that the component works even if you don’t specify a user or password. So all you need to do is specify the IP.
Are you using the released version or the custom_component I wrote yesterday.

Matt

Not yet, where i have to create the folder? In /home/homassistant or /home/homeassistant/.homeassistant ?

In the config file i have only
platform: onvif
host: xxx.xxx.xxx.xxx

Just tried both, bit always get “error loading image” in the front-end. Do I have to install any other components or library?

Yes you need to make sure ffmpeg is setup. See ffmpeg hub

The custom_components folder needs to be in the same folder as the configuration.yaml

Ok matt…
now all is working perfectly!

Installed the ffmpeg and put into the config, then only with the ip i can see the image from cam.

Thanks for all!

I’ve tried adding your custom component which has solved the wsdl issue. However I am now getting an issue with the stream closing unexpectedly.

I am using the official docker image at 0.48.1 and have ffmpeg setup.

2017-07-23 19:25:55 ERROR (MainThread) [aiohttp.server] Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 422, in start
    resp = yield from self._request_handler(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web.py", line 306, in _handle
    resp = yield from handler(request)
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 213, in coro
    res = yield from res
  File "/usr/local/lib/python3.6/asyncio/coroutines.py", line 213, in coro
    res = yield from res
  File "/usr/src/app/homeassistant/components/http/ban.py", line 58, in ban_middleware_handler
    return (yield from handler(request))
  File "/usr/src/app/homeassistant/components/http/__init__.py", line 424, in handle
    result = yield from result
  File "/usr/src/app/homeassistant/components/camera/__init__.py", line 338, in get
    response = yield from self.handle(request, camera)
  File "/usr/src/app/homeassistant/components/camera/__init__.py", line 376, in handle
    yield from camera.handle_async_mjpeg_stream(request)
  File "/config/custom_components/camera/onvif.py", line 99, in handle_async_mjpeg_stream
    yield from stream.close()
  File "/usr/local/lib/python3.6/site-packages/haffmpeg/core.py", line 131, in close
    yield from self._proc.communicate(input=b'q')
  File "/usr/local/lib/python3.6/asyncio/subprocess.py", line 195, in communicate
    loop=self._loop)
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 331, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 244, in _wakeup
    future.result()
  File "/usr/local/lib/python3.6/asyncio/futures.py", line 244, in result
    raise self._exception
  File "/usr/local/lib/python3.6/asyncio/tasks.py", line 179, in _step
    result = coro.send(None)
  File "/usr/local/lib/python3.6/asyncio/subprocess.py", line 143, in _feed_stdin
    self.stdin.write(input)
  File "/usr/local/lib/python3.6/asyncio/streams.py", line 294, in write
    self._transport.write(data)
  File "uvloop/handles/stream.pyx", line 632, in uvloop.loop.UVStream.write (uvloop/loop.c:74612)
  File "uvloop/handles/handle.pyx", line 150, in uvloop.loop.UVHandle._ensure_alive (uvloop/loop.c:54917)
RuntimeError: unable to perform operation on <WriteUnixTransport closed=True reading=False 0x7f2fc0f8dbd8>; the handler is closed

What camera are you using? Do you get a picture at all?

It’s a Digoo DG-M1Q. I can get a picture using rstp but not onvif.

Try adding debug logging for the component.

logger:
  logs:
    homeassistant.components.camera: debug
    custom_components.camera.onvif: debug

You should then see the steam URL in the log. That should be a rtsp URL.

Not sure that logging config is correct. I get this error.

2017-07-23 21:20:22 ERROR (MainThread) [homeassistant.config] Invalid config for [logger]: [homeassistant.components.camera] is an invalid option for [logger]. Check: logger->logger->homeassistant.components.camera. (See /config/configuration.yaml, line 133). Please check the docs at https://home-assistant.io/components/logger/
2017-07-23 21:20:22 ERROR (MainThread) [homeassistant.setup] Setup failed for logger: Invalid config.

I’ve edited the post above. I had missed the logs. Here is what I have in my configuration. Logger

It looks like it gets the correct URL for rtsp from the onvif service. However it doesn’t include the username and password. If I manually add an ffmpeg component with the username and password included in the url it works.

2017-07-24 07:05:54 DEBUG (MainThread) [custom_components.camera.onvif] ONVIF Camera Using the following URL for Thumper Cam: rtsp://192.168.0.57:554/onvif1

Working url rtsp://username:[email protected]:554/onvif1.

That’ll be the issue. I’ll have a look at the code tonight and update once i’ve got a fix. I’ll need to test that it doesn’t break existing code.