Support for ONVIF (standard for IP cameras etc)

Hi there,

I have been reading along for a few days. Got my Foscam C1 today, setup worked fine with the Foscam app so I am sure that the cam is working properly.

Now I am trying to set it up using onvif as described above. I used both the newest and the version before, both have trouble setting up.

As I am by no means a programmer I can’t figure out what is going on. The only line I understand is “onvif.exceptions.ONVIFError: Unknown error: (400, ‘Bad Request’)”, looks like something is pointing to the wrong URL but I am 100% sure I used the right IP, port and credentials.

2018-01-20 01:13:38 ERROR (MainThread) [custom_components.camera.onvif] Unable to communicate with ONVIF Camera: Unknown error: (400, ‘Bad Request’)
2018-01-20 01:13:38 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 400: Bad Request

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: Bad Request

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 726, in failed
raise Exception((status, reason))
Exception: (400, ‘Bad Request’)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/lib/python3.6/site-packages/homeassistant/helpers/entity_component.py”, line 171, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.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/asyncio/tasks.py”, line 180, in _step
result = coro.send(None)
File “/usr/lib/python3.6/asyncio/coroutines.py”, line 210, in coro
res = func(*args, **kw)
File “/config/custom_components/camera/onvif.py”, line 47, in async_setup_platform
async_add_devices([ONVIFCameraHASS(hass, config)])
File “/config/custom_components/camera/onvif.py”, line 66, 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: (400, ‘Bad Request’)

Any idea what I am doing wrong?

Kind regards,
Bram

Dear Matt:

thank you for writing the component.

I have a silly question: what do you mean by “onvif camera support?”

I briefly went through onvif specification, it contains many parts. The most important part is so-called “Profile S” which dictates the video streaming.

My question for you are:

  1. Since onvif CAN use rtsp for video streaming, what is the differences, in the home-assistant context, between your onvif component and ffmpeg component?

  2. exactly how to use onvif component in conjunction with ffmpeg component?

I just got this cheap German/Chinese camera claim to support onvif/rtsp with h.264 high. here is my current setup:

camera:
  # Security Camera: hikam S06
  - platform: ffmpeg
    input: -rtsp_transport tcp -i rtsp://192.168.34.134:554/stream=0
    name: cameraDinning

in your onvif component context, I am having problem where to input the /stream=0 part of the rtsp uri

thanks in advance

The idea of the component was to make it easier for users, you don’t need to worry about the stream when using the onvif platfrom.

the reason why I am “worrying” about it is because my suppose onvif camera is not working out of box.

On my synology, i set up this camera (hikam S6) as a “generic onvif” with port 8090, it worked fine.

but when i try to connect it to my home assistant using onvif, i got this strange error:

onvif.exceptions.ONVIFError: The requested profile token ProfileToken does not exist

I am not even sure the issue is on your side!

I got the still image working which refreshes now and than.
However clicking the image should open a live stream but nothing seems to happen.
It seems to do some camera_proxy calls which result in 200 response codes but nothing shows.

CONFIG
camera:

  • platform: onvif
    name: kitchen_camera
    host: 192.168.x.x
    username: admin
    password: verysecret
    port: 8080

ffmpeg:
ffmpeg_bin: /usr/local/bin/ffmpeg

Any ideas?

[UPDATE]
capturing rtsp stream via ffmpeg to avi works in command prompt.

[UPDATE]
tried the exact command from the logging for rstp and in a command prompt that works, however no stream in frontend.
ffmpeg -i rtsp://admin:[email protected]:554/11 -an -frames:v 1 -c:v mjpeg -q:v 2 -f image2pipe -

[UPDATE]
I get {“message”: “Entry not found”} on an attempt from the frontend to access the entity registry for my camera. It is just not in the entity registry.
https://x.x.x.x/api/config/entity_registry/camera.kitchen_camera 404 (Not Found)

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

Create a custom_component

@matt2005:

latest home assistant update, streaming worked with set up like this:
- platform: onvif
host: 192.168.5.132
port: 8090
name: hikamS6onvif
username: user
password: password

You’ve must done some magic that I wasn’t aware of. thank you so much

Have you figure out how to use onvif camera as motion sensor yet?

my other camera use proprietary amcrest platform, has a amcrest component which can configure it as a motion sensor easily.

i know that onvif suppose to support it. i am just wondering have you managed to figure out how to configure it in home assistance, if it is implemented, that is.

I haven’t looked at it at all. that is far above my skill level. I was hoping someone else who knows how to do it might have a crack

Hi All,

Mayby someone will be looking for configuration on how to get Sricam 360 camera to work, along with PTZ.
My camera is Sricam SP012, cheap 360 nigt vision camera.
But be aware that there is some backdoor on it … Once it started to get a look around my appartment by itself … So I suggest to lock down outside communication :wink:

Here is my config:

  - platform: onvif
    host: ip_of_camera
    username: admin
    password: password
    extra_arguments: -rtsp_transport udp

default password was 888888

tricky part for me was setting udp transport

After above setup I was able to use scipts to get control buttons:

  ptz_tilt_up:
    sequence:
      - service: camera.onvif_ptz
        data:
          entity_id: 'camera.sricam_360'
          tilt: 'UP'
  ptz_tilt_down:
    sequence:
      - service: camera.onvif_ptz
        data:
          entity_id: 'camera.sricam_360'
          tilt: 'DOWN'
  ptz_pan_left:
    sequence:
      - service: camera.onvif_ptz
        data:
          entity_id: 'camera.sricam_360'
          pan: 'LEFT'
  ptz_pan_right:
    sequence:
      - service: camera.onvif_ptz
        data:
          entity_id: 'camera.sricam_360'
          pan: 'RIGHT'
2 Likes

I’ve removed/denied internet access from every camera through my router, mostly because the security on these things and the amount they get updated is particularly poor, so they can suffer from all sorts of vulnerabilities that can give someone a route in if they went looking, so your suggestion is one I’d agree wholly with on all these P2P based IP cameras!

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

this worked for me in the end, not with same camera but maybe it could help
the port was the issue, my camera was not using standard one.

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

Thanks for your answer. My problem is that if I access the stream from VLC I do see what is being shot by the camera m. If I use that very same steam configuration and replicate it in HASSIO, nothing happens; I don’t even see any information in the log file.

Yesterday I also tired with my iOS and an app specific for RTSP, and I too accessed the stream even from an iOS device very quickly.

There is this thing above with the custom component, and it seems to be tied to increasing the log verbosity. Could anybody clarify what needs to be done if one wants to see in the logs what is going on with the camera?

I suspect there is something going on with my HASSIO as I’ve even tried with the Shinibi add on, and that won’t work either.

Hi MrUkleja

Can you give more info on how you get the PTZ working and possibly a screen shot etc

I have my Sricam sp005 and sp008 cameras in hassio no problem, but just cannot get them to do PTZ

You have full configuration above. I don’t know what I can add …
Simply configure your cams using ONVIF platform.
Then use camera.onvif_ptz service to get PTZ functionality.
That’s all …

Hi MrUkleja
I tried your setting and it worked, just one quick question: Can you stream the video on your hassio web interface?
I have picture refreshed every 10 seconds.

That is correct. But if you tap on video, you will see pop-up with live stream.
On my Sricam it takes few seconds to show onvif live stream. I use Shinobi CCTV solution on second raspberry and I’m downsizing video to make it work faster when I’m on mobile network.

running into problems with onvif camera component also.
VLC works fine with this URL : rtsp://192.168.XXX.YYY:554/stream1

this is the config :

  - platform: onvif
    host: 192.168.11.15
    name: Street

Hass.io webif shows a card saying Street (Image not available)

Any ideas?

Check my config above, maybe your camera need extra arguments for UDP transport type for RTSP or any other …