ONVIF Cameras broken not (net)working from HA docker in 2021.1.5

I have upgraded a RPb3 venv to RPb4 docker image. Unfortunately I can’t for the life of me get 2 Dahua cameras to work either as ONVIF (which previously worked) or ffmpeg / stream. In both cases the docker seems not to be allowing traffic through, despite network_mode being set to “host”.

Trying to use the UI ONVIF device setup times out or throws “Unknown error occurred”. Adding the cameras through yaml causes my entire network to grind to a very slow crawl, home assistant to take tens of minutes to start and throw an ‘Error Handling Request’ (log below).

I’ve spent a couple of days reading the docs / forums, but can’t seem to pin down the reasons for the problem - I may need to simply build a new venv on the rpb4 - although part of the attraction of docker was avoiding the horrid builds of ffmpeg and pyav!

If anyone has a clue as to what I’m doing wrong before I go in that direction I’d really appreciate it.
Extra notes:

  1. I have tried ports 554 (RTSP) / 40000 (TCP) / UDP (37778) / 80 (HTTP)
  2. ONVIF is turned on on both cameras
  3. Multicast is turned on on both cameras
  4. I can view the cameras on their web-interface via the local network
  5. I can view the cameras via RTSP on VNC

Here is my docker-compose.yaml


version: '3.8'
networks:
  homeassistant:
    external: true
services:
  broker:
    container_name: mosquitto
    image: eclipse-mosquitto
    expose:
      - "1883"
    ports:
      - "1883:1883"
    restart: always

  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    network_mode: "host"
    volumes:
      - /opt/homeassistant:/config
      - /etc/localtime:/etc/localtime:ro
    devices:
      - /dev/ttyACM0:/dev/ttyACM0:rwm
    restart: always

Here are the cameras in cameras.yaml (included from configuration.yaml)

  - platform: onvif
    host: 192.168.0.200
    name: t_cam1
    username: !secret cam_usr
    password: !secret cam_pwd
    port: 554

  - platform: onvif
    host: 192.168.0.201
    name: t_cam2
    username: !secret cam_usr
    password: !secret cam_pwd
    port: 554

Here is the relevant log error


Logger: homeassistant
Source: components/onvif/config_flow.py:203
First occurred: 17:25:21 (1 occurrences)
Last logged: 17:25:21

Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/httpx/_exceptions.py", line 326, in map_exceptions
    yield
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1502, in _send_single_request
    (status_code, headers, stream, ext,) = await transport.arequest(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection_pool.py", line 218, in arequest
    response = await connection.arequest(
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/connection.py", line 106, in arequest
    return await self.connection.arequest(method, url, headers, stream, ext)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 72, in arequest
    ) = await self._receive_response(timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 133, in _receive_response
    event = await self._receive_event(timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_async/http11.py", line 172, in _receive_event
    data = await self.socket.read(self.READ_NUM_BYTES, timeout)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_backends/asyncio.py", line 153, in read
    raise
  File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpcore/_exceptions.py", line 12, in map_exceptions
    raise to_exc(exc) from None
httpcore.ReadError: [Errno 104] Connection reset by peer

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 130, in async_init
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 213, in _async_handle_step
    result: Dict = await getattr(flow, method)(user_input)
  File "/usr/src/homeassistant/homeassistant/components/onvif/config_flow.py", line 275, in async_step_import
    return await self.async_step_profiles()
  File "/usr/src/homeassistant/homeassistant/components/onvif/config_flow.py", line 203, in async_step_profiles
    await device.update_xaddrs()
  File "/usr/local/lib/python3.8/site-packages/onvif/client.py", line 276, in update_xaddrs
    capabilities = await devicemgmt.GetCapabilities({"Category": "All"})
  File "/usr/local/lib/python3.8/site-packages/zeep/proxy.py", line 64, in __call__
    return await self._proxy._binding.send_async(
  File "/usr/local/lib/python3.8/site-packages/zeep/wsdl/bindings/soap.py", line 156, in send_async
    response = await client.transport.post_xml(
  File "/usr/local/lib/python3.8/site-packages/zeep/transports.py", line 230, in post_xml
    response = await self.post(address, message, headers)
  File "/usr/local/lib/python3.8/site-packages/zeep/transports.py", line 215, in post
    response = await self.client.post(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1633, in post
    return await self.request(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1371, in request
    response = await self.send(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1406, in send
    response = await self._send_handling_auth(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1444, in _send_handling_auth
    response = await self._send_handling_redirects(
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1476, in _send_handling_redirects
    response = await self._send_single_request(request, timeout)
  File "/usr/local/lib/python3.8/site-packages/httpx/_client.py", line 1502, in _send_single_request
    (status_code, headers, stream, ext,) = await transport.arequest(
  File "/usr/local/lib/python3.8/contextlib.py", line 131, in __exit__
    self.gen.throw(type, value, traceback)
  File "/usr/local/lib/python3.8/site-packages/httpx/_exceptions.py", line 343, in map_exceptions
    raise mapped_exc(message, **kwargs) from exc  # type: ignore
httpx.ReadError: [Errno 104] Connection reset by peer

Docker does not limit outgoing traffic, but your cameras might filter traffic coming from an yet unknown ip/network?

I am using docker with same version not on rpi and everything working for me onvif wise.

Is “host” supposed to be in quotes?

Also, what OS is running on the rpi, how is the host network setup? What does the camera’s logfile look like?

The first bit is great news - I’d rather not go back to venv - what cameras do you have and did you add them via yaml or the UI please?

I’m new to docker-compose, but will remove the quotes now (I’m going to be very embarrassed if its that), the z-wave service is working so I assumed it was in host mode.

Yes, I thought that could be the case - but I haven’t changed their settings since the RPb3 venv connected to them and they don’t have trusted networks turned on, so I’m stumped.

I’m running v.10 (buster) - everything up to date as of this morning

The camera logs are showing second by second login/logouts from within the network (I assume HA) - image below - camstream is the ONVIF username reserved for the PI / HA

It shows a login, I assume that means it was successful. The connection reset by peer almost sounds like the cam itself is causing the socket to reset after login

I am using 3 Lorex cams, 2 different models, setup through the UI. I also have an old Sony cam but it is not onvif complaint, though I can still access the stream through rtsp.

Actually, I don‘t see why you define network „homeassistant“ in your docker-compose file while at the same time the only service (homeassistant) binds to the host‘s network.

No.

Thanks - I’ll do a hardware reset of the cameras just in case!

I’ll try removing the network too.

One of those changes to docker-compose.yaml worked!! :slight_smile: - insofar as the audodiscover in the UI now sees both of the cameras, although it is still timing out with the following

Logger: homeassistant.components.onvif
Source: components/onvif/event.py:223
Integration: ONVIF (documentation, issues)
First occurred: 19:28:31 (2 occurrences)
Last logged: 19:28:45

Unable to parse event from a0:bd:1d:33:79:58: { 'SubscriptionReference': None, 'Topic': { '_value_1': 'tns1:Monitoring/OperatingTime/LastReboot', 'Dialect': 'http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet', '_attr_1': { } }, 'ProducerReference': None, 'Message': { '_value_1': { 'Source': None, 'Key': None, 'Data': { 'SimpleItem': [ { 'Name': 'Status', 'Value': '31-01-2021T13:23:07Z' } ], 'ElementItem': [], 'Extension': None, '_attr_1': None }, 'Extension': None, 'UtcTime': datetime.datetime(2021, 1, 31, 8, 28, 30, tzinfo=<isodate.tzinfo.Utc object at 0xaf7e7df0>), 'PropertyOperation': 'Initialized', '_attr_1': { } } } }
Unable to parse event from 9c:14:63:66:73:12: { 'SubscriptionReference': None, 'Topic': { '_value_1': 'tns1:Monitoring/OperatingTime/LastReboot', 'Dialect': 'http://www.onvif.org/ver10/tev/topicExpression/ConcreteSet', '_attr_1': { } }, 'ProducerReference': None, 'Message': { '_value_1': { 'Source': None, 'Key': None, 'Data': { 'SimpleItem': [ { 'Name': 'Status', 'Value': '31-01-2021T18:21:32Z' } ], 'ElementItem': [], 'Extension': None, '_attr_1': None }, 'Extension': None, 'UtcTime': datetime.datetime(2021, 1, 31, 8, 28, 35, tzinfo=<isodate.tzinfo.Utc object at 0xaf7e7df0>), 'PropertyOperation': 'Initialized', '_attr_1': { } } } }

However … muuuuch closer … I’m embarrassed to think this may be a yaml issue!

Probably network_mode: host (without quotes). Without host networking, discovery does not work.