AlexxIT/go2rtc · error

hass: wrong response

Error message

hass: wrong response

What it means

hass.API.ExchangeSDP sends a WebRTC offer via the Home Assistant websocket and expects a result message with Success == true. If the response type is not "result" or Success is false, this generic error is returned — the actual failure reason is in the response the library discards.

Solutions

  1. Check that the target camera entity exists and supports the web_rtc frontend stream type.
  2. Inspect Home Assistant logs for the underlying stream/camera error at the time of the request.
  3. Confirm the camera integration is loaded and the entity state is not unavailable.
  4. Improve the library call site to surface the raw response's error message for diagnosis.

Example fix

// before
// library discards res.Error
// after
if res.Type != "result" || !res.Success {
    return "", fmt.Errorf("hass: wrong response: type=%s err=%v", res.Type, res.Error)
}
Defensive patterns

Strategy: validation

Validate before calling

// verify camera supports WebRTC before exchanging SDP
states, err := api.GetWebRTCEntities()
if err != nil { return err }
if _, ok := states[cameraEntityID]; !ok {
    return fmt.Errorf("camera %s does not support web_rtc", cameraEntityID)
}

Try / catch

answer, err := api.ExchangeSDP(entityID, offer)
if err != nil {
    if strings.Contains(err.Error(), "hass: wrong response") {
        return fmt.Errorf("camera rejected the WebRTC offer (unsupported stream type or entity offline): %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Requesting a WebRTC answer for a camera entity that does not exist, is offline, does not support web_rtc stream type, or when the command ID mismatches so an error message arrives instead of the result.

Common situations: Camera without WebRTC support (only HLS/LL-HLS); camera entity unavailable; camera integration erroring on offer; Home Assistant returning an error frame because the stream component rejected the SDP.

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


AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07). Data as JSON: /api/errors/ceedee9bbf8d867e. Report an issue: GitHub.

Appendix: source

Thrown at pkg/hass/api.go:74

func (a *API) ExchangeSDP(entityID, offer string) (string, error) {
	var msg = map[string]any{
		"id":        1,
		"type":      "camera/web_rtc_offer",
		"entity_id": entityID,
		"offer":     offer,
	}
	if err := a.ws.WriteJSON(msg); err != nil {
		return "", err
	}

	var res ResponseOffer
	if err := a.ws.ReadJSON(&res); err != nil {
		return "", err
	}

	if res.Type != "result" || !res.Success {
		return "", errors.New("hass: wrong response")
	}

	return res.Result.Answer, nil
}

func (a *API) GetWebRTCEntities() (map[string]string, error) {
	s := `{"id":1,"type":"get_states"}`
	if err := a.ws.WriteMessage(websocket.TextMessage, []byte(s)); err != nil {
		return nil, err
	}

	var res ResponseStates
	if err := a.ws.ReadJSON(&res); err != nil {
		return nil, err
	}
	if res.Type != "result" || !res.Success {
		return nil, errors.New("hass: wrong response")
	}

View on GitHub (pinned to c245815e75)