Domonap Errors After Re-Auth In Home Assistant: A Fix Guide
Experiencing issues with your Domonap integration in Home Assistant after re-authentication? You're not alone! Many users encounter errors in their logs and find that their objects disappear after removing and re-adding the integration, especially after upgrading. This guide dives deep into the common problems, providing clear steps to diagnose and resolve them. Let's get your Domonap integration back on track!
Understanding the Problem
So, you've updated your Domonap integration in Home Assistant, maybe from an older version like 1.1.6 to a newer one such as 1.2.0 or 1.2.1. You decided to remove the old authorization and re-authorize, which seems like a good housekeeping step. But, uh-oh, now your objects aren't showing up, and your logs are screaming with errors. Don't worry; let's break down what's likely happening.
The core issue often stems from two main problems, which we'll address in detail:
- Asyncio Errors: The dreaded
asyncio.run() cannot be called from a running event looperror. This typically indicates a problem with how asynchronous tasks are being handled within the Domonap integration's code, especially concerning token updates. - Duplicate Unique IDs: Errors like
Platform domonap does not generate unique IDs. ID [some_long_id] already existssuggest that the integration is creating entities (buttons, cameras, etc.) with IDs that conflict with existing ones in your Home Assistant setup.
Let's dive into each of these problems and see how we can fix them.
Problem 1: Asyncio Errors
The Error Message
You might see errors like these in your Home Assistant logs:
2025-07-12 18:22:38.812 ERROR (MainThread) [homeassistant.components.button] Error while setting up domonap platform for button: asyncio.run() cannot be called from a running event loop
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 382, in _async_setup_platform
await asyncio.shield(awaitable)
File "/config/custom_components/domonap/button.py", line 11, in async_setup_entry
response = await api.get_paged_keys()
File "/config/custom_components/domonap/api.py", line 108, in get_paged_keys
self.check_token_expiration()
File "/config/custom_components/domonap/api.py", line 29, in check_token_expiration
asyncio.run(self.update_token())
File "/usr/local/lib/python3.13/asyncio/runners.py", line 191, in run
raise RuntimeError(
"asyncio.run() cannot be called from a running event loop")
RuntimeError: asyncio.run() cannot be called from a running event loop
This error pops up for different components like button and camera, but the underlying cause is the same.
What's Going On?
The error asyncio.run() cannot be called from a running event loop means that the code is trying to start a new asyncio event loop while one is already running. In Home Assistant, which is inherently asynchronous, trying to nest event loops like this is a no-no. It usually happens when a synchronous function tries to call an asynchronous one in a context where it shouldn't.
In the Domonap integration's case, this error typically occurs within the check_token_expiration() function in api.py. The integration attempts to update the authentication token using asyncio.run() which is incorrect within an already running asyncio loop.
The Fix
To resolve this, we need to modify the check_token_expiration() function to use asyncio.create_task() or await the update_token() function directly within the existing event loop.
-
Access Your Home Assistant Configuration: You'll need to access your Home Assistant configuration files. This might involve using the Samba add-on, the SSH & Web Terminal add-on, or accessing the files directly if you're running Home Assistant OS.
-
Locate the
api.pyFile: Navigate to thecustom_components/domonap/directory and find theapi.pyfile. -
Edit the
api.pyFile: Open theapi.pyfile in a text editor. Find thecheck_token_expiration()function, which likely looks something like this:async def check_token_expiration(self): if self._token_expires_at is not None and self._token_expires_at < datetime.now(): asyncio.run(self.update_token()) -
Modify the Function: Replace
asyncio.run(self.update_token())withawait self.update_token():async def check_token_expiration(self): if self._token_expires_at is not None and self._token_expires_at < datetime.now(): await self.update_token()Why this works: Using
awaitensures that theupdate_token()function is awaited within the existing asyncio event loop, preventing the creation of a new, conflicting loop. -
Save the File: Save the changes to the
api.pyfile. -
Restart Home Assistant: Restart your Home Assistant instance to apply the changes. This is crucial for the modifications to take effect.
Problem 2: Duplicate Unique IDs
The Error Messages
You'll likely see a barrage of errors like these in your logs:
2025-07-20 23:50:35.674 ERROR (MainThread) [homeassistant.components.button] Platform domonap does not generate unique IDs. ID 668294f1cf60 already exists - ignoring button.dvor_16k3_kalitka_1_open_door
2025-07-20 23:50:35.678 ERROR (MainThread) [homeassistant.components.camera] Platform domonap does not generate unique IDs. ID 67d1dd188a already exists - ignoring camera.camera
These errors indicate that the Domonap integration is trying to create entities (like buttons and cameras) with IDs that already exist in your Home Assistant configuration. This often happens after re-authenticating or upgrading the integration because Home Assistant still remembers the old entities.
What's Going On?
Home Assistant relies on unique IDs to track entities. When you remove and re-add an integration, or when an integration updates, it needs to ensure that each entity has a unique identifier. If the Domonap integration isn't generating unique IDs correctly, or if old entities are lingering in Home Assistant's database, you'll run into these conflicts.
The Fix
There are a couple of ways to tackle this. We'll start with the simplest, and if that doesn't work, we'll move to a more involved solution.
Solution 1: Restart and Refresh
Sometimes, Home Assistant just needs a little nudge to clear its head. Try these steps:
- Restart Home Assistant: Perform a full restart of your Home Assistant instance. This can often clear out cached data and resolve temporary conflicts.
- Clear Browser Cache: Clear your browser's cache and cookies. Sometimes, the browser can hold onto old information that interferes with Home Assistant's interface.
- Refresh the Page: After clearing the cache, refresh the Home Assistant page in your browser.
If you're lucky, this might be enough to resolve the issue. If not, let's move on to the more robust solution.
Solution 2: Clean Up Entity Registry
If the simple restart doesn't cut it, you might need to manually clean up the entity registry. This involves removing the old, conflicting entities from Home Assistant's database.
Warning: This involves directly modifying Home Assistant's configuration, so proceed with caution. It's always a good idea to create a backup before making significant changes..
-
Stop Home Assistant: Stop your Home Assistant instance to prevent any changes while you're editing the files.
-
Access the
.storageDirectory: Navigate to your Home Assistant configuration directory and find the.storagedirectory. This directory contains Home Assistant's internal data, including the entity registry. -
Locate the
core.entity_registryFile: Inside the.storagedirectory, find thecore.entity_registryfile. This is a JSON file that stores information about all the entities in your Home Assistant setup. -
Edit the
core.entity_registryFile: Open thecore.entity_registryfile in a text editor. Be careful when editing JSON files; a single mistake can corrupt the file and prevent Home Assistant from starting. -
Identify and Remove Conflicting Entities: Look for entries related to your Domonap integration. You can identify them by their entity IDs (e.g.,
button.dvor_16k3_kalitka_1_open_doororcamera.camera) or by their platform (domonap).Remove the entire JSON object for each conflicting entity. For example, you might remove something like this:
{ "entity_id": "button.dvor_16k3_kalitka_1_open_door", "platform": "domonap", "... other properties ..." } -
Save the File: Save the changes to the
core.entity_registryfile. -
Start Home Assistant: Start your Home Assistant instance.
-
Reconfigure Domonap (If Necessary): If the entities don't automatically reappear, you might need to reconfigure the Domonap integration through the Home Assistant UI.
Why this works: By removing the old entity entries, you're allowing Home Assistant to create new entities with the correct unique IDs when the Domonap integration is re-initialized.
Additional Tips and Considerations
- Check Domonap Configuration: Double-check your Domonap integration configuration in Home Assistant. Ensure that all the settings are correct, such as API keys or login credentials.
- Review Domonap Documentation: Consult the official documentation for the Domonap integration. There might be specific instructions or troubleshooting steps for your particular setup.
- Update Home Assistant: Make sure you're running the latest version of Home Assistant. Sometimes, bugs in older versions can cause integration issues.
- Seek Community Support: If you're still stuck, don't hesitate to reach out to the Home Assistant community forums or the Domonap integration's maintainers. Other users may have encountered similar issues and can offer valuable insights.
Conclusion
Dealing with errors after re-authenticating or upgrading integrations can be frustrating, but with a systematic approach, you can usually resolve the problems. By addressing the asyncio errors and cleaning up duplicate unique IDs, you should be well on your way to getting your Domonap integration working smoothly again in Home Assistant. Remember to take things one step at a time, and don't be afraid to ask for help if you need it. Happy automating, guys!