Core: ONVIF Cameras with same IP but different profile treated as one entity

Created on 21 Mar 2020  路  11Comments  路  Source: home-assistant/core

The problem


I updated yesterday my installation to 0.107.2 (same for 0.107.4). Unfortunately that broke my onvif cams (DVR) configuration. I have several cameras on one DVR integrated through onvif. For each camera all the config is the same apart the profile number (e.g. same ip).
Ufter update HA tries to assign the same entity_id to all the cameras.

Environment

  • Home Assistant release with the issue: 0.107.4
  • Last working Home Assistant release (if known): 0.106.6
  • Operating environment (Hass.io/Docker/Windows/etc.): Docker on Ubuntu 19.10
  • Integration causing this issue: onvif
  • Link to integration documentation on our website: https://www.home-assistant.io/integrations/onvif/

Problem-relevant configuration.yaml

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

Traceback/Error logs

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

Additional information

in progress onvif

Most helpful comment

Let me remove my previous message, I probably misinterpreted your message.
One week of covid 19 confinement must make me paranoid.

Thanks

All 11 comments

I have also noticed the same as soon as updating to 0.107.0, I had two streams to the same camera (one low quality and one high, profile 0 and profile 1) and I kept on getting errors that entity already exists even though they had different names when being created.

Hi,

I think I found the commit that provoke the issue: (https://github.com/home-assistant/core/commit/edfb967b103d00d2d969faa274822bc9fb769307)

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...

I put a comment to the commit author @frenck but he seems to not understand the issue.

To have the way to use different camera profiles, in home assistant, we are forced to defined multiple profile of the same camera

Some additionals information I put in the forum:
https://community.home-assistant.io/t/onvif-cameras-from-a-dvr-entity-id-clash-after-upgrading-to-0-107-2/179968/8

I do understand the issue now, since there is context here.
The comment you left on a commit @pinonpierre, however, did not.

So a simple solution would be to take the profile ID into account, right?

I do understand the issue now, since there is context here.
The comment you left on a commit, however, did not.

Why this response:

A hardware mac address on a network must be unique... If this causes you issues, you have a whole world of different problems.

So a simple solution would be to take the profile ID into account, right?

Yes

Why this response

Because it was not clear your were talking about ONVIF capabilities from an aggregator, like a DVR.

Besides, we don't spend time on comments on commits or closed issues/PRs.

I'll look into adjusting this behavior.

I even used please and closed with thanks including 馃憤 emoji ... there was no aggression intended from my end and I don't see how that would be interpreted aggressively either. 馃し鈥嶁檪

Let me remove my previous message, I probably misinterpreted your message.
One week of covid 19 confinement must make me paranoid.

Thanks

Thanks @frenck for your fix :-)

No problem, having a unique ID allows one to change the name, icon & entity_id of an ONVIF camera from the frontend, which is kinda nice and cool IMHO.

The fix is backward compatible and awaiting review.

Was this page helpful?
0 / 5 - 0 ratings