Templating Engine - Detect Unavailable Entities, for HomeKit Delayed Start

Hi all, trying to figure out a maintainable way to do the “HomeKit” start automation, as discussed in the homekit guide, and I was looking for a way to find all the “unavailable” entities, as visible in the entity registry?

I.e., when my Hue failed to connect today, due to a firewall issue on a server reboot, Homekit freaked out. The solution is the delayed-started automation, checking for devices, but I’m curious if there’s a way to have it look for all registered entities, being seen that boot, or if I should just pick one for each “service provider”, and hope that is sufficient?

Thanks.

That’s not possible. You can look per domain.

This is how you find all unavailable:

{% set entities = states | selectattr('state','in',['unavailable','None']) | map(attribute='entity_id') | list %}

This is how you find all unavailable the light domain (swap light for whatever you want):

{% set entities = states.lights | selectattr('state','in',['unavailable','None']) | map(attribute='entity_id') | list %}

And if you have a specific list of entities…

{% set list_of_entities = ['light.foo', 'switch.foo'] %}
{% set entities = states | selectattr('entity_id','in', list_of_entities) | selectattr('state','in',['unavailable','None']) | map(attribute='entity_id') | list %}

or if I should just pick one for each “service provider”

I was meaning as a manual process. If I ensure I have one Hue light, one Smart Things device, one wifi device, etc, then chances are tolerable that things are happy.

This is how you find all unavailable:

{% set entities = states | selectattr('state','in',['unavailable','None']) | map(attribute='entity_id') | list %}

For my specific case, I believe that the entities wont even exist in the states array, sadly. When home assistant comes up without connectivity to, for example, my Hue hub, then the lights entities are not present in the states object. However, I can navigate to the Entity Registry, and see that they do exist there, and are marked with “Entity not available”.