sbidy / wiz_light

A WiZ Light integration for Home Assistant
MIT License
341 stars 68 forks source link

Invalid Entity ID's Generated by HASS #129

Closed spencerthayer closed 2 years ago

spencerthayer commented 3 years ago

My problem. If Home Assistant reboots while a Wiz light is powered off it will mark that light as broken, when that light is switched on, instead of reconnecting with the information contained within the configuration.yaml auto-discovery will connect to that light with a new entity ID. This is frustrating because it breaks everything. The only solution is to turn all the lights on in my house and reboot - let the configuration.yaml properly establish connections and then turn those lights off as I see fit. Until such time that it starts all over again.

Is there a way to disable auto-discovery entirely? I hate it. It ruins everything. I only want Home Assistant to connect to the device that I specify it connects to in the particular way that I want it to.

code-in-progress commented 3 years ago

Is there a way to disable auto-discovery entirely? I hate it. It ruins everything. I only want Home Assistant to connect to the device that I specify it connects to in the particular way that I want it to.

The way that I did it was to roll back to the 0.2 version and define all my lights (55 in total now) in yaml manually. The 0.2 version has been running flawlessly for me for months now.

sbidy commented 3 years ago

I should have a deeper look into that. Overall the integration itself doesn't provide a "auto-discover" yet. If you add a device with the config flow this device should not be added again because of the unique identifier. This ID will be the MAC address of the bulb. The discovery happens because of the initialization of the YAML file. HASS will read the file on each startup and initialize every entry which "not exists". But if you add the bulbs with the configuration.yaml (which will be a deprecated feature in the next HASS versions) you should add a name to each entry in your config. Because this will identify the bulb and if the initialization of the YAML file starts, HASS this should recognize this entries as existing.

I've tested this with the latest HASS version and the bulb will not be added twice in my implementation. But the issue, that the bulb will marked as "unavailable" after a HASS reboot and a offline bulb will stay. I'm working on that.

The first entry shows a device added with the UI - the second is a configuration.yaml one:

  {
                "entity_id": "light.wiz_bulb_dw",
                "config_entry_id": "2fc718d8a8633d293c4ed53993152e25",
                "device_id": "c3e94d7154c1c84ceee67af124513694",
                "area_id": null,
                "unique_id": "a8bb50214db1",
                "platform": "wiz_light",
                "name": null,
                "icon": null,
                "disabled_by": null,
                "capabilities": {},
                "supported_features": 1,
                "device_class": null,
                "unit_of_measurement": null,
                "original_name": "WiZ Bulb DW",
                "original_icon": null
            },
            {
                "entity_id": "light.test1",
                "config_entry_id": null,
                "device_id": null,
                "area_id": null,
                "unique_id": "a8bb5020feca",
                "platform": "wiz_light",
                "name": null,
                "icon": null,
                "disabled_by": null,
                "capabilities": {},
                "supported_features": 1,
                "device_class": null,
                "unit_of_measurement": null,
                "original_name": "Test1",
                "original_icon": null
            }
spencerthayer commented 3 years ago

Where does one put this in the configuration.yaml when just pasting the below I see can not read a block mapping entry; a multiline key may not be an implicit key.

{
  "entity_id": "light.living_room_lamp",
  "config_entry_id": null,
  "device_id": null,
  "area_id": null,
  "unique_id": "58a26ed6-74f3-43a1-9641-526f043c781f",
  "platform": "wiz_light",
  "name": "Living Room Lamp",
  "icon": null,
  "disabled_by": null,
  "capabilities": {},
  "supported_features": 1,
  "device_class": null,
  "unit_of_measurement": null,
  "original_name": "Living Room Lamp",
  "original_icon": null
}

I am also unclear how I integrate the above with the typical WIZ light setup.

light:
  - platform: "wiz_light"
    host: 192.168.0.201
    name: "Living Room Lamp"
spencerthayer commented 3 years ago

Any insight @sbidy?

sbidy commented 3 years ago

Ah, the first is an JSON notation config from the internal HASS database. This can't be copied and pasted into the configuration.yaml.

The overall issue exist since I integrated the entry and device creation in HASS. If you add a entry via configuration.yaml no device will be created.

excalbian commented 3 years ago

The overall issue exist since I integrated the entry and device creation in HASS. If you add a entry via configuration.yaml no device will be created.

Unless I’m misunderstanding, this isn’t what’s happening in my system. I had all my (dozen or so) bulbs defined in configuration.yaml but if any were (apparently) offline when homeassistant started, the bulbs would then be added with a new name (and device id - like light.jacobs_room_east_2 with the 2 added) when they were available. This has the effect of breaking my automations and dashboards, which I’ve been trying to work around. I’ve started experimenting with moving all the lights to the UI (and out of configuration.yaml) since that seems to not have the same issues, but I’m still testing that approach.

sbidy commented 3 years ago

Yes, I know that issues and I'm pretty sure that there is an issue in my code but I tried to get an idea where and why this issues happens. I also try to get some insights from the HASS dev side but without an respones. There are more integration out there with the same issue - most of them with a direct interaction with the (IoT) device.

spencerthayer commented 3 years ago

There are more integration out there with the same issue - most of them with a direct interaction with the (IoT) device.

Exploring this topic I can confirm @sbidy's statement that other integrations are experiencing a similar problem. I am suspecting that this could be a bug within the Home Assistant core and not a fault of this integration. I have some free time this week so I am going to have a better look into the code.

spencerthayer commented 2 years ago

I ended up deleting Homeassistant and just using the Wiz app integrated with Google but I though I would try Homeassistant again and find that this issue is still very persistent. @excalbian did you ever find a solution?

spencerthayer commented 2 years ago

I added every light through the GUI rather than with a YAML file but I am still getting the duplicate lights error. For example the light light.bedroom_ceiling_1 gets replaced with light.bedroom_ceiling_1_2. And of course, this problem completely breaks Home Assistant so that it's absolutely unusable as a light management app.

Screen Shot 2021-12-07 at 2 08 58 PM

@sbidy I have noticed there are other issues with similar problems such as #110, #185 and #192 but it doesn't appear like there is an existing solution. Is there any fix for this problem on the horizon?

sbidy commented 2 years ago

As I mentioned, if the lights are offline while HASS is rebooting, the bulb will re-add after you power the bulb on. The solution is to do not reboot HASS while the bulbs are offline. In the current HASS dev fork, where I'm working on the native integration in the HASS core, the issue was (maybe) resolved.

TL;DR: Don't restart HASS while the bulbs are powered off. This will be a workaround for that issue.

spencerthayer commented 2 years ago

Is this a problem with HASS or the integration?

bdraco commented 2 years ago

This can be closed as its fixed in the core version

spencerthayer commented 2 years ago

It does seem to be fixed.