AlexxIT/go2rtc · error
hass: wrong type:
Error message
hass: wrong type:
What it means
hass.API.Auth performs the Home Assistant WebSocket auth handshake and expects the first message type to be "auth_required". If the server sends any other type, Auth returns this error including the received type, indicating the connection is not in the expected authentication state.
Solutions
- Verify the WebSocket URL points to Home Assistant's API websocket endpoint (path /api/websocket).
- Log the received res.Type value to see what the server actually sent.
- Bypass or correctly configure reverse proxies so the raw WebSocket reaches Home Assistant.
- Ensure you are not reusing an already-authenticated connection.
Example fix
// before
api, err := hass.NewAPI("ws://homeassistant.local:8123/api")
// after
api, err := hass.NewAPI("ws://homeassistant.local:8123/api/websocket") Defensive patterns
Strategy: try-catch
Validate before calling
u, err := url.Parse(wsURL)
if err != nil || !strings.HasSuffix(u.Path, "/api/websocket") {
return fmt.Errorf("invalid Home Assistant websocket URL: %s", wsURL)
} Try / catch
api, err := hass.NewAPI(wsURL, token)
if err != nil {
if strings.Contains(err.Error(), "hass: wrong type") {
return fmt.Errorf("endpoint did not send auth_required; check URL points to /api/websocket: %w", err)
}
return err
} Prevention
- Always append /api/websocket to the Home Assistant base URL.
- Test the websocket endpoint with a raw client before wiring it into the app.
- Check reverse-proxy WebSocket upgrade configuration (Connection/Upgrade headers).
When it happens
Trigger: Connecting to a URL that is not the Home Assistant WebSocket endpoint (e.g. the HTTP API root, or behind a proxy serving HTML/error pages that fail differently), or an already-authenticated connection that skips auth_required.
Common situations: Wrong ws:// or wss:// URL (missing /api/websocket path); reverse proxy intercepting the handshake; connecting to a different Home Assistant integration expecting another protocol; token supplied to a connection that already completed auth.
Understand the failure class
Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.
Related errors
- wrong auth response
- hass: wrong response
- hass: no token
- ivideon: wrong message type:
- unsupported frame type
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/a7e9b532234d52b9.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/hass/api.go:36
}
api := &API{ws: ws}
if err = api.Auth(token); err != nil {
_ = ws.Close()
return nil, err
}
return api, nil
}
func (a *API) Auth(token string) error {
var res ResponseAuth
if err := a.ws.ReadJSON(&res); err != nil {
return err
}
if res.Type != "auth_required" {
return errors.New("hass: wrong type: " + res.Type)
}
s := `{"type":"auth","access_token":"` + token + `"}`
if err := a.ws.WriteMessage(websocket.TextMessage, []byte(s)); err != nil {
return err
}
if err := a.ws.ReadJSON(&res); err != nil {
return err
}
if res.Type != "auth_ok" {
return errors.New("hass: wrong type: " + res.Type)
}
return nil
}
func (a *API) Close() error {
return a.ws.Close()View on GitHub (pinned to c245815e75)