How to log out of lovelace cast to Google Home

tl;dr - Does anybody know how to log out of an HA screen when cast to Google Home, so you can log in again with a different userid?

When I first used cast.show_lovelace_view I’m pretty sure it wanted me to log on to HA, and I used my usual HA login. I wanted to login with a different userid, but couldn’t find any way of logging out on the Google Home - the sidebar is not shown and you can’t swipe to bring it up. I thought I could fix it by using login control, but that seems like a bad idea as it deletes all long-lived tokens as well.

Since doing this, when I cast to a Google Home, the cast works, but I also get a “Login attempt or request with invalid authentication” notification. If I dismiss the notification, another ones back some seconds later. The log shows the following:

Exception in _handle_signal_show_view when dispatching 'cast_show_view': (<pychromecast.controllers.homeassistant.HomeAssistantController object at 0x7f6f7b9ba290>, 'media_player.gh_2', 'clock', 'lovelace-cast') Traceback (most recent call last): File "/usr/src/homeassistant/homeassistant/components/cast/media_player.py", line 980, in _handle_signal_show_view self._hass_cast_controller.show_lovelace_view(view_path, url_path) File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 119, in show_lovelace_view self._send_connected_message( File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 130, in _send_connected_message self._connect_hass( File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 103, in _connect_hass raise PyChromecastError() pychromecast.error.PyChromecastError

I’m also getting this:

Logger: pychromecast.controllers
Source: /usr/local/lib/python3.10/site-packages/pychromecast/controllers/receiver.py:246
First occurred: 14:01:46 (1 occurrences)
Last logged: 14:01:46

Exception thrown when calling cast status listener
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/receiver.py", line 244, in _report_status
    listener.new_cast_status(self.status)
  File "/usr/local/lib/python3.10/site-packages/pychromecast/socket_client.py", line 498, in new_cast_status
    handler.channel_connected()
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 53, in channel_connected
    self.get_status()
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 113, in get_status
    self._send_connected_message(
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 130, in _send_connected_message
    self._connect_hass(
  File "/usr/local/lib/python3.10/site-packages/pychromecast/controllers/homeassistant.py", line 103, in _connect_hass
    raise PyChromecastError()
pychromecast.error.PyChromecastError

I have also tried deleting and re-installing the Cast integration, but that was no help.

It seems I was barking up the wrong tree. Before Google Cast, you logged in on the Google Home, but no more. Now Google Cast seems to always use the Owner account - at least that’s what you see with {{ user }} on the page, or in data.new_state.context.user_id. I was hoping to find a way of identifying the different Google Homes, and I thought one way would be to have separate logins for them. I guess I would have to store a different random cookie on each to help with this.

I have found your post while searching for the same error and I wonder if you have found a solution already? It does not depend on which user is authenticated on the Nest Hub according to my experience.

Thank you!

Regards,

Csaba