Newly created entities are unavailable for several minutes
Hi, I have a problem with getting the state of newly created entities. I am listening to events from HA to get newly created entities:
self.listen_event(self.on_entity_registry_updated, "entity_registry_updated", action="create")
Now, when in handler I'm trying to get the state of this entity I in fact get None as a state. It takes about 10 minutes to finally be able to get the real state of these newly created entities.
The documentation says "State updates are continuously tracked, so this call runs locally and does not require AppDaemon to call back to Home Assistant. In other words, states are updated using a push-based approach instead of a pull-based one.". Is there any way either use pull-based approach to get the state of some specific entities or to somehow indicate AppDaemon that there are new entities and it should re-read them from HA?
Thank you!
indeed HA pushes the state changes, and there is a backup in the loop that checks if its still correct. that checkup is done every 10 minutes. doing it more often would make AD unworkable.
a pullbased approach isnt implemented in AD, but you can use the HA api.
you could try an approach like:
- listen to the event for the new entity
- if a new entity is seen, use create entity (which probably gives a warning or error in HA)
- then AD sees the entity.
another option:
- listen to the event for the new entity
- if a new entity is seen, use HA api to pull the state every 10 seconds (i wouldnt advise to do it more often) untill AD knows the new entity.
Hi @ReneTode , many thanks for your recommendations! I used the first approach and it worked as expected. However, it would be really cool to have a more direct way to retrieve newly created entities without such workarounds.
the problem is that HA changes a lot and quick. this wasnt possible in the past.
and the AD devs have very busy lives nowadays, which causes that AD there is not done as much work on AD as HA demands.
luckily it are mostly such small things that have simple workarounds. and for most users its not a problem anyway.
normally new entities in HA, also means that the person is working on HA, so then a restart from HA/AD is not a problem.
so yeah it would be nice if its in AD, but i got no idea when that can happen.
at least you can add a feature request if you do so then add the event you listen to and the datastructure that it provides. and that the simplest solution at this moment is using create entity.
when a dev picks up the feature then he will know all there is to know to implement it.
and call it something like:
add new HA entities immediate to AD.
This is working as designed however there are plans to create a new mass plugin that will address this.