{"record":{"id":"42147e7809c7b024","repo":"AlexxIT/go2rtc","slug":"hass-no-entity-id","errorCode":null,"errorMessage":"hass: no entity_id","messagePattern":"hass: no entity_id","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/hass/client.go","lineNumber":26,"sourceCode":"\t\"github.com/AlexxIT/go2rtc/pkg/webrtc\"\n\tpion \"github.com/pion/webrtc/v4\"\n)\n\ntype Client struct {\n\tconn *webrtc.Conn\n}\n\nfunc NewClient(rawURL string) (*Client, error) {\n\tu, err := url.Parse(rawURL)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tquery := u.Query()\n\n\tentityID := query.Get(\"entity_id\")\n\tif entityID == \"\" {\n\t\treturn nil, errors.New(\"hass: no entity_id\")\n\t}\n\n\tvar uri, token string\n\n\tif u.Host == \"supervisor\" {\n\t\turi = \"ws://supervisor/core/websocket\"\n\t\ttoken = SupervisorToken()\n\t} else {\n\t\turi = \"ws://\" + u.Host + \"/api/websocket\"\n\t\ttoken = query.Get(\"token\")\n\t}\n\n\tif token == \"\" {\n\t\treturn nil, errors.New(\"hass: no token\")\n\t}\n\n\t// 1. Check connection to Hass\n\thassAPI, err := NewAPI(uri, token)","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/hass/client.go#L8-L44","documentation":"NewClient parses a URL and requires an entity_id query parameter identifying the Home Assistant entity to control. If the query string does not contain a non-empty entity_id, construction is aborted with this error before any network connection is attempted.","triggerScenarios":"Calling hass.NewClient with a URL like ws://host:8123/api/websocket?token=... but omitting &entity_id=<entity>, or misspelling the parameter (e.g. entityid=), or passing an empty entity_id value.","commonSituations":"Config file or environment variable building the Home Assistant URL lost the entity_id part; users copy a token-only URL from HA docs; URL building code forgets to url-encode/append the entity query param.","solutions":["Add the entity_id query parameter to the URL, e.g. ws://host:8123/api/websocket?token=TOKEN&entity_id=camera.front","Verify the parameter name is exactly entity_id (case-sensitive, via query.Get)","Log/print the parsed URL query in your config assembly to confirm the value reaches NewClient","Check that config templating/env expansion is not producing an empty entity_id value"],"exampleFix":"// before\nclient, err := hass.NewClient(\"ws://ha.local:8123/api/websocket?token=\" + token)\n// after\nclient, err := hass.NewClient(\"ws://ha.local:8123/api/websocket?token=\" + token + \"&entity_id=camera.front\")","handlingStrategy":"validation","validationCode":"u, _ := url.Parse(rawURL)\nif u == nil || u.Query().Get(\"entity_id\") == \"\" {\n    return errors.New(\"URL must include entity_id query parameter\")\n}\nclient, err := hass.NewClient(rawURL)","typeGuard":"func hasEntityID(rawURL string) bool {\n    u, err := url.Parse(rawURL)\n    return err == nil && u.Query().Get(\"entity_id\") != \"\"\n}","tryCatchPattern":null,"preventionTips":["Build the HA URL in one helper that always appends both token and entity_id","Unit-test URL construction for the entity you control","Validate query parameters before calling NewClient"],"tags":["home-assistant","url","missing-parameter","client-init"],"backgroundTag":"missing-required-argument","analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}