I know that the entities have to be “online” before homekit gets startet and most of the time this works.
Lately I had some internet connection troubles. When I restart HA while there is a connectivity issue some entities will to come up and will be deleted in homekit. I than have to chose the rooms again and so on. Really annoying.
So I reed about that I should set up an automation. The thing is a simple time offset won’t do the trick. I also don’t know if a ping test will always work. Because there might the option that the internet connection is available but the entities are not set up right, because the connection was failure at the ha restart.
I think the best way to do this would be to proof if the entities (which are included in homekit) are available in “current entities”. One example are my netatmo entities. I have auto discovery enabled for that because I have quite a few of those. So if netatmo fails (could also be their server) the entities will be delated in homekit.
The only thing I can think of would be to create template entities for those you would like to stay in HomeKit. I don’t know if that’s possible for all your devices and it’s probably a lot work to set it up, but it should solve your issue.
That really would be a lot of work and a lot of unnecessary entities.
Isn’t there a way to search in the “current entities” list for the homekit entities. And if one value doesn’t appear it should go false. Else true. Something like that.
I guess you could create a template sensor that checks for all states and returns false if one entity is unavailable. Combine this with a delayed HomeKit startup and a a condition in the automation and it should work. Still lots of ifs though.
The result could look something like this. Adjust the if-statements accordingly. Just keep in mind that I haven’t tested it, so there might still be some issues with it.
Thanks or your example. I tried it with the templating tool.
I don’t know if this will work.
As an example: I believe the entities of netatmo will disappear in the “current entities” list, when it is offline and ha gets restarted.
In your example, if I use a random entitiy (which is not in my ha), it will output “true”. The disappeared entity cannot be “none”, because its not in the list. It looks like the the code above will ignore those unknown entities (because output is true)
I agree that this could be useful for other too.
EDIT:
So instead of “None” we’d need some like an “isn’t even in the list”
Not by default. I just wanted to add the example to the official docs so other users could find and use it quicker. If they are in a similiar situation as you have been.
@h4nc During the review @frenck noticed one more improvement.
Instead of using a binary_sensor, the entity check should be in the wait_template. This improves performance a bit, since the state isn’t logged in the database and not checked if HomeKit is already started.
However, it might be that you actually want the state to be logged. In that case the binary_sensor works as well.
The example code. This will be in the HomeKit doc, too, once the PR is accepted.
Latly it seems like HomeKit autostarts (sometimes) after a ha reboot even if the binary sensor is off, because my ha entities are in the standard room again.
Also very annoying: The settings go my garage door get reset on all our devices and we get the garage door open/close notification, which we don’t need/want.
I did not figure out which could cause this. Is there any known issue?