Random logouts and entity_id reversions

One of my children has one of my old iPhones without cellular service. I’ve installed the HA companion app on it and he’s able to connect to a WiFi signal most of the places he goes, but sometimes has no connection. I’ve logged him in via the internal and external (Nabu Casa) login so that the sensors can send updates back when he’s on an external network.

Every 1-2 days, I see that his sensors are no longer updating, so I check his phone. Sure enough, the app is logged out (he’s not logging out). So, I log the app back in and the sensors still don’t update. When I check on the entities, I see that the custom entity_id’s I set (e.g. adding “_app”) all reverted back to their base names essentially breaking any templates, etc.

  1. Why does the app (seemingly) randomly log out?
  2. Why do the entity_id’s reset to their base names and how can I stop that from happening?

You can “force” sensor update using iOS shortcuts automation. 2 ways actually;
one is using power disconnect automation running home companion shortcut integration named update sensor. This method makes update very time phone is disconnect from power without user interaction.
The other method is using connect to any Wi-Fi automation using same update sensor shortcut integration, but this method asks for user to run it every time.

Thanks, but I already have the shortcuts configured. That’s not my issue. The sensors cannot update if the app logs out, which is my issue.

You can see the reason for the logout in Settings > App > Debugging > Event Log. Look for Refresh token is invalid, showing onboarding. Tap into that, it’ll give you the reason. This only happens if the server returns a 401/403 response code when refreshing the access token, which should only happen when the app is logged out via invalid credentials.

Logging in again causes the app to re-integrate, which causes HA to reset the name of entities. This shouldn’t happen if logging in isn’t occurring, so it’s sort of the root problem.

Thank you. I had him set to local only, so hopefully that fixes his logouts. How often does the app try to refresh the token?

Any idea on the entity_id?

Refreshes occur hourly or so. The entity IDs are not expected to reset unless you are signing in again.

Ok, so if any device doesn’t have a data connection for over ~1 hour, it is logged out since it couldn’t retrieve a new token from the HA server and when that happens HA forgets about any custom names - resetting them upon the next successful login?

If I have that right, is there any way to configure HA to not drop certain devices.

Of course, in the meantime, the goal is to stay logged in, but a data connection isn’t always available (e.g. flying, camping, etc.). I’m sure I’m still missing something. :rofl:

Authentication to Home Assistant follows the OAuth spec, which has 2 token types: a refresh token, and an access token. The refresh token typically does not expire or expires after a long duration, and the access token expires regularly but new ones can be created via a refresh token.

You should not expect to be signed out of the app unless you revoke the refresh token or the server does not allow the refresh token to be used for some other reason (like local users or not being on a trusted network).

Hi this is your son, I’ve been logging out and changing your entity IDs to troll you into making a forum post

Ok, thanks. So, it’s not simply being off data, but the first attempt to access the server once back on data (or really any time) that could result in the user getting logged out (if local, untrusted network, etc.).

It still seems there should be a way to maintain modified device names and entity_id’s.