Reinitialize HA instead of restart if an entity is not available

Hello

I have some entities which are sometimes not available. For example: My wife has a switch unplugged, or there is a network problem. If I restart home assistant when the entity is currently offline, I see the entity as “unavailable” in Home Assistant. In that case I have to restart Home Assistant again and if the entity is available I get it back.

Instead of restarting, is there a simple trick like “re-initialize home assistant”, re-initialize an entity or reload a group of entities?

Thanks for answering
Gilbert

2 Likes

What kind of switch?

These things should report available as soon as they turn on and enter the network again. There is no need to restart HomeAssistant in most of these cases.

Are the logs giving errors? If there are errors, it could help point at the actual problem of why things aren’t updating once connected later…

Hi Jim
Thanks for the fast answer. The switches are these: https://www.home-assistant.io/integrations/mystrom/#switch

The error is simple:

2020-01-29 20:30:18 ERROR (SyncWorker_1) [homeassistant.components.mystrom.switch] No route to device: 192.168.1.145

I see this error during the startup of HA and only then. Looks like HA tries to initialize if not available HA forgets it and do not try a bit later again.

Gilbert

Yeah, looking at the code, if it can’t connect to the device on startup, it just fails and wont ever try again.

It’s strange, it does the same check on .update(), so no clue why it had to validate in setup_platform() too.

You would have to modify that integration sadly :frowning:

No, there is not. The configuration is coming out of the configuration.yamlfile and in the current state this is the base for integrations which do not support a config flow.

When I wrote the integration that was the way how it’s done. If a device is not present during the startup of Home Assistant then the device was not added. This helped to avoid that people were adding devices with the wrong IP address. Nowadays, it’s different (reading config flow).

That’s because we didn’t want to add devices during setup_platform() which were not working.

Ok, there are changes which better support for handling the case when the device is offline.

1 Like

Just to add another use-case for the same ask of “re-initialize entities” - some entities like the Media-Player one (media player integration) can get stuck if the network temporarily fails during playback - the UI card shows the same content that was being played back prior to the networks issue and gets stuck in that state (it never re-syncs with the media player) until HA is restarted, even if the network is restored.

It would be really nice to be able to reset integrations or entities one by one in case this happens. I can see this is probably an issue of the integration, however having this feature would make HA more bullet proof

1 Like

Upvote. I would like to have a functionality too that scans the unavailable entities once in a while if they’ve become available in the meantime if this was not solved in the integration itself.

In meantime fabaff did the change (it is not really a fix) in the integration. So for this one case the “problem” is solved. Thanks very much to fabaff.

But what you write is a good idea. What about a general setting somewhere where I can say “rescan every 30min yes=no”?

I’m getting the same issue with the TP-Link integration. Besides not handling any brief network interruptions, it also fails to work if, for example, the power goes out and HA comes up before the TP-Link device, and the network path to it, are fully restored.

Apps from the vendor, as well as other home automation hubs, handle startup and occasional network fluctuations just fine. It’s odd that HA (or at least, that one integration) is not able to.

It seems to me that the sensible thing would be to re-check unavailable devices at some configurable interval.

Yes, that’s a real problem.

My case is the harmony hub integration. If the hub restartes (and it does a unplaned reboot several times a week - I think temperature related to the hub) the integration looses the connection and will grey out. No chance to get it to work again, despite a complete HA restart.

There must be a better way to handle this.

1 Like

I arrived here looking for a service to reload the TP link integration. That would fix my case of the general problem described in this thread.

Right now reloading the TP link integration is required if a light was powered off during a reboot. This means I have to make sure all lights are powered on before any reboot.

I welcome any pointers or workarounds :slight_smile:

I have the same problem with the hikvision integration. I’m cutting the power to the cameras inside my house when I’m home, but when I then turn them back on, the binary sensors stays offline :-/

1 Like

Same things here. Following…

Same here, Its happening with my TP Link Kasa plugs. The slightest network interruption and they go dark.

hi there, did you find any workable solution to this? my cameras publish a motion sensor that I use in my automation. Like you, If my cameras are off when HA boots, then the associated entities are not visible unless I reboot.

No, I’m afraid not :-/ Currently I’m just not turning it off, but that is not a sustainable solution…

I’m still having the similar issue in 2023 - with Goodwe solar panel solution and a smart wi-fi switch set up through the rest platform…

Also experiencing entities that become unavailable when the router is restarted, after an internet disconnect and reconnect or if for some other reason the entity is not reachable for a while. It seems that for me, the problem occurs predominantly with the Xiaomi Miio, Heos and recently also the Homekit Device integrations. The only way to fix the problem then is to restart Home Assistant. Not an ideal situation. While HA has grown in terms of complexity and supported integrations in recent years, it sometimes feels that stability has taken a back seat.