ONVIF cameras from a DVR entity_id clash after upgrading to 0.107.2

Hi!

I updated today my installation to 0.107.2. Unfortunately that broke my cams configuration. I have several cameras on one DVR integrated through onvif. Thats my config for that:

camera:
  - platform: onvif
    host: 192.168.1.13
    username: *****
    password: *****
    name: Driveway
    profile: 1
    port: 80
  - platform: onvif
    host: 192.168.1.13
    username: *****
    password: *****
    name: Enternance
    profile: 0
    port: 80

For each camera all the config is the same apart the profile number.
That configuration used to work in 0.105 and now it tries to assign the same entity_id to all the cameras.

2020-03-20 21:57:31 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 425, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: camera.entarnance. Platform onvif does not generate unique IDs

How can I fix that?

I got the same error.

I havenā€™t touched to entity creation in my ONVIF PR embedded in this release, only altered ptz service.

So it could be relative to other parent camera change or even maybe to that issue :
https://github.com/home-assistant/core/issues/32992

Same issue for me but not related to the bug https://github.com/home-assistant/core/issues/32992 because I didnā€™t overrided the docker command. For my part, I sue docker-compose on Synology.

Ok, seems there is an issue if you set 2 times the same onvif camera with 2 differents profilesā€¦ (Maybe we can also have this issue with 2 differents onvif camera??)

My workaround is to use generic camera while waiting for a fix.

How do you reverse engineer the stream address from ONVIF? I found a tool for windows to do that, but I donā€™t have windows on any machineā€¦

BTW.: Created an issue for the problem:

Enable debug logging for Onvif and all related as i donā€™t remeber which one provides this info:

    homeassistant.components.onvif.camera: debug
    homeassistant.components.camera: debug
    zeep.asyncio.transport: debug
    zeep.asyncio: debug

Restart HA then look at your logs for ā€œONVIF Camera Using the following URL for ā€¦ā€ string, it should include your RTSP URI.

Hi,

Thanks for your reply

rtsp://<user>:<password>@192.168.0.90:554/12

Just tested the 0.107.4 version and the issue still occurs

Partial Logs (Removed soap xml lines because message was too big to be posted here):

2020-03-21 15:03:44 INFO (MainThread) [homeassistant.components.camera] Setting up camera.generic
2020-03-21 15:03:44 INFO (MainThread) [homeassistant.components.camera] Setting up camera.onvif
2020-03-21 15:03:44 INFO (MainThread) [homeassistant.components.camera] Setting up camera.onvif
2020-03-21 15:03:44 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF camera platform
2020-03-21 15:03:44 DEBUG (MainThread) [homeassistant.components.onvif.camera] Constructing the ONVIFHassCamera
2020-03-21 15:03:44 DEBUG (MainThread) [homeassistant.components.onvif.camera] Importing dependencies
2020-03-21 15:03:44 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF camera component
2020-03-21 15:03:44 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF camera device @ '192.168.0.90:8080'
2020-03-21 15:03:44 DEBUG (MainThread) [homeassistant.components.onvif.camera] Updating service addresses
2020-03-21 15:03:45 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/device_service:
2020-03-21 15:03:45 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF camera platform
2020-03-21 15:03:45 DEBUG (MainThread) [homeassistant.components.onvif.camera] Constructing the ONVIFHassCamera
2020-03-21 15:03:45 DEBUG (MainThread) [homeassistant.components.onvif.camera] Importing dependencies
2020-03-21 15:03:45 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF camera component
2020-03-21 15:03:45 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF camera device @ '192.168.0.90:8080'
2020-03-21 15:03:45 DEBUG (MainThread) [homeassistant.components.onvif.camera] Updating service addresses
2020-03-21 15:03:46 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/device_service:
2020-03-21 15:03:46 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/device_service (status: 200):
2020-03-21 15:03:46 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/event_service:
2020-03-21 15:03:46 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/device_service (status: 200):
2020-03-21 15:03:46 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/event_service:
2020-03-21 15:03:46 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/event_service (status: 400):
2020-03-21 15:03:47 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/device_service:
2020-03-21 15:03:47 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/event_service (status: 400):
2020-03-21 15:03:47 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/device_service:
2020-03-21 15:03:47 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/device_service (status: 200):
2020-03-21 15:03:47 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF device management service
2020-03-21 15:03:48 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieving current camera date/time
2020-03-21 15:03:48 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/device_service:
2020-03-21 15:03:48 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/device_service (status: 200):
2020-03-21 15:03:48 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF device management service
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieving current camera date/time
2020-03-21 15:03:49 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/device_service:
2020-03-21 15:03:49 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/device_service (status: 200):
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] TimeZone for date/time: UTC
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] Camera date/time: 2020-03-21 14:03:49+00:00
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] Camera date/time in UTC: 2020-03-21 14:03:49+00:00
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] System date/time: 2020-03-21 14:03:48.775385+00:00
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] Connecting with ONVIF Camera: 192.168.0.90 on port 8080
2020-03-21 15:03:49 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieving profiles
2020-03-21 15:03:50 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/media_service:
2020-03-21 15:03:50 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/device_service (status: 200):
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] TimeZone for date/time: UTC
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Camera date/time: 2020-03-21 14:03:49+00:00
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Camera date/time in UTC: 2020-03-21 14:03:49+00:00
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] System date/time: 2020-03-21 14:03:49.408647+00:00
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Connecting with ONVIF Camera: 192.168.0.90 on port 8080
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieving profiles
2020-03-21 15:03:50 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/media_service:
2020-03-21 15:03:50 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/media_service (status: 200):
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieved '2' profiles
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Using profile index '0'
2020-03-21 15:03:50 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieving stream uri
2020-03-21 15:03:51 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/media_service:
2020-03-21 15:03:51 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/media_service (status: 200):
2020-03-21 15:03:51 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieved '2' profiles
2020-03-21 15:03:51 DEBUG (MainThread) [homeassistant.components.onvif.camera] Using profile index '1'
2020-03-21 15:03:51 DEBUG (MainThread) [homeassistant.components.onvif.camera] Retrieving stream uri
2020-03-21 15:03:52 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Post to http://192.168.0.90:8080/onvif/media_service:
2020-03-21 15:03:52 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/media_service (status: 200):
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] ONVIF Camera Using the following URL for camera_entree: rtsp://<user>:<password>@192.168.0.90:554/11
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF PTZ service
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] PTZ is not available
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] Completed set up of the ONVIF camera component
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] Camera 'camera_entree' added to hass
2020-03-21 15:03:52 DEBUG (MainThread) [zeep.asyncio.transport] HTTP Response from http://192.168.0.90:8080/onvif/media_service (status: 200):
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] ONVIF Camera Using the following URL for camera_entree_profile1: rtsp://<user>:<password>@192.168.0.90:554/12
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] Setting up the ONVIF PTZ service
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] PTZ is not available
2020-03-21 15:03:52 DEBUG (MainThread) [homeassistant.components.onvif.camera] Completed set up of the ONVIF camera component
2020-03-21 15:03:52 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 425, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: camera.camera_entree_profile1. Platform onvif does not generate unique IDs

I have also noticed the same since 0.107.0, I had two streams for the same camera as two different entities (one low quality and one high, profile 0 and profile 1) and worked just fine on 0.106.X but now it complains that is a duplicate

Probably relative to the code change of the 2020 february the 22th:

    @property
    def unique_id(self) -> Optional[str]:
        """Return a unique ID."""
        return self._mac
    async def async_obtain_mac_address(self):
        """Obtain the MAC address of the camera to use as the unique ID."""
        devicemgmt = self._camera.create_devicemgmt_service()
        network_interfaces = await devicemgmt.GetNetworkInterfaces()
        for interface in network_interfaces:
            if interface.Enabled:
                self._mac = interface.Info.HwAddress

The unique Id seems to be generated from the hardware mac addressā€¦

1 Like

Bug => https://github.com/home-assistant/core/issues/33093

Bug was already linked 5h earlier :wink:
Relevant PR to watch: