home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
69.77k stars 28.92k forks source link

Similar Onvif Cameras being merged #97258

Open fernandolcardoso opened 11 months ago

fernandolcardoso commented 11 months ago

The problem

I have several IMOU cameras and when adding the duplicate Onvif, the settings are merged and/or unified incorrectly.

What version of Home Assistant Core has the issue?

core-2023.7.3

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Onvif

Link to integration documentation on our website

Diagnostics information

When adding the first camera, everything works correctly

image

image

image

However, when adding the second camera it informs that it was already configured

image

You may notice a mismatch in the settings or when the camera is added in the configuration files

image

image

In the "core.config_entries" file it is possible to observe the discrepancy of the problem, when adding a second entry with the data from the second camera, the data is somehow merged between the two. Notice the "title" and "data:name" keys are no longer the same.

image

Example YAML snippet

Not applicable because Home Assistant had the bright idea to remove this option

Anything in the logs that might be useful for us?

2023-07-26 08:39:26.085 INFO (MainThread) [homeassistant.setup] Setting up onvif
2023-07-26 08:39:26.085 INFO (MainThread) [homeassistant.setup] Setup of domain onvif took 0.0 seconds
2023-07-26 08:39:29.000 INFO (MainThread) [homeassistant.components.button] Setting up button.onvif
2023-07-26 08:39:29.002 INFO (MainThread) [homeassistant.components.camera] Setting up camera.onvif
2023-07-26 08:39:29.003 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.onvif
2023-07-26 08:39:29.004 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.onvif
2023-07-26 08:39:29.007 INFO (MainThread) [homeassistant.components.switch] Setting up switch.onvif
2023-07-26 08:39:29.012 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new button.onvif entity: button.entrada_principal_reboot
2023-07-26 08:39:29.013 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new button.onvif entity: button.entrada_principal_set_system_date_and_time
2023-07-26 08:39:29.013 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.onvif entity: camera.entrada_principal_profile000
2023-07-26 08:39:29.014 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.onvif entity: camera.entrada_principal_profile001
2023-07-26 08:39:29.014 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.onvif entity: binary_sensor.entrada_principal_motion_alarm
2023-07-26 08:39:29.015 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new binary_sensor.onvif entity: binary_sensor.entrada_principal_global_scene_change
2023-07-26 08:39:29.015 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.onvif entity: switch.entrada_principal_autofocus
2023-07-26 08:39:29.016 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.onvif entity: switch.entrada_principal_ir_lamp
2023-07-26 08:39:29.016 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.onvif entity: switch.entrada_principal_wiper

2023-07-26 08:42:35.252 INFO (MainThread) [homeassistant.components.button] Setting up button.onvif
2023-07-26 08:42:35.252 INFO (MainThread) [homeassistant.components.camera] Setting up camera.onvif
2023-07-26 08:42:35.253 INFO (MainThread) [homeassistant.components.binary_sensor] Setting up binary_sensor.onvif
2023-07-26 08:42:35.253 INFO (MainThread) [homeassistant.components.sensor] Setting up sensor.onvif
2023-07-26 08:42:35.253 INFO (MainThread) [homeassistant.components.switch] Setting up switch.onvif
2023-07-26 08:42:35.255 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new button.onvif entity: button.hall_bloco_a_reboot
2023-07-26 08:42:35.255 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new button.onvif entity: button.hall_bloco_a_set_system_date_and_time
2023-07-26 08:42:35.256 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.onvif entity: camera.hall_bloco_a_profile000
2023-07-26 08:42:35.256 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new camera.onvif entity: camera.hall_bloco_a_profile001
2023-07-26 08:42:35.258 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.onvif entity: switch.hall_bloco_a_autofocus
2023-07-26 08:42:35.258 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.onvif entity: switch.hall_bloco_a_ir_lamp
2023-07-26 08:42:35.259 INFO (MainThread) [homeassistant.helpers.entity_registry] Registered new switch.onvif entity: switch.hall_bloco_a_wiper

Additional information

I noticed that there are other calls without answers and/or solutions similar to my question. I hope I have presented evidence/information that leads to the solution of the problem.

fernandolcardoso commented 11 months ago

Complementing the question, it is possible to observe that the Home Assistant cannot obtain the MAC address correctly and registers an unknown/random MAC address in the "core.config_entries" file.

By changing the "core.config_entries" file, informing the correct MAC address in the "unique_id" key and then restarting the Home Assistant, it is possible to add the other cameras without problems.

image

home-assistant[bot] commented 11 months ago

Hey there @hunterjm, mind taking a look at this issue as it has been labeled with an integration (onvif) you are listed as a code owner for? Thanks!

Code owner commands Code owners of `onvif` can trigger bot actions by commenting: - `@home-assistant close` Closes the issue. - `@home-assistant rename Awesome new title` Renames the issue. - `@home-assistant reopen` Reopen the issue. - `@home-assistant unassign onvif` Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


onvif documentation onvif source (message by IssueLinks)

fernandolcardoso commented 11 months ago

This Home Assistant Onvif integration is buggy or poorly developed. Cameras are being added with wrong MAC addresses and now it is adding duplicate entities.

I already removed and added again and after restarting the entities are duplicated.

image

fernandolcardoso commented 11 months ago

Resolved when editing the "core.entity_registry" file, again a manual procedure that could compromise the system when edited.

image

Basically, you should remove the entity that stopped working from the list, rename the duplicate entity by removing the "_2", save and restart

image

fernandolcardoso commented 11 months ago

Is the Home Assistant interested in resolving the issue?

I see that other problems were reported, but they were left without a return and solution

https://github.com/home-assistant/core/issues/69661

https://github.com/home-assistant/core/issues/96889

energywave commented 9 months ago

The problem is still there! I'm also having the exact same issue by adding the second IMOU Cue2C device. It seems that ONVIF use the first reported MAC address as unique_id and that MAC Address seems to be the one when the device is in A/P mode and that's the same for every cameras...

To workaround the issue I did the following and it's working correctly (but this issue should really be resolved!):

  1. Remove all the ONVIF integration with multiple devices inside
  2. Add the first camera as usual
  3. Edit the .storage/core.config file and change the unique_id field replacing the value with the real one (use "arp -a" from the command prompt to get the mac address of the cam ip)
  4. Reboot Home Assistant (the core is enough)
  5. Add the second camera as usual
  6. (optional) edit again the .storage/core.config and change again the unique_id of the second camera with the real one
  7. Reboot Home Assistant core
  8. Repeat points 5-7 if adding more cameras
Mister-Slowhand commented 7 months ago

I'm seeing this bug too. Generic chinese WiFI cam, local installation, they both return the same serial number, hardware version and some kind of fake mac address (4FB494:4FB495:4FB496:4FB497:4FB498:4FB499). When I try to add the second, HA says it's already configured. Workaround doesn't work : if I change only the core.config_entries MAC address with the correct one, second camera adds, but only one stream (the second one) is linked to both devices. If I try and change all references to the MAC address, duplicates sensors are created with fake MAC address at restart.

MAC address shouldn't be used to discriminate devices, as long as IP address is different, it should try to keep both.

issue-triage-workflows[bot] commented 4 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

fernandolcardoso commented 4 months ago

Any solution?

fernandolcardoso commented 3 months ago

Any solution? I see many similar problems in other forums. Since it is an issue that can be solved manually, I understand that it is a problem of the Home Assistant to detect the correct MAC.

energywave commented 3 months ago

I understand that it is a problem of the Home Assistant to detect the correct MAC.

I think that's a IMOU problem that expose the MAC address of the A/P mode and the fact that's the same MAC address for every device is for sure a IMOU problem, not ONVIF integration. That said it can be taken in account by the integration and resolved easily by taking in account the specific MAC address or the manufacturer and ignore the first MAC, for example. But something has to be done, I agree.

tomlut commented 3 months ago

Yep still an issue. I had to shutdown my HA host machine for some electrical work today. After booting back up I have two Onvif devices.

One that works, and another one with a different MAC address and no entities. Neither MAC address are correct.

Two issues: 1) We really need to be able to delete these false devices via the UI rather than delving into the storage registry. 2) They should not be generated in the first place.

issue-triage-workflows[bot] commented 3 weeks ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

tomlut commented 3 weeks ago

Nothing has been done so this is still an issue.

fernandolcardoso commented 2 weeks ago

Hello Home Assistant development team, would you be able to help us or take a closer look at this issue?