t0bst4r / matterbridge-home-assistant

Apache License 2.0
36 stars 2 forks source link

Bug: Lost devices in Google Home if matterbridge-home-assistant starts before HA or before HA is fully loaded #55

Open Cheerpipe opened 3 weeks ago

Cheerpipe commented 3 weeks ago

First of all, I am not sure if this is a bug or even if it belongs here or to the Matterbridge repository, so sorry if this bug report does not apply.

Description of the problem:

If Matterbridge-Home-Assistant (Docker version) is started before Home Assistant is running (or not fully loaded), it will "unregister" all devices, resulting in no devices being exposed. The problem is, if I am using Matterbridge devices with Google Home automations, these actions lose the link with the device, resulting in a "corrupted" automation. (Sorry for my English.)

Steps to reproduce:

  1. Expose a device (e.g., a switch) using Matterbridge-Home-Assistant.
  2. Link Google Home with Matterbridge-Home-Assistant.
  3. Create a Google Home automation and add a switch turn-on action as the automation action. Until this point, everything works okay.
  4. Stop Home Assistant.
  5. Stop the Matterbridge-Home-Assistant Docker.
  6. Start the Matterbridge-Home-Assistant Docker (before Home Assistant). At this point, Matterbridge-Home-Assistant will expose no devices.
  7. Check the recent Google Home automations. The action parts will be empty.
  8. I know Matterbridge-Home-Assistant is intended to be used with Home Assistant as a device backend, but the problem I describe above may occur anytime if Home Assistant is not up or not ready at the moment Matterbridge-Home-Assistant is started.
t0bst4r commented 3 weeks ago

That is interesting. I’ll try if it can be reproduced with Alexa as well.

in general all of this makes sense:

  1. matterbridge starts with an empty bridge
  2. Google home detects that the bridge is up again and scans it
  3. Google removes all missing devices
  4. automations loose references
  5. Devices are added again

The difference with Alexa will be that devices are never removed when they disappear on the Bridge. They just get "unavailable".

The solution could be to cache entities in the storage and restore them on boot - before HA is contracted first. Anyway the removal of entities is one thing that wouldn’t happen then.

I’ll need to figure out how deletions of entities could be detected.