home-assistant/core · error · HomeAssistantError

connection_closed

connection_closed

Error message

Connection to the Android TV device is closed

What it means

Raised as HomeAssistantError (translation connection_closed) when AndroidTVRemote._send_key_command catches ConnectionClosed from the androidtv-remote library: the ADB-remote protocol channel to the TV was already closed when a key press was queued. Unlike coordinator errors this aborts the current entity action immediately.

Source

Thrown at homeassistant/components/androidtv_remote/entity.py:76

        self._api.add_is_available_updated_callback(self._is_available_updated)
        self._api.add_is_on_updated_callback(self._is_on_updated)

    @override
    async def async_will_remove_from_hass(self) -> None:
        """Remove callbacks."""
        self._api.remove_is_available_updated_callback(self._is_available_updated)
        self._api.remove_is_on_updated_callback(self._is_on_updated)

    def _send_key_command(self, key_code: str, direction: str = "SHORT") -> None:
        """Send a key press to Android TV.

        This does not block; it buffers the data and arranges
        for it to be sent out asynchronously.
        """
        try:
            self._api.send_key_command(key_code, direction)
        except ConnectionClosed as exc:
            raise HomeAssistantError(
                translation_domain=DOMAIN, translation_key="connection_closed"
            ) from exc

    def _send_launch_app_command(self, app_link: str) -> None:
        """Launch an app on Android TV.

        This does not block; it buffers the data and arranges
        for it to be sent out asynchronously.
        """
        try:
            self._api.send_launch_app_command(app_link)
        except ConnectionClosed as exc:
            raise HomeAssistantError(
                translation_domain=DOMAIN, translation_key="connection_closed"
            ) from exc

View on GitHub (pinned to 58a3fdb3ea)

Solutions

  1. Confirm the TV is powered and on the network, then retry the action.
  2. Reload the androidtv_remote integration to force a fresh remote session.
  3. Give the integration its reconnect delay/time after the TV boots — the library reconnects automatically.
  4. Verify the TV's remote debugging credentials in the integration settings still match.
Defensive patterns

Strategy: try-catch

Validate before calling

if not self._api.is_available:  # library availability flag
    raise HomeAssistantError('TV not connected')

Try / catch

except HomeAssistantError as err: if 'connection_closed' in err.translation_key: notify user / schedule reconnect; re-raise otherwise.

Prevention

When it happens

Trigger: Any media_player/remote action that ends in _send_key_command (turn_on/off, volume, mute, key presses) while the underlying remote connection is closed — TV powered off, network drop, or the remote protocol session expired and has not yet re-established.

Common situations: TV switched to standby/off or unplugged from network; Wi-Fi blips; acting on the entity right after HA restart before the remote session re-connects.

Related errors


AI-assisted analysis of home-assistant/core@58a3fdb3ea (2026-08-14). Data as JSON: /api/errors/076723896896cffe. Report an issue: GitHub.