ONVIF camera

Anyone figure this out. I have the Reolink C2 and getting same errors and same testing as bueller. I’m on HA .65

I get this in the logs
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 82, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/lib/python3.6/asyncio/futures.py”, line 245, in result
raise self._exception
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/components/camera/onvif.py”, line 98, in setup_platform
add_devices([ONVIFHassCamera(hass, config)])
File “/usr/lib/python3.6/site-packages/homeassistant/components/camera/onvif.py”, line 121, in init
self._profiles = media_service.GetProfiles()
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 36, in wrapped
raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: (400, ‘Bad Request’)

have a look at this link reolink onvif
here is an extract from the link above

Before using it, please check the camera’s local IP address and set its profile to “Baseline”.

The errors that you are appear to be due to the camera reporting that the camera doesn’t understand the command. this could be due to the camera not fully supporting onvif or and authentication issue.

Hello @Devanl

Did you ever find a solution and got a connection?

I am getting the following problems:

Error while setting up platform onvif
Traceback (most recent call last):
  File "/usr/lib/python3.5/urllib/request.py", line 1254, in do_open
    h.request(req.get_method(), req.selector, req.data, headers)
  File "/usr/lib/python3.5/http/client.py", line 1106, in request
    self._send_request(method, url, body, headers)
  File "/usr/lib/python3.5/http/client.py", line 1151, in _send_request
    self.endheaders(body)
  File "/usr/lib/python3.5/http/client.py", line 1102, in endheaders
    self._send_output(message_body)
  File "/usr/lib/python3.5/http/client.py", line 934, in _send_output
    self.send(msg)
  File "/usr/lib/python3.5/http/client.py", line 877, in send
    self.connect()
  File "/usr/lib/python3.5/http/client.py", line 849, in connect
    (self.host,self.port), self.timeout, self.source_address)
  File "/usr/lib/python3.5/socket.py", line 711, in create_connection
    raise err
  File "/usr/lib/python3.5/socket.py", line 702, in create_connection
    sock.connect(sa)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/onvif/client.py", line 34, in wrapped
    return func(*args, **kwargs)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/onvif/client.py", line 201, in wrapped
    return call(params, callback)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/onvif/client.py", line 191, in call
    ret = func(**params)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/suds/client.py", line 559, in __call__
    return client.invoke(args, kwargs)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/suds/client.py", line 618, in invoke
    result = self.send(soapenv)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/suds/client.py", line 652, in send
    reply = transport.send(request)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/suds/transport/http.py", line 178, in send
    return HttpTransport.send(self, request)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/suds/transport/http.py", line 78, in send
    fp = self.u2open(u2request)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/suds/transport/http.py", line 119, in u2open
    return url.open(u2request, timeout=tm)
  File "/usr/lib/python3.5/urllib/request.py", line 466, in open
    response = self._open(req, data)
  File "/usr/lib/python3.5/urllib/request.py", line 484, in _open
    '_open', req)
  File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.5/urllib/request.py", line 1282, in http_open
    return self.do_open(http.client.HTTPConnection, req)
  File "/usr/lib/python3.5/urllib/request.py", line 1256, in do_open
    raise URLError(err)
urllib.error.URLError: <urlopen error [Errno 111] Connection refused>

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/homeassistant/helpers/entity_platform.py", line 84, in async_setup
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.5/asyncio/tasks.py", line 392, in wait_for
    return fut.result()
  File "/usr/lib/python3.5/asyncio/futures.py", line 274, 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 206, in coro
    res = func(*args, **kw)
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/onvif.py", line 51, in async_setup_platform
    async_add_devices([ONVIFCamera(hass, config)])
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/homeassistant/components/camera/onvif.py", line 72, in __init__
    self._input = media.GetStreamUri().Uri
  File "/home/ubuntu/homeassistant/lib/python3.5/site-packages/onvif/client.py", line 36, in wrapped
    raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: <urlopen error [Errno 111] Connection refused>

Haven’t looked at this for a while. Looking back through the thread now, are we testing it as a custom_component again?

I do not think so, but honestly I do not understand what the custom_component thing was all about…
I think it is a component introduced with 0.47 (https://www.home-assistant.io/components/camera.onvif/)

I have similar problems using current component. We need to add timestamp ajustment: Onvif error

For that I modify default component using latest library’s because onvif-py3 doesn’t have this patch. If you want to try.
onvif custom_component

after putting this on the back-burner for a while I have just had another crack at getting it to work…no luck

cameras.yaml

- platform: onvif
  host: 192.168.0.101
  name: Driveway
  port: 554

I have used the above settings to match what is currently configured in the camera (I turned off auth in an attempt to remove any obsticles)
image

However HassIO takes forever to restart which becomes evident in the error log:

2018-05-17 08:48:50 WARNING (MainThread) [homeassistant.setup] Setup of config is taking over 10 seconds.
2018-05-17 08:51:45 ERROR (MainThread) [custom_components.camera.onvif] Unable to communicate with ONVIF Camera: Unknown error: timed out
2018-05-17 08:51:45 WARNING (MainThread) [homeassistant.components.camera] Setup of platform onvif is taking over 10 seconds.
2018-05-17 08:51:45 ERROR (MainThread) [homeassistant.components.camera] Error while setting up platform onvif
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/suds/transport/http.py”, line 78, in send
fp = self.u2open(u2request)
File “/usr/lib/python3.6/site-packages/suds/transport/http.py”, line 119, in u2open
return url.open(u2request, timeout=tm)
File “/usr/lib/python3.6/urllib/request.py”, line 532, in open
response = meth(req, response)
File “/usr/lib/python3.6/urllib/request.py”, line 642, in http_response
‘http’, request, response, code, msg, hdrs)
File “/usr/lib/python3.6/urllib/request.py”, line 570, in error
return self._call_chain(*args)
File “/usr/lib/python3.6/urllib/request.py”, line 504, in _call_chain
result = func(*args)
File “/usr/lib/python3.6/urllib/request.py”, line 650, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 405: Method Not Allowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/suds/client.py”, line 652, in send
reply = transport.send(request)
File “/usr/lib/python3.6/site-packages/suds/transport/http.py”, line 178, in send
return HttpTransport.send(self, request)
File “/usr/lib/python3.6/site-packages/suds/transport/http.py”, line 86, in send
raise TransportError(e.msg, e.code, e.fp)
suds.transport.TransportError: Method Not Allowed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 34, in wrapped
return func(*args, **kwargs)
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 201, in wrapped
return call(params, callback)
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 191, in call
ret = func(**params)
File “/usr/lib/python3.6/site-packages/suds/client.py”, line 559, in call
return client.invoke(args, kwargs)
File “/usr/lib/python3.6/site-packages/suds/client.py”, line 618, in invoke
result = self.send(soapenv)
File “/usr/lib/python3.6/site-packages/suds/client.py”, line 664, in send
result = self.failed(binding, e)
File “/usr/lib/python3.6/site-packages/suds/client.py”, line 716, in failed
reply = error.fp.read()
File “/usr/lib/python3.6/http/client.py”, line 459, in read
s = self.fp.read()
File “/usr/lib/python3.6/socket.py”, line 586, in readinto
return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_platform.py”, line 82, in async_setup
SLOW_SETUP_MAX_WAIT, loop=hass.loop)
File “/usr/lib/python3.6/asyncio/tasks.py”, line 358, in wait_for
return fut.result()
File “/usr/lib/python3.6/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/config/custom_components/camera/onvif.py”, line 48, in async_setup_platform
async_add_devices([ONVIFCameraHASS(hass, config)])
File “/config/custom_components/camera/onvif.py”, line 67, in init
config.get(CONF_USERNAME), config.get(CONF_PASSWORD)
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 267, in init
self.update_xaddrs()
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 283, in update_xaddrs
capabilities = self.devicemgmt.GetCapabilities({‘Category’: ‘All’})
File “/usr/lib/python3.6/site-packages/onvif/client.py”, line 36, in wrapped
raise ONVIFError(err)
onvif.exceptions.ONVIFError: Unknown error: timed out
2018-05-17 08:51:47 ERROR (MainThread) [homeassistant.core] Error doing job: Task was destroyed but it is pending!
2018-05-17 08:51:54 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/components/websocket_api.py”, line 476, in get_services_helper
descriptions = await async_get_all_descriptions(self.hass)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 156, in async_get_all_descriptions
loaded = await hass.async_add_job(load_services_files, missing)
File “/usr/lib/python3.6/concurrent/futures/thread.py”, line 56, in run
result = self.fn(*self.args, **self.kwargs)
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/service.py”, line 139, in load_services_files
loaded[yaml_file] = load_yaml(yaml_file)
File “/usr/lib/python3.6/site-packages/homeassistant/util/yaml.py”, line 67, in load_yaml
with open(fname, encoding=‘utf-8’) as conf_file:
OSError: [Errno 9] Bad file descriptor

although I dont know what to do to get it working. this is using onvif v3 as posted above. Any ideas guys?

For the life of me i could never get my dahua cameras talking to HA via Onvif
Then last week after again looking at the issue i just tried port 80 and the cameras started working.

my config for in case it helps anyone

  • platform: onvif
    host: 10.0.0.4
    port: 80
    profile: 1
    name: front_door
    user: ********
    password: *********

can this component be used to grab a still image from inside an automation ?

I’m trying to set this up as well but getting the error:

Unable to communicate with ONVIF Camera: Unknown error: Missing element ProfileToken (GetStreamUri.ProfileToken)

I am using the custom_components route. I have HASSIO installed on ubuntu server 16.04 in a VM. I enabled the logger function and it gives me a bunch of zeep errors. I saw previously that it shouldn’t be using zeep. how to I correct this.

My camera is a Reolink RLC-410 with the following setup in my config.yaml:

camera:
 - platform: onvif
   host: 192.168.1.62
   port: 8000
   name: Driveway
   username: !secret camera_username
   password: !secret camera_password

Per my cameras settings, 8000 is the ONVIF port. I have tried port 80 and the default 5000 (by not specifying a port) and it gives me a connection error so I know it is hitting the cameras correct port. Hopefully someone can help. I can only think that maybe because the camera has 3 quality settings to choose from on login (Clear, Balanced, Fluent) which affect the streaming quality, I need to somehow specify which one I want to use.

I think I solved that error, i googled the error and included onvif.py in the search string and came across a site discussing the error:
https:/github.com/quantanium/python-onvif/issues/17
I modified line 69 in the onvif.py that is in my custom_components directory to be

{'StreamSetup': {'Stream': 'RTP-Unicast', 'Transport': 'UDP'}, 'ProfileToken': 'profiles[0]._token'}

Specifcally i added the bit at the end regarding 'ProfileToken': 'profiles[0]._token'. It solved my previous error and now I get a gray bar in my UI with the camera name, but no picture, there appears to be an error regarding FFMPEG, I’m not completely sure how to set that up. I just have

ffmpeg:

defined in my config.yaml

any help would be great.

Hello everyone,

I’m also struggling to have my Revotech PIR ip camera recognized and properly configured in Hassio. I’ve tried lots of combinations with unsuccessful results. I’ve also used ONVIF Device Manager for spotting the right URL and not even then have I managed to integrate the stream into Hassio. If I run VLC on a Windows machine I do access the stream. If I access the camera ip address, I can access the stream as well in the embedded website.

Any tip would be most appreciated.

Thanks

I’m also confused. Have you managed to understand what is that all about?

No not a clue, but I do not want to work too much with custom components in the fear of them being overwritten when updating or migrating.
It sounds like you are almost there, with accessing the stream and all.
Are you on Hassio.io?
Have you added the pre-requirement ffmpeg: ?
Have you tried the Shinobi Pro addon on Hassio?

Yes, tried all that already. I fear something may be missing in my home assistant because Not only do I access the steam from vlc but also from my iPhone. Only HA can’t access it neither from the standard HA with the configuration above, nor using Shinobi. In fact Shinobi does find the camera but it won’t reproduce the stream.

As I may be upgrading to the newest hassOS version soon, I have moderate hopes it will address this. I’m clueless at this point. When I suggested using the custom component is because I wanted to debug the ONVIF component, and it seemed suggested above, the custom component was the way to go.

Can anybody give me any hint on how to move forward?

Thanks

One weird thing that may help spot the source of this problem. When I use VLC for Windows, I can access the rtsp stream but when I use VLC on a Mac, it crashes complaining something is not right with the sound. Does this suggest anything to anybody?

As many others, I can’t get Onvif to work.
During troubleshooting I discovered at least one thing;
Don’t use an exclamation mark in your password, this will trip the ffmpeg command in bash. Hope this helps someone.

My current state;
Using hass in py venv on rasbian stretch.
The camera is a Hikvision DS-2CD2542FWD-IWS.
You have to enable Onvif in the settings and create a specific user for it.
I can get a stream on the commandline using ffmpeg.
I can also get a stream in VLC.

I can get a picture with the generic platform;
With a user specified in usermanagement (Not the Onvif user)

- platform: generic
  still_image_url: http://192.168.1.20/Streaming/channels/1/picture
  username: user
  password: foobar
  authentication: digest

Onvif is on port 8000, confirmed using desktop software (which also confirms onvif and the onvif user is working) Using other ports throws expected errors.

- platform: onvif
  host: 192.168.1.20
  name: Voordeur
  port: 8000
  username: onvif
  password: foobar
  # profile: 101 //tried with and without

Debug log:
2018-07-21 09:30:40 INFO (MainThread) [homeassistant.components.camera] Setting up camera.onvif
2018-07-21 09:30:40 DEBUG (MainThread) [custom_components.camera.onvif] Connecting with ONVIF Camera: 192.168.1.20 on port 8000
2018-07-21 09:30:50 ERROR (MainThread) [custom_components.camera.onvif] Unable to communicate with ONVIF Camera: Unknown error: [Errno 104] Connection reset by peer
2018-07-21 09:30:50 ERROR (MainThread)

Any idea why it would say connection reset by peer?

I too couldn’t get my onvif camera to work using the onvif platform, but it worked in VLC.

I tried just the ffmpeg platform calling the rtsp stream (same url VLC uses) and it works. See below for my config, note the first camera commented out is the hi-res stream. My RPi 2 can’t handle it.

ffmpeg:
  
camera:
#   - platform: ffmpeg
#     name: "Shed Camera Hi-Res"
#     input: rtsp://user:[email protected]:554/onvif1
#     extra_arguments: -r 3
   - platform: ffmpeg
     name: "Shed Camera Lo-Res"
     input: rtsp://user:[email protected]:554/onvif2
1 Like

I tried this but I was getting an invalid login on my router IP for some reason and hassio would not start. Had to do a power reset after changing my configuration.yaml back to this:

# Camera Support 1/21/18
ffmpeg:

# Cameras
camera:
  - platform: onvif
    host: 192.168.8.41
    port: 8080
    name: Cam-Kitchen
    username: admin
    password: cam1

I’m running HASSIO version 0.75.0 There have been some obvious improvements made as the error logs are quite a bit smaller. However, I’m still not able to get an image into HASSIO using ONVIF.

2018-08-04 12:14:22 INFO (MainThread) [homeassistant.components.camera] Setting up camera.onvif
2018-08-04 12:14:32 WARNING (MainThread) [homeassistant.components.camera] Setup of platform onvif is taking over 10 seconds.
2018-08-04 12:14:36 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-08-04 12:15:17 DEBUG (SyncWorker_4) [homeassistant.components.camera.onvif] Connecting with ONVIF Camera: 192.168.8.41 on port 8080
2018-08-04 12:15:18 DEBUG (SyncWorker_4) [homeassistant.components.camera.onvif] ONVIF Camera Using the following URL for Cam-Kitchen: rtsp://<user>:<password>@192.168.8.41:554/11
2018-08-04 12:24:49 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-08-04 12:25:05 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-08-04 12:25:06 WARNING (MainThread) [haffmpeg.core] Timeout while waiting of FFmpeg
2018-08-04 12:25:06 ERROR (MainThread) [aiohttp.server] Unhandled exception
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_protocol.py", line 398, in start
    await resp.prepare(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 300, in prepare
    return await self._start(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 605, in _start
    return await super()._start(request)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/web_response.py", line 367, in _start
    await writer.write_headers(status_line, headers)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/http_writer.py", line 100, in write_headers
    self._write(buf)
  File "/usr/local/lib/python3.6/site-packages/aiohttp/http_writer.py", line 57, in _write
    raise ConnectionResetError('Cannot write to closing transport')
ConnectionResetError: Cannot write to closing transport
2018-08-04 12:25:10 ERROR (MainThread) [homeassistant.core] Timer got out of sync. Resetting
2018-08-04 12:25:10 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-08-04 12:25:10 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-08-04 12:25:10 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.
2018-08-04 12:25:10 WARNING (MainThread) [haffmpeg.tools] Timeout reading image.

I’ve been able to successfully use VLC to view the video stream on my browser using the following:
rtsp://admin:[email protected]:554/11 (For High Quality) or
rtsp://admin:[email protected]:554/12 (For Low Quality)

I don’t know if the user name or password is being passed just by looking at the log file since it only records: Using the following URL for Cam-Kitchen: rtsp://user:[email protected]:554/11.

And I don’t see how I can change to the :554/12 for the low-res stream which I would prefer to use for HASSIO reporting. The camera appears to be connecting on the correct ONVIF port defined in the camera setup setting of 8080. I’m still not getting any images in the dashboard. I’m using several FDT 7901 720p IP cameras and they are working with the VLC, my NVR using ONVIF, any mobile device, and any browser I choose on my LAN.

@daryl.sargent I was having a similar issue where connectivity was failing with 401. Since I don’t care about other controls, switching to ffmpeg to pull my RTSP feed seemed sufficient. The only thing I’d do is move input to the secret.yml file so you don’t expose your pass.