maximvelichko / pyvera

A python library to control devices via the Vera hub
GNU General Public License v2.0
26 stars 30 forks source link

Frequently fails on Home Assistant restart with "Entity already exists" #128

Closed brgerig closed 4 years ago

brgerig commented 4 years ago

When restarting Home Assistant, I very frequently get errors in the log similar to the following:

2020-02-15 22:50:48 ERROR (MainThread) [homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/opt/homeassistant/lib/python3.8/site-packages/homeassistant/helpers/entity_platform.py", line 415, in _async_add_entity
    raise HomeAssistantError(msg)
homeassistant.exceptions.HomeAssistantError: Entity id already exists: binary_sensor.living_room_window_106. Platform vera does not generate unique IDs

There are usually errors for most of my devices. When this happens, HA is unable to control them. My only option is to keep restarting HA until the errors don't show up. I haven't been able to figure out any pattern as to when this does or doesn't happen.

steveelwood commented 4 years ago

I have the same issue. There's a thread on the Home Assistant forums documenting the same bug. https://community.home-assistant.io/t/vera-error-entity-ids-already-exist-unable-to-toggle-devices-on-and-off/171397

pavoni commented 4 years ago

This is an odd one. Seems likely that something has changed in HA that causes this. given that it seems intermittent it might even be some sort of timing issue

Given that this library just gets the ids from Vera - it's hard to imagine there is anything here.

I guess it' s possible that the HA wrapper needs modification - although again that's pretty simple.

Don't know what to suggest - except to see if there are other similar HA id issues in the recent release.

brgerig commented 4 years ago

It's actually been an issue for a while, at least since I began using Home Assistant back in the .80's. Today it happened for probably 6+ restarts in a row before I finally got a clean restart without Vera device errors.

vangorra commented 4 years ago

I'm aware of a bug with the HA integration that can cause this. The short of it is this will take a while to fix. I already have one PR in that modernizes the vera config. Once that lands, then we'll gave the code in place to fix the unique ID issue. Once the id fix is in place, you'll have to remove your existing config from vera then re add it. This will result in entirely new entity IDs.

The cause of the issue is that the vera integration sets the entity unique id using the vera id from the hub. The entity unique id is suppose to be unique in the world. So it's often a device MAC address. The problem is that Vera's device ids are far from unique as it's an auto incrementing integer starting at 1.

The fix I'll be submitting will make the unique ID the hub serial number concatenated with the device id. Something like "vera_234565433_10".

That all being said, getting changes merged in HA takes a while as they're maintainers are focused on quality and stability. So you won't see a fix for a couple months. On the plus side, this also opens up the ability to support multiple vera controllers.

brgerig commented 4 years ago

Great news! Thanks for the update, and for the work you're putting in to getting it fixed.

vangorra commented 4 years ago

Closing as this will be resolved in home assistant.